Saturday, July 17, 2010

How to improve performance of you web application - Series 1

I have been doing performance and scalability improvement of web applications for some time. Though my experience is based on small scale applications, the learnings and concepts are applicable for general web applications from small to medium scale.

This topic will be in a series of blogs and we will cover very basic things in the first series.

We will start this by defining performance & scalability.

What is scalability ?

A desirable property of a system, application or a process, which indicates its ability to either handle growing amounts of work in a graceful manner or to be readily enlarged.For example, it can refer to the capability of a system to increase total throughput under an increased load when resources (typically hardware) are added

A system whose performance improves after adding hardware, proportionally to the capacity added, is said to be a scalable system. An algorithm, design , program, or other system is said to scale if it is suitably efficient and practical when applied to large situations (e.g. a large input data set or large number of participating nodes in the case of a distributed system). If the design fails when the quantity increases then it does not scale.


What is Performance ?

In simple terms performance is the time taken to complete a task. In terms of web applications it's defined as time taken to load the page or submit a form and get response.

In web applications performance can be perceived performance and actual performance. Perceived performance refers to how quickly a web application page appears to complete its task. It's not necessarily to fully complete the task, but it gives the illusion to the user that the task is completed.

Scalability & Performance :

There is a some relationship between scalability & performance. Scalable applications are those which can give acceptable performance under increased load. For example assume 5 second is acceptable performance for the page to load. A web application can serve 100 concurrent requests with 3 second as the performance. Under increased load (say 1000 concurrent requests) if the application serves pages with 5 second performance, then it could be said as scalable. So scalability is defined as within the acceptable performance.

There are some simple techniques (scale up & scale out) by which you can improve the scalability of the system without doing much changes in the software.

Scale Up means increasing the performance & scalability of the application by adding more resources in a single node. i.e. By adding more RAM, Disk, CPU the application scalability and performance can be improved. This technique is also called as vertical scaling.

Scale Out means increasing performance and scalability by adding more nodes. i.e. For example this means adding 2 more web servers to improve performance and scalability. This technique is also called as horizontal scaling.

Performance and Scalability Measurement:

Now we have defined the meaning of performance and scalability, the next step is to measure it. Without measuring we can not improve it. So we will use simple metrics to measure the performance and scalability.

Performance Metrics:

We will be using the following metrics to define performance
  • Time taken to complete the task. It will be in the order of seconds for web application.
  • Resources taken to complete the task. i.e CPU cycles, RAM Usage of the web application. Though it may be difficult to measure this for single task, we will average this over multiple invocations of similar task.
Scalability Metrics:

We will be using the following metrics to define scalability.
  • Number of concurrent requests served with the acceptable performance
  • Maximum number of concurrent requests the web application can handle during the peak burst.
  • Resources (CPU, Memory & Disk) used by application.

Now we have defined metrics to measure those, we will see in next article on actual steps to improve it.