By Srikanth Ramamurthy on Apr 2, 2014 6:07:28 AM
As a developer our majority of concentration lay around implementing the functional requirements of the product. But as an Architect, I need to take care of the non-functional requirements like how well the application performs? Can the application scale up?etc. besides ensuring functional requirements are met.
Is there a way for an Architect to find out the performance bottlenecks in the application without getting too much involved into the nitty-gritty of the low level code? Are there any tools which we can use to know the details of the application performance?
Let’s take a typical web application as an example and see what we can do to improve the performance without getting too much involved into the code. In our example, there is a page which is taking too much of time to load when a user requests the page.
As a developer I have coded this page & it works perfectly according to the requirements. But it is taking too much of time to show up in the client browser. So what is wrong?
So, let’s start our investigation & better understand what’s happening when a user requests the page. But the bigger question is how do we go ahead? How do I know what is going as an HTTP request & what is coming back as an HTTP response without going into the code?
The answer lies in using some of the tools which provide these details. Couple of tools which I use are:
These tools are HTTP sniffers / proxy for majority of the browsers & they provide more insights into how your web page is loading & performing. They log all the requests / responses to your web site. Now that I have this tool & I can see the requests / responses logged, the next question is where do we go from here?
I use these tools to get answers for some of my questions. Below are the questions:
- How many HTTP requests are sent to the server when the user requested that one page? Well, you may say it as one request? But the answer is NO. Although, the user requested a page, but internally browser will make many requests to get all the resources referenced in that page. The resources could be style sheet (CSS) files, images, java script files etc.
- Are we leveraging caching of the HTTP requests?
- How much of response data sent to the browser?
- Is the HTTP response compressed?
- How much time the browser waited to get the response back from the server?
Depending on the answers I get for these questions from the tool, below are some of the performance tuning we can do to improve the response time of the page:
- If there are many HTTP requests executed internally by the browser then use “minify” to combine many requests to CSS & JS files into single downloads. This will reduce the bandwidth required to get these files.
- It’s best to cache images as they may not change regularly. Implement caching filters to cache different types of images the web site may have.
- Look at the response data sent from the server and see whether the data is compressed. Most of the browsers supports gzip compression. So the browser can automatically un-zip the contents sent by the server. Gzip can be enabled at the web server level without writing any piece of code. Most of the web servers supports this. In Jboss it can be configured in the server.xml. Refer your web server manual for more details.
- If your server is taking more time to send back the response then comes the need to look at the application code. But wait. Before I get into the code, I need to know the time taken by the application to get the data from the database. How do I get the timings of the database calls?
I use tools like:
These tools enable database calls to be intercepted and logged without any change in the application code. I use these tools to get answers for some of my questions. Below are the questions:
How many database calls are executed to render our example page?
- Which calls taking more time?
- Are there any duplicate calls to fetch the same set of data?
Depending on the answers I get for these questions from the tool, below are some of the performance tuning we do to improve the response time of the page:
- Analyze the query which is taking more time. Check with database administrator to tune this query in terms of creating new indexes or new table space etc.
- If there are duplicate calls then check with the developer why duplicate calls required in the same transaction? Can we get data once and use it in multiple places instead of making same calls again.
- Out of the database calls made for the page, see whether any data that can be cached instead of loading from the database always. If so, implement a caching strategy.
These tools enables me to do some amount of performance tuning without getting too much involved at the code level. Of course in some cases it will be imperative to get to the lower levels but not without implementing the first level of performance optimization as mentioned above.