Linux JNA-based affinity not usable because it failed to load

621 views Asked by At

I have a listener project implemented on java that consumes the data from kafka and pushes into the Vanilla Chronicle queue. I am using the java libraries of jna, jna-platform version 4.4.0 and chronicle queue version 3.6.4. When I run the project on Windows it successfully consumes and pushes the data into the queue. However when I run it on "Ubuntu 16.04.3 LTS" that is located on Azure VM while pushing the data into the queue it fails. And on also when I run it on my local ubuntu that is in VMware it also succesfully runs. Anyone has an idea what the problem is? The execution log is below:

*WARN  [main] (net.openhft.affinity.Affinity:149):
 Linux JNA-based affinity not usable because it failed to load! Reason: java.lang.ExceptionInInitializerError
    at net.openhft.affinity.Affinity.isLinuxJNAAffinityUsable(Affinity.java:113)
    at net.openhft.affinity.Affinity.<clinit>(Affinity.java:52)
    at net.openhft.affinity.AffinitySupport.getThreadId(AffinitySupport.java:26)
    at net.openhft.chronicle.VanillaChronicle$VanillaAppenderImpl.startExcerpt(VanillaChronicle.java:628)
    at net.openhft.chronicle.VanillaChronicle$VanillaAppenderImpl.startExcerpt(VanillaChronicle.java:615)
    at com.myproject.queue.DataQueueManager.add(DataQueueManager.java:55)
    at com.myproject.listener.myprojectListener.initKafka(myprojectListener.java:67)
    at com.myproject.listener.myprojectListener.start(myprojectListener.java:43)
    at com.myproject.listener.myprojectListener.main(myprojectListener.java:35)
Caused by: java.lang.IllegalStateException: sched_getaffinity(0, (8) , cpuset) failed; errno=22
    at net.openhft.affinity.impl.LinuxHelper.sched_getaffinity(LinuxHelper.java:61)
    at net.openhft.affinity.impl.LinuxJNAAffinity.getAffinity(LinuxJNAAffinity.java:62)
    at net.openhft.affinity.impl.LinuxJNAAffinity.<clinit>(LinuxJNAAffinity.java:49)
    ... 9 more
Caused by: com.sun.jna.LastErrorException: [22] H"
    at com.sun.jna.Native.invokeInt(Native Method)
    at com.sun.jna.Function.invoke(Function.java:390)
    at com.sun.jna.Function.invoke(Function.java:323)
    at com.sun.jna.Library$Handler.invoke(Library.java:236)
    at net.openhft.affinity.impl.$Proxy7.sched_getaffinity(Unknown Source)
    at net.openhft.affinity.impl.LinuxHelper.sched_getaffinity(LinuxHelper.java:56)
    ... 11 more
07.09.2017 12:58:28.631 WARN  [main] (net.openhft.affinity.Affinity:149):
 Posix JNA-based affinity not usable because it failed to load! Reason: java.lang.ExceptionInInitializerError
    at net.openhft.affinity.Affinity.isPosixJNAAffinityUsable(Affinity.java:99)
    at net.openhft.affinity.Affinity.<clinit>(Affinity.java:56)
    at net.openhft.affinity.AffinitySupport.getThreadId(AffinitySupport.java:26)
    at net.openhft.chronicle.VanillaChronicle$VanillaAppenderImpl.startExcerpt(VanillaChronicle.java:628)
    at net.openhft.chronicle.VanillaChronicle$VanillaAppenderImpl.startExcerpt(VanillaChronicle.java:615)
    at com.myproject.queue.DataQueueManager.add(DataQueueManager.java:55)
    at com.myproject.listener.myprojectListener.initKafka(myprojectListener.java:67)
    at com.myproject.listener.myprojectListener.start(myprojectListener.java:43)
    at com.myproject.listener.myprojectListener.main(myprojectListener.java:35)
Caused by: java.lang.IllegalStateException: sched_getaffinity((4) , &(allocated@0x7f2ba436c7e0 (4 bytes) (com.sun.jna.ptr.IntByReference@a437470b)) ) errorNo=22
    at net.openhft.affinity.impl.PosixJNAAffinity.getAffinity(PosixJNAAffinity.java:125)
    at net.openhft.affinity.impl.PosixJNAAffinity.<clinit>(PosixJNAAffinity.java:64)
    ... 9 more
Caused by: com.sun.jna.LastErrorException: [22] ý
    at com.sun.jna.Native.invokeInt(Native Method)
    at com.sun.jna.Function.invoke(Function.java:390)
    at com.sun.jna.Function.invoke(Function.java:323)
    at com.sun.jna.Library$Handler.invoke(Library.java:236)
    at net.openhft.affinity.impl.$Proxy8.sched_getaffinity(Unknown Source)
    at net.openhft.affinity.impl.PosixJNAAffinity.getAffinity(PosixJNAAffinity.java:117)
    ... 10 more
07.09.2017 12:58:28.633 INFO  [main] (net.openhft.affinity.Affinity:61):
 Using dummy affinity control implementation
07.09.2017 12:58:28.634 ERROR [main] (com.myproject.listener.myprojectListener:71):
 java.lang.UnsupportedOperationException*
1

There are 1 answers

0
Mark Price On
Caused by: com.sun.jna.LastErrorException: [22] H"

Error code 22 from the linux source is EINVAL [1].

Looking at the man page for the function sched_getaffinity shows the reason for EINVAL being returned:

EINVAL (sched_getaffinity() and, in kernels before 2.6.9, sched_setaffinity()) cpusetsize is smaller than the size of the affinity mask used by the kernel.

This could be an issue in the library, but is more likely due to the runtime environment and the way that the VM infrastructure is reporting/using CPU masks.

As Peter has pointed out, the value of setting process affinity in a virtualised environment is questionable.

1) http://elixir.free-electrons.com/linux/v4.4.84/source/include/uapi/asm-generic/errno-base.h#L25