Blog Post

Building high performance Java application (Lessons Learnt)

🗓 November 03, 2013 :: 🕑 2 min read :: 👏 0 💬 0

Whilst on training abroad last month, I had the opportunity of building an automated rates trading system in Java from scratch to compete with systems built by the other teams.

Surprisingly, this opportunity has turned out to be a great learning experience for me building a high performance application. My team did well in terms of performance and here are some of the lessons I learnt in the 2 weeks.

1. Monetary Calculations

  • Try to use long/double instead of BigDecimal for monetary calculation
  • Round result of multiplication/division calculation to the smallest currency unit
  • Don’t convert double to BigDecimal, convert using a string instead

2. Caching

3. Listeners

  • Keep listeners light
  • Hand events to another part of the system for processing

3. Multi-Threading

  • Thread creation is expensive
  • Use threadpools
  • Avoid synchronisation where possible
  • Have flow control to regulate the amount of threads
  • Fork-Join in 1.7 (or (link: https://g.oswego.edu/dl/concurrency-interest/ text: jsr166) in 1.6)

4. Java Specifics

java -server java -XX:+OptimizeStringConcat

5. Garbage Collection (GC)

6. Benchmark

  • Do it regularly (if possible, at the end of every sprint in agile)
  • Look for performance consistencies from historical benchmark
  • Use jvisualvm and visual GC plugin
  • Enable GC monitoring options
java -verbose:gc -Xloggc:<filename> -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+PrintTenuringDistribution -XX:+PrintGCApplicationConcurrentTime -XX:+PrintGCApplicationStoppedTime
Ben Shi

Whilst on training abroad last month, I had the opportunity of building an automated rates trading system in Java from scratch to compete…

https://hbish.com/building-high-performance-java-application-lessons-learnt/


Fetching Replies...