Hello @hft-team-city
As the title described, I tested AffinityThreadFactory on my macOS, and the result with AffinityThreadFactory was consistently slower than the default threadfactory, the code below
val threadFactory = AffinityThreadFactory("affinity",AffinityStrategies.DIFFERENT_CORE)
val threadPool= Executors.newFixedThreadPool(8,threadFactory)
val futures: ArrayList<Future<Long>> = ArrayList()
val runnable = runable@{
val l1=System.nanoTime()
for (j in 1..5000){
var sum = 0
for (i in 1..10000){
sum +=i
}
}
val l2=System.nanoTime()
return@runable l2-l1;
}
var l1=System.currentTimeMillis()
for (i in 1..8){
futures.add( threadPool.submit(runnable))
}
for (i in futures){
i.get()
}
var l2=System.currentTimeMillis();
println("-----------------"+(l2-l1))
threadPool.shutdownNow()
When I use affinity thread factory, it costs about 1400ms~1700ms
however, I remove the thread factory as below:
val threadPool= Executors.newFixedThreadPool(8)
It costs about 700ms~1100ms
I know the affinity factory will bind a thread to the CPU core, but why is it slower than a thread that never bound the CPU core?
Hello @hft-team-city As the title described, I tested AffinityThreadFactory on my macOS, and the result with
AffinityThreadFactory
was consistently slower than the defaultthreadfactory
, the code belowWhen I use affinity thread factory, it costs about 1400ms~1700ms however, I remove the thread factory as below:
val threadPool= Executors.newFixedThreadPool(8)
It costs about 700ms~1100ms
I know the
affinity factory
will bind a thread to the CPU core, but why is it slower than a thread that never bound the CPU core?