Improve your Web Application Performance | Optimize Caching , Code , SQL



Are u facing performance issues with your Web Application ? One can improve the performance by working on the following areas - 

Hardware improvements 

The simplest way is to upgrade infrastructure ie upgrade memory , processor of web , application and DB servers. 

Caching

1. Caching Proxy Servers

Static content can be rendered to the user from the Proxy server and without giving it to the load balancer and hence to the respetive web server.

2. Caching Pages at the Web Servers

Static Content can also be cached at the web server level. 

3. Shared Memory

Loading shared Information upon Application Start up. For example - content of a file or DB can be loaded in memory and can be shared among requests.

4. Database Caching

Caching the DB content so as to save DB call for each request.

5. Caching View Templates 

We can incorporate using Velocity instead of JSP wherein intermediatery template is used for faster conversion of dynamic content to html. 

Coding Techniques -

1. Avoid creating unnecessary objects and always prefer to do Lazy Initialization

2. Avoid creation of a variable within a loop.

3. Prefer If Else instead of multiple If. 

If Else moves to the targetted block in a binary way whereas using only If means reaching to the target block in sequence.

4. Organize If Else or multiple ifs in the order of their success probabilities.

5. Wherever possible try to use Primitive types instead of Wrapper classes


6. Use Strings with utmost care.


Always carefully use Strings in your code. A simple concatenation of strings can reduce performance of program. For example if we concatenate strings using + operator in a for loop then everytime + is used, it creates a new String object. This will affect both memory usage and performance time.


SQL Optimization 

1. Use Bid Variables instead of Variables directly - In case of Bind variables , The DB server stores the excution strategy for this first call and then reuse the execution strategy for each such call with a seperate variable but in case direct variables are used the server is not able to corelate both the calls and hence creates a new strategy for each execution.


2. If possible , Use SubQueries in place of Joins