Wednesday, June 1, 2011

Site performance tuning using jMeter and jVisualVm

I recently had to work on a requirement where I had to support (response time  less than 5 seconds) for   500 concurrent users, with 10 million users in database and a single server. I tried going through many forums and open source tools, from which I finalized on jMeter for performance testing and jVisualVm for finding bottlenecks.

This was my approach:
  1. Make sure that the server (hardware can be as per the staging/production requirements) has no other installations that can affect the performance. 
  2. For setting up the users in DB, a procedure can be used and can be called as a part of jmeter test plan.
  3. Install jmeter on a separate machine, so that jmeter won't affect the performance. 
  4. Create a test plan in jmeter (as shown in the figure 1) for all the uri's, with response checking and timer based requests.  
  5. Take the initial benchmark, using jmeter.
  6. Check for the low performance uri's. These are the points to expect for bottlenecks.
  7. Try different options for performance improvement, but focus on only one bottleneck at a time. Some of them can be 
    1. Database index. Use the DB server logging to find the slow queries, use explain plan and improve the sql statements.
    2. Check the configuration parameters for any third party tools.
    3. Check if there are any dead locks (can be checked with jVisualVM as shown in Figure 2).
    4. Profiling the application using jVisualVm(can be checked with jVisualVM as shown in Figure 3).
    5. Data structures, algorithms and loops.
    6. UI components, try advices from YSlow. Try streaming, caching, etc.
    7. Read the hardware configuration and try for any options like cpu cache, jvm tuning, paging, etc. This step does not include hardware scaling.
    8. Check for memory leaks using jVisualVm.
  8. Try any one fix from step 6 and then take an benchmark. If there is any improvement commit the changes and repeat from step 5. Otherwise revert and try for any other options from step 6.
  9. The next step would be to use load balancing, hardware scaling, clustering, etc. This may include some physical setup and hardware/software cost. Give the results with the scalability options.
jMeter test plan
Figure 1: jMeter test plan

jVisualVM run for a sample deadlock program.

Figure 2: jVisualVM shows Thread 1 and 2 waiting for the monitor
Figure 3: jVisualVm showing profile results for memory

Results:

In the end it is better to prepare a complete report from the benchmarks and finally define the performance with details of the hardware, software, maximum db load, maximum number of concurrent users supported(users active every 2 seconds), maximum number of sessions, changes made and the improvement achieved.  Any unimplemented changes can be suggested for improvement, so that the effort to find the bottleneck is improved.


Saturday, December 11, 2010

Originality

I believe the most powerful tool that human beings possess is the mind, that can ignite imagination. Every possible creation in the world is a tangible idea. Every possible idea is the outcome of all or some of the senses, passed through may be a single or billions of neural schemas (referring to the brain). 

Any idea can be referred to some part of the nature (at Universal level). When someone says an idea is original, what is it? I don't understand.  Take for instance, Google search, don't you think it is a matured idea of the search that we do everyday; Facebook, is it not a virtual social network; Virtualization, complete simulation of a natural concept; Photography, light captured with a particular setting (do you own the light or the setting?); Music, captured sound at some desired frequencies; etc. 

I still don't understand, the noun originality, is it the first idea preceding all others in time? In such case, it belongs to the nature. Or is it the first one to file a patent or register it, or is it the first one to show it to the world. Or is it the first one who comes out with some tangible output. What if someone had the idea for long time and could not come with an output or did not express it.

Understanding this, I do understand the considerable amount of work someone puts for coming out with  an idea, which we all feel new. I still wonder if the newness or freshness can be considered as original. I take the concept of wall (which itself is taken from a broadcast or something else) and come out with a specification of wall with only 150 characters max, inclusive all characters and call it twitter (just an example, which is considered as a great idea). Is this original? But, I understand the effort that is put for developing this and the ego of so many developers, and may be testers too.

Why all the software is not made open source? Is it because of security reasons or is it because of the ego of the investors or ego of all the developers, who don't want someone else to directly copy it or reuse it. 

So, definition of originality or original-idea (as it is used) is the ego of the hard-work to build an idea, which creates the feeling of some newness or freshness and belongs to the first one who expresses/shows it to the world.

Actually, originality is nature.

Disclaimer:  I do not copy nor encourage some one to copy any idea, but just sharing my thoughts on my confusion on originality. This is my understanding and welcome your definitions or ideas. 


Tuesday, April 6, 2010

Inherent Variability: A Major Difference Between Man and Machines


Image (a)
Image (b)
Image (a) shows my attempt to write alphabet 'a' the same way four times. Image (b) shows how a machine does the same. Obviously, we can see the machine is precise in doing this. A loud applause for the machine!

Image (c)


Image (c) shows a hand written word, in two different ways. The word can, obviously, be recognized by any human reader. How good is the machine in doing the same task? This is how a captcha differentiates man and machines (though it is not exactly written by human beings, but some algorithm that can generate and display words with some distortion, which is difficult to be recognized by machines and can be easily recognized by humans).


Any written alphabet, spoken word, action performed by a human being is a stochastic process; i.e., it is an output of a random function. Apart from the variability in doing things, we are built with an inherent ability to recognize and learn from the variability.

Though both the images on the right and left represent the same great person, we can easily recognize the variability and if we try to draw the same image again and again, we will end up in producing a different image every time.

This shows  our inherent ability to produce and recognize the variability. This is very, very difficult for a machine to recognize this as a same person.





Watch a 6-months-old baby (almost a fresh brain, of course, though trained for a few tasks and far better than the best known robots), give her a toy and she feels happy for some time, and then searches for a new one.

Have you ever wondered why we don't feel happy watching the same movie more that a few times?

It is all the part of the human intelligence architecture: the brain. Our brain (still we are not in a position to exactly know its architecture) contains 1011 neurons and 1015 synapses. Each new activity changes the whole network. Each time you watch a movie, you are watching it with a new neuron-synapse network. Each time we watch, we look at some new things which we missed in the other part. The watched part goes automatically into the sub-conscious mind, and the selective mechanism is now focused on the new variable part which goes into the conscious mind. Each time our mind expects some learning. When this learning saturates or if we couldn't find any interesting variability any more, we feel boredom. So if any movie is enjoyable for quite a number of times, it has a lot of likable-variability in it.

There are a few generalization algorithms that are used by machines to generalize identification of objects.  For e.g: Asimo, one of the worlds best humanoid robot can generalize few objects based on its characteristics. Obviously, not as good as humans. Humans work on very high dimensional space to find  or understand the variability and use A-priori knowledge, which makes the difference in identification.

Even the motor control in human beings has the variability in every action we do compared to the machines which can just do any action based on the limited controlling parameters.

The reason why television, computers are still interesting is the variability of shows in the  TV  (compromising multi-dimensional parameters into a few dimensions) and computer being one device having capability of running different applications providing variability. Overall, the inherent variability makes our lives very interesting, which is very difficult to achieve by the machines.