- Limit the number objects instanciations. This might actually be difficult to do, however with the right design and approach tremendous saving are possible. Object pools is one way to go, but may not be applicable in every situation.
- Avoid or improve object serialization if possible. Object serialization (accross networks) happens to be very slow. It offers ease of use, but you pay in performance. Analyze the classes that are serialized and make sure only required attributes are serialized. Hashtables and complex structures are the biggest hit.
- Analyze and optimize string related operations -- especially concatentations, string buffer extensions are usually expensive.
- More threads does not mean better throughput -- thread management adds overhead and after a certain number may actually degrade performance. Multiple CPUs might add marginal improvement especially when threads are dependent and sychronized with other threads. Revise your thread model to take advantage of multiple CPUs.
- Avoid synchronous IO -- using asynchronous socket IO, file IO is prefered, let the worker threads to the job. I happen to like the principle of accepting the client request, and let it process by the worker thread and unblock the client app -- then notify the client when task completes.
Friday, May 18, 2007
Improving performance of Java applications
During many implementation of high performance java applications, I found that the following strategies lead to be better performaning java apps -- especially better performing server apps.