🎄 Happy Holidays! 🥳

Most of Solace is closed December 24–January 1 so our employees can spend time with their families. We will re-open Thursday, January 2, 2024. Please expect slower response times during this period and open a support ticket for anything needing immediate assistance.

Happy Holidays!

Please note: most of Solace is closed December 25–January 2, and will re-open Tuesday, January 3, 2023.

Can I set the CPU Core for the context thread in JavaRTO API?

JamilAhmed
JamilAhmed Member, Employee Posts: 20 Solace Employee
edited April 2020 in Blogs & Tutorials #1

Is there the ability to define the core to which a given thread will be pinned to?

Tagged:

Best Answer

  • JamilAhmed
    JamilAhmed Member, Employee Posts: 20 Solace Employee
    edited April 2020 #2 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).

Answers

  • JamilAhmed
    JamilAhmed Member, Employee Posts: 20 Solace Employee
    edited April 2020 #3 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).

  • Aaron
    Aaron Member, Administrator, Moderator, Employee Posts: 644 admin

    Huh! I didn't know that. Cool!

    As an alternative, I usually handle my CPU affinity at the shell using taskset. That way I can change at runtime.

  • mprabhat_jha
    mprabhat_jha Member Posts: 15
    edited May 2023 #5

    How did you calculate 255 ? I used 10 for using core 4 but don't think it worked.

  • Aaron
    Aaron Member, Administrator, Moderator, Employee Posts: 644 admin

    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.

  • mprabhat_jha
    mprabhat_jha Member Posts: 15

    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.

  • mprabhat_jha
    mprabhat_jha Member Posts: 15

    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

This Week's Leaders