Solace Community is getting a facelift!
On March 3rd we will be starting the process of migrating Solace Community to a new platform. As a result, Solace Community will go in to a temporary read-only state. You will still be able to come onto Solace Community and search through posts to find answers, but you won't be able to ask questions, post comments, or react in any way.
We hope to have the migration complete by Wednesday March 5th (or sooner), so please keep an eye out!
Can I set the CPU Core for the context thread in JavaRTO API?

Is there the ability to define the core to which a given thread will be pinned to?
Best Answer
-
Yes, you can set the thread affinity of the automatically created context thread.
The relevant context properties for the underlying C API can be found here.From within JavaRTO, you can provide the required “CONTEXT_THREAD_AFFINITY” property on context creation like so:
String[] contextProperties = new String[4]; int index = 0; contextProperties[index++] = "CONTEXT_THREAD_AFFINITY"; contextProperties[index++] = "255"; contextProperties[index++] = "CONTEXT_CREATE_THREAD"; contextProperties[index++] = "1"; rc = Solclient.createContextForHandle(contextHandle, contextProperties);
Note: if you pass context properties to createContextForHandle(), you must include CONTEXT_CREATE_THREAD with a value of 1. (Its default is 0, meaning disabled, which is not supported).
2
Answers
-
Yes, you can set the thread affinity of the automatically created context thread.
The relevant context properties for the underlying C API can be found here.From within JavaRTO, you can provide the required “CONTEXT_THREAD_AFFINITY” property on context creation like so:
String[] contextProperties = new String[4]; int index = 0; contextProperties[index++] = "CONTEXT_THREAD_AFFINITY"; contextProperties[index++] = "255"; contextProperties[index++] = "CONTEXT_CREATE_THREAD"; contextProperties[index++] = "1"; rc = Solclient.createContextForHandle(contextHandle, contextProperties);
Note: if you pass context properties to createContextForHandle(), you must include CONTEXT_CREATE_THREAD with a value of 1. (Its default is 0, meaning disabled, which is not supported).
2 -
How did you calculate 255 ? I used 10 for using core 4 but don't think it worked.
0 -
See the docs for the C API here: https://docs.solace.com/API-Developer-Online-Ref-Documentation/c/group___context_props.html
(Note, the JavaRTO API is a JNI wrapper around the C API... if you need pure Java, there is the new Java API, and the older JCSMP API)
It is a bitmask. So if you want core 4 (numbering starts at 0), you'll want to set only the 5th bit from the right, or
0b00010000
, which is 16.255 means
0b11111111
, or setting the mask so it can run on any core from 0-7.1 -
Thanks @Aaron. Is it possible to busy spin? I saw if using shares memory there is an option to spin but I am using tcp protocol and couldn't find any way to spin.
0 -
0x0000000000000010 is the bit mask I used as per https://bitsum.com/tools/cpu-affinity-calculator/ for core 4. But after reading your response its clear that it is incorrect. Many thanks
0