Tips On Performance Testing and Optimization
Tips On Performance Testing and Optimization
Definitions:
Response Time the time it takes between initial request and complete download of
response (rendering of entire web page).
Load a measurement of the usage of the system. A server is said to experience high
load when its supported application is being heavily trafficked.
Scalability - A scalable application will has a response time that increases linearly as load
increases. Such an application will be able to process more and more volume by adding
more hardware resources in a linear (not exponential) fashion.
Automation testing tools Tools (Silk from Segue Software, WebLoad, etc) used to
simulate a user by requesting pages or going through pre-programmed workflow on your
site.
Load testing tools Most automation testing tools can also be used as load testing
software, like WebLoad. These tools will simulate any number of users using your site
and provide you with important data like average response times.
Profiler. A profiler is a program that examines your application as it runs. It provides you
with useful run time information such as time spent in particular code blocks, memory /
heap utilization, number of instances of particular objects in memory, etc.
3) Interpreting the results. After measuring response time at varied database sizes and
loads, you can now make interpretations based on the average response time of these tests
and the resource utilization of the server during the tests.
4) Optimization. After identifying problems in the last step, you now interpret the
results and track down the problem.
Optimization
The database, your architecture, configuration and hardware will need to be optimized.
As mentioned in the previous section, the easiest way not to scale is to have a database
that isnt tuned. A database administrator (DBA) is always a vital person to have on any
dev team, but if you dont have one, here is what you can do:
Look though your EJBs and verify that your database isnt doing linear searches for any
of the sql queries that you have encoded. To do this, copy your SQL from your code and
in your database sql window, run an EXPLAIN clause:
Explain select * from table where tablefield = somevalue
Although the explain syntax differs from database to database, there is always something
similar. After running this line of code, your DB will tell you if it is searching an index or
a linear search. Make sure you verify that every piece of SQL in your application is using
your DBs indexes, and if not, create the indexes.
After optimizing the database, and optimizing your hardware configuration (as discussed
in the previous section), the next step is optimizing your code, and this is done with a
profiler.
A profiler is a program that analyzes your application as it runs. A Profiler provides you
with information you could not otherwise get access to, such as:
1. How many objects of each class are in memory and garbage collection
behaviour
o This information can help you identify classes, which should be pooled.
o Can help you tune your java heap.
2. How much time your application is spending in particular classes
This is the most important feature. Your profiler will point its finger and
show you which classes are the bottlenecks.
One such program that really helped me is called Optimize-It. Optimize-It can be used
with any java program or any java-based application server. Configuration with
Weblogic is easy, and Optimize-It can be used to profile an application on a remote
server.
Optimizing your architecture is extremely project specific, but here are some tips:
1. Make sure you have minimized your network calls, especially database calls
o It is better to make one large database call rather than many small ones.
o Make sure ejbStore isnt storing anything for read only operations.
o Use Details Objects to get entity bean state.
2. Make sure to take advantage of caching where possible
Your app. Server probably allows you to cache entity beans in memory, make sure
you take advantage of this, as it will dramatically reduce database calls and speed
up data access.
3. Make sure you are using session beans as a faade to your entity beans.
You can encapsulate the workflow of one entire usecase in one network call to
one method on a session bean (and one transaction).
was extremely unscalable. The response time jumped from 3 to 4 seconds single
user to 15 to 20 seconds per page under heavier load. These numbers were
obviously not good enough.
Having optimized the database and upgraded the hardware, we now turned to
examine our architecture. Minor modifications were made, but we still couldnt
find the cause of the problem. Once we began using a profiler, that all changed.
After running Optimize It remotely (had a window on my local machine telling
me the stats of the server running at our ISP) I discovered the cause of our
problem. 30% of the CPU time was being spent in socket communications with
our database. Optimize It allowed me to trace back and see which
objects/methods were initiating these calls, and I identified a design problem that
was causing us to query for a count in the database every time we wanted to
display a message on TheServerSide.com. After fixing this silly problem, I
brought down the number of database calls invoked to display a page from 15+
down to 1, and suddenly our response time went down to about 1 second. This
was exactly what we wanted.
Conclusion
Performance testing and optimizing your application can be pretty challenging. Luckily,
there are tools on the market that can make the process easier. By using these tools and
following the simple steps in this paper, you should be able to effectively track down the
bottlenecks in your system.