Search code examples
javaperformancejvmmulticore

jvm on multicore


I've read a blog post a while ago claiming a Java application ran better when it was allowed to utilize a single cpu in a multicore machine: http://mailinator.blogspot.com/2010/02/how-i-sped-up-my-server-by-factor-of-6.html

What reasons could there be for a Java application, running on multicore machines to run much slower than on a single core machine?


Solution

  • If there is significant contention among shared resources in the different threads, it could be that locking and unlocking objects requires a large amount of IPI (inter-processor interrupts) and the processors may spend more time discarding their L1 and L2 caches and re-fetching data from other CPUs than they actually spend making progress on solving the problem at hand.

    This can be a problem if the application has way too-fine-grained locking. (I once heard it summed up "there is no point having more than one lock per CPU cache line", which is definitely true, and perhaps still too fine-grained.)

    Java's "every object is a mutex" could lead to having too many locks in the running system if too many are live and contended.

    I have no doubt someone could intentionally write such an application, but it probably isn't very common. Most developers would write their applications to reduce resource contention where they can.