Re: issues while using Java Thread Affinity library

228 views
Skip to first unread message

Peter Lawrey

unread,
Feb 1, 2016, 7:22:39 AM2/1/16
to Sonia 2, java-ch...@googlegroups.com
Hello Sonia,
   You can use the pom.xml to build the library in Maven, however since the build is available on Maven central, I suggest you use that instead. http://search.maven.org/#artifactdetails%7Cnet.openhft%7Caffinity%7C3.0.1%7Cbundle for the latest version.
  You can use Ivy for Ant, Maven or Gradle to have it download it as needed.  If you are not using one of these build tools, I highly recommend you do so as building/downloading all the JARs you might need from scratch could use a lot of your time for little benefit.
   To get the most benefit from CPU binding I suggest using Linux and running your critical threads on isolated CPUs.

If you have any technical questions, you can post them to the java-chronicle google group (see the CC)

Regards,
   Peter.

On 1 February 2016 at 06:34, Sonia 2 <son...@tcs.com> wrote:
Hello,


I am Sonia, working in TCS, pune India. I am interested in doing Java threads binding with cores in windows. I have gone through your 
"Java Thread Affinity" library, which provides a mechanism to bind Java threads with CPU cores in windows. 

But I have some issues whle using the library: 

1) I am not finding any mechanism to build this library in windows. 
2) Do I need JNA or Maven to build this library?


Looking forward for your reply. 

Thanks & Regards,
Sonia 

=====-----=====-----=====
Notice: The information contained in this e-mail
message and/or attachments to it may contain
confidential or privileged information. If you are
not the intended recipient, any dissemination, use,
review, distribution, printing or copying of the
information contained in this e-mail message
and/or attachments to it are strictly prohibited. If
you have received this communication in error,
please notify us by reply e-mail or telephone and
immediately and permanently delete the message
and any attachments. Thank you


Sonia Bansal

unread,
Feb 3, 2016, 1:02:43 AM2/3/16
to Chronicle, son...@tcs.com
Hello Peter, 

I am using multiple threads and want to do the thread binding with cores. If number of cores are less then after completion of first level of threads, next few threads should acquire the cores. I was using acquireCore(), but it is not working with multiple threads. Should I use acquireLock() or something else to bind multiple threads with cores. Please suggest. 

Peter Lawrey

unread,
Feb 3, 2016, 6:23:16 AM2/3/16
to java-ch...@googlegroups.com, son...@tcs.com
The library is really design to bind threads to their own isolated core rather than bind multiple threads to the same pool of cores.  You can do this however by using AffinitySupport.

You could do

    AffinityLock lock = AffinitySupport.acquireLock(false); // false if you don't want the thread creating this to be bound.

   // in each thread you want to add to this
   Affinity.setAffinity(lock.cpuId()); 

This will bind all the threads which call this to the same CPU.  Binding multiple threads to a core (both cpus on a hyperthreading pair) is a little tricky but it could be done.

Note: you can do anything you want with this pattern.

BitSet affinity = new BitSet(Runtime.getRuntime().availableProcessors());

// set as many cpus as you want
affinity.set(cpu);

// run in each thread you want to add to a pool of cpus.
Affinity.setAffinity(affinity);

This way you can for example add all the threads of an ExecutorService to say 2 cores.

-- Peter.

--
You received this message because you are subscribed to the Google Groups "Chronicle" group.
To unsubscribe from this group and stop receiving emails from it, send an email to java-chronicl...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Sonia Bansal

unread,
Feb 3, 2016, 6:49:17 AM2/3/16
to Chronicle, son...@tcs.com
Thank you for your reply. Actually thing is, I do have a system with 8 cores and my application has 280 cores. When I use acquireLock() or something like this, then first 6-8 threads will bind to 8 cores but all other threads are not binding to any core. they are running randomly on all available cores. 

So I want to bind first 8 threads and all other threads should wait and when ever a core is free then all waiting threads should go and bind to the available core. I am not sure whether this is possible or not. 

Please correct me If I am wrong. 

With Regards, 
Sonia 


On Monday, February 1, 2016 at 5:52:39 PM UTC+5:30, Peter Lawrey wrote:

Peter Lawrey

unread,
Feb 3, 2016, 10:08:52 AM2/3/16
to java-ch...@googlegroups.com, son...@tcs.com
Can you calrify what is the problem you are trying to solve?  WHen you have 280 threads, they will run on the next free logical CPU. If you have 8 cores plus hyperthreading, you can have 16 threads running at any one time and the OS scheduler will arrange the running threads in a reasonable optimal manner.  The reason to use affinity is because the OS isn't doing the right thing for you in which case you want to handle scheduling yourself.

Note: reducing the number of active threads can help improve the performance of your machine.  Since you have at most 16 threads running at any one time, having more than 16 active threads may just adds overhead.

Regards,
   Peter.
This email has been sent from a virus-free computer protected by Avast.
www.avast.com

Reply all
Reply to author
Forward
0 new messages