Load Test, Profiling and Refactoring is the way to improve the performance of a web application

Posted on Updated on

Software engineering is not about particular technology like Java or Dot Net but it is all about the kind of standard practices we need to follow for production quality software. Recently I come across one of the practice during the performance testing of a web application. It would be helpful for other software developer, tester or devops.

Problem Definition: We have developed Asp.Net MVC 4 web application and we want to release it in production prior to that we need to  find out how much load it can take means how many concurrent users can access the web application and what is response time for each request during heavy load. We have agreed upon the response time should not be more than 3 seconds. This is common use case for all web application.

Solution: To solve it we have started with load testing, for that purpose we used the JMeter one of the open source load testing framework. We recorded the JMeter script. JMeter provided the user manual please refer it for more detail. We also want to monitor the server CPU and memory utilization for that purpose JMeter is having performance collection plugin and a server agent utility which captures the server parameters and sends it to the JMeter Plugin. JMeter has various listeners in which summary report gives the required statistics.

If the statistics are not satisfactory then it triggers the need to do profiling of a web application. By profiling we come to know various hot spots in the web application which very clearly state the resource utilization of every method and class. We have used the dotTrace from Jetbrains it provides the 10 days trial edition. Every language is having the profiling support so you choose which ever fit for you but objective is the same.

Now we have profiling result which triggers the need of re factoring of code. The re-factoring is common practice in agile which help to evolve the design and architecture of software. This activity triggers to implement particular task in more efficient way. This is totally depends on your business logic, design and architecture of software.

We need to repeat this cycle Load Test –> Profiling –> Re factoring until you will not be satisfactory with result. But one thing is very sure that you will have performance efficient software with good design and architecture.

performance tunning cycle

Remaining performance tuning can be done at web server level like increase number of worker and IO threads per process, increase the request queue length and if required add the load balancers etc.

Once you got the required result you can not hide smile on your face 🙂 i.e. “AANAND”

References

  1. http://jmeter.apache.org/usermanual/component_reference.html
  2. http://jmeter-plugins.org/wiki/PerfMonAgent/
  3. http://jmeter-plugins.org/wiki/PerfMon/
  4. http://www.jetbrains.com/profiler/
  5. http://refactoring.com/

Custom Error Page for ASP.NET MVC 4

Posted on

Step 1: Custom Error page IIS 6. it helps for page not found (404) at http://www.example.com/someNotExistPage.html
Inside web.config
<system.web>
<customErrors mode=”On” defaultRedirect=”~/GenericErrorPage.html”/>
</system.web>

 
Step 2: Custom Error page IIS 7.5 it helps for page not found (404) at http://www.example.com/pathOne/pathTwo/someNotExistPage.html
Inside web.config
<system.webServer>

<httpErrors errorMode=”Custom” >
<remove statusCode=”404″ subStatusCode=’-1′ />
<remove statusCode=”500″  subStatusCode=’-1′ />
<error statusCode=”404″ path=”/GenericErrorPage.html” prefixLanguageFilePath=”” responseMode=”ExecuteURL”  />
<error statusCode=”500″ path=”/GenericErrorPage.html” prefixLanguageFilePath=”” responseMode=”ExecuteURL” />
</httpErrors>
……
</system.webServer>

Step 3: Inside the Global.asax for catching all exception in web application

protected void Application_Error(object sender, EventArgs e)
{
var httpApp = (HttpApplication)sender;
Exception exception = Server.GetLastError();
// log the exception
}

Step 4:
In the ASP.NET MVC 4 case must provide page at /Views/Shared/Error.cshtml
Inside App_Start …

public class FilterConfig
{
public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
filters.Add(new HandleErrorAttribute());
….
}
}

And from Global.asax register it

protected void Application_Start()
{
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);

….
}

If needed create CustomHandleErrorAttribute by extending HandleErrorAttribute and override OnException
and register it at global.aspx filter or manage like any other controller level attribute
e.g.

[CustomHandleError()]
public class AccountController: Controller
{
…..
}

 Step 5: If needed override controller OnException method at controller level

protected override void OnException(ExceptionContext filterContext)
{
base.OnException(filterContext);
….
}

If anything is missing please let me know.

Thanks & Regards,
-Vinayak B

Tomcat 7 maven plug-in for remote deployment and remote debugging using jpda in netbeans

Posted on Updated on

I am trying to deploy web application in tomcat 7.0.42 remotely and also want to debug remote deployed web application from Netbeans 7.4. During this faced some issue also resolved it from reference but want to consolidate all this steps at one place. It would be helpful to someone who is trying this first time and also for my reference.

Tomcat maven plug-in for remote deployment:

Step 1: Add tomcat plug in build section

<build>
<plugins>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<url>http://localhost:8084/manager/text</url&gt;
<server>TomcatServer</server>
</configuration>
</plugin>
</plugins>
<build>

Step 2: Inside tomcat-users.xml which is located at catalina_home/conf add following

<tomcat-users>
<user password=”passoword” roles=”manager-gui,manager-script,admin” username=”admin”/>
</tomcat-users>

Step 3: Add following setting in your maven settings. File location is user home/.m2/settings.xml

<settings xmlns=”http://maven.apache.org/SETTINGS/1.0.0&#8243;
xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance&#8221;
xsi:schemaLocation=”http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd”&gt;
<servers>
<server>
<id>TomcatServer</id>
<username>admin</username>
<password>passoword</password>
</server>
</servers>
</settings>

Step 4: from maven project run command tomcat7:deploy

Enable remote debugging in netbeans 7.4:

Step1:  Go to tomcat/Catalina home directory. Open the startup.bat file.

Set parameters at first empty line :
set JPDA_ADDRESS=8000
set JPDA_TRANSPORT=dt_socket
And last line should be replaced
call “%EXECUTABLE%” start %CMD_LINE_ARGS%
by
call “%EXECUTABLE%” jpda start %CMD_LINE_ARGS%

Step 2: Start the tomcat using startup.bat from command line.

Step 3: From netbeans attach debugger with following setting and debug the code.

Debugger : Java Debugger (JPDA)
Connector: Socket Attach
Transport: dt_socket
Host: localhost
Port:8000

attach debugger

Regards,
-Vinayak B

References:

http://tomcat.apache.org/maven-plugin-trunk/tomcat7-maven-plugin/usage.html
http://tomcat.apache.org/maven-plugin-trunk/tomcat7-maven-plugin/plugin-info.html
http://stackoverflow.com/questions/13336816/tomcat7-maven-plugin-tomcatmanager-status-code403-reasonphraseforbbiden
https://confluence.sakaiproject.org/display/BOOT/Setting+Up+Tomcat+For+Remote+Debugging