1

Single thread eliminates a lot of complications involved in multithreaded application.

I was wondering if there are garbage collector configurations which can take advantage of single threaded application?

Right now I am using a UseConcMarkSweepGC, incrementalMode GC settings on a Java Runtime Environment build: Java 1.6.0_22-b04

Srujan Kumar Gulla
  • 5,721
  • 9
  • 48
  • 78
  • Not sure that it really makes a difference? GC tuning is very application specific, and the threading is not necessarily relevant. Do you currently have problems for GC? What problems? What does your object model look like? etc... all this stuff matters a lot more than single threaded vs. multi-threaded. – Taylor Apr 09 '13 at 20:49
  • @Taylor Issue:Doing profiling I see the heap having a lot of Strings generated. I was thinking if I increase the ParallelGCThreads then GC on the whole will hog the cpu instead of application during ConcurrentMarkingPhase of CMS but the GC Time can be reduced. So for a single thread app this might be an issue right? In this line of thought I was thinking are there any good settings suiting a single Threaded application – Srujan Kumar Gulla Apr 09 '13 at 21:53
  • do you need those strings? same strings re created? maybe can keep some in weak references or an auto discarding map like whirly? – tgkprog Apr 10 '13 at 07:54

2 Answers2

2

If JVM is started on single threaded machine, it will not use complex memory barriers required for multicore, thus saving some CPU cycle.

But JVM is inherently multithreaded, even if you have just one thread there are still other threads supporting JVM.

So answer is no, there is no GC algorithm optimized for single threaded applications.

Alexey Ragozin
  • 8,081
  • 1
  • 23
  • 23
  • agree there will be JVM threads (at least the main if its non gui) but most of the action will be in the user thread. a – tgkprog Apr 10 '13 at 07:52
  • @tgkprog GC tuning is individual for each application and being multithreaded is not an important factor. If you seek for a help with GC tuning, post your GC logs and state goal you want to achieve (e.g. max pause duration) – Alexey Ragozin Apr 10 '13 at 11:39
0

The GC strategies do not depend on how you coded your application but on the hardware you have.

For instance, if you have only one CPU available, then you should not enable CMS for two reasons :

  • it will steal this only CPU time from your application so you will have STW pauses
  • It implies overhead to be concurrent, which means your application will be stopped longer

In that case, you should enable SerialGC (or ParallelGC, it does not matter on a single CPU machine).

Now, if you have N cores available but your application only uses one, you can set -XX:ConcGCThreads=N-1 and -XX:ParallelGCThreads=N-1 (depending on the GC you use) so that the JVM takes full advantage of your hardware.

Note that before setting any flag, you should enable GC logs using -Xloggc:gc.log -XX:+PrintGCDetails and check after each new configuration that it improved your application response time/throughput.

Source : http://jvm-options.tech.xebia.fr/

Pierre Laporte
  • 1,205
  • 8
  • 11