2

我有一个在 java 上实现的侦听器项目,它使用来自 kafka 的数据并推入 Vanilla Chronicle 队列。我正在使用 jna 的 java 库,jna-platform 版本 4.4.0 和编年史队列版本 3.6.4。当我在 Windows 上运行项目时,它成功使用数据并将数据推送到队列中。但是,当我在 Azure VM 上的“Ubuntu 16.04.3 LTS”上运行它,同时将数据推送到队列中时,它会失败。而且,当我在 VMware 中的本地 ubuntu 上运行它时,它也成功运行。任何人都知道问题是什么?执行日志如下:

*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*
4

1 回答 1

1
Caused by: com.sun.jna.LastErrorException: [22] H"

来自 linux 源的错误代码 22 是EINVAL[1]。

查看man该函数的页面会sched_getaffinity显示返回的原因EINVAL

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.

这可能是库中的一个问题,但更有可能是由于运行时环境和 VM 基础架构报告/使用 CPU 掩码的方式。

正如 Peter 所指出的,在虚拟化环境中设置进程亲和性的价值值得怀疑。

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

于 2017-09-11T06:55:51.480 回答