views:

340

answers:

6

I would like to create comprehensive checklist for Java low latency application. Can you add your checklist here?

Here is my list
1. Make your objects immutable
2. Try to reduce synchronized method
3. Locking order should be well documented, and handled carefully
4. Use profiler
5. Use Amdhal's law, and find the sequential execution path
6. Use Java 5 concurrency utilities, and locks
7. Avoid Thread priorities as they are platform dependent
8. JVM warmup can be used
9. Prefer unfair locking strategy

As per my definition, low-latency application is tuned for every Milli-seconds.

+1  A: 

Use StringBuilder instead of String when generating large Strings. For example queries.

medopal
only makes sense when you want to do something with the String, e.g. concatenating other Strings or reversing or suchlike.
Tedil
It usually makes no difference. The bytecodes that the Java compiler generates for String concatenations uses StringBuilders!
Stephen C
Concatenation in a loop (or multiple statements) is the usual case where explicit `StringBuilder` wins.
Tom Hawtin - tackline
@Tedil, i fixed it, that's exactly what i meant, thanks.
medopal
+3  A: 

Buy, read, and understand Effective Java. Also available online

Thorbjørn Ravn Andersen
+2  A: 

Although immutability is good, it is not necessarily going to improve latency. Ensuring low-latency is likely to be platform dependent.

Other than general performance, GC tuning is very important. Reducing memory usage will help GC. In particular if you can reduce the number of middle-aged objects that need to get moved about - keep it object either long lived or short lived. Also avoid anything touching the perm gen.

Tom Hawtin - tackline
@Tom Hawtin, doesn't using immutable datastructures help latency when you don't have to synchronize around shared data?
binil
+2  A: 

avoid boxing/unboxing, use primitive variables if possible.

elec
Valuable point.
A: 

Another important idea is to get it working first, then measure the performance, then isolate any bottlenecks, then optimize them, then measure again to verify improvement.

As Knuth said, "premature optimization is the root of all evil".

maerics
Few of the application success or failure just depends on performance. Though premature optimization is wrong, that rule wont suite for every application. Low latency application has to be built with certain guidelines.
+1  A: 

Avoid context switching wherever possible on the message processing path Consequence: use NIO and single event loop thread (reactor)

bobah