Question

May be this is a well known question, But i didn't find the best reference for this ques...

  1. what is the formula to calculate and assign the default u-limit, verbose (for gc) and max heap memory value?

  2. If there is no specific formula, what is the criteria to specify this for a particular machine.

If possible could anyone please explain these concepts also.

  1. Is there any other concepts we need to consider for performance improvement?

  2. How to tune the JVM for better performance,

Was it helpful?

Solution

Stop what you're doing right now.

Tuning the JVM is probably the last thing you should worry about. Until you've gone through every other performance trick in the book, the default settings should be just fine.

Firstly you need to profile your application and find out where the bottlenecks are. Specifically, you will want to know:

  • What functions /methods are consuming the majority of CPU time?
  • Where are all the memory allocations happening?
  • What kind of objects are taking up most space on the heap?

Then you should apply targeted optimisations to the areas that are causing problems. There are thousands of valid techniques, but here are the ones that I find are most useful:

  • Improve algorithms - anything that is taking up a decent chunk of CPU time and has complexity of O(n^2) or worse is probably a good candidate for improvement. Try to get it to O(n log n) or better.
  • Share immutable data - if you have a lot of copies of the same data then it makes sense to turn these into immutable objects and share a single instance. This can save a lot of memory (and has the nice effect of improving thread safety / concurrency)
  • Use primitive types - replace Integer with int etc. This saves memory and makes numerical operations faster.
  • Be lazy - don't compute things until they are definitely needed.
  • Cache things - if something is expensive to compute but frequently requested, store it in a cache after the first request. Use a cache backed by a SoftHashMap so that the memory can still be released if needed.
  • Offload work - Can you make use of multiple cores? Can the client application do some of the work for you?

After making any changes you then need to profile again. At the very least, you will want to confirm that your optimisations actually helped. Additionally, fixing one bottleneck will usually move the bottleneck to another part of the application. So you will need to identify the new place to focus next.

Repeat until your application is fast enough (as defined by your own or your customers' requirements).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top