【问题标题】:Hazelcast: number of threads on a cluster with multi CPU machinesHazelcast:具有多 CPU 机器的集群上的线程数
【发布时间】:2016-05-03 07:33:43
【问题描述】:

我使用 Hazelcast 创建了一个集群:它有一个主节点,可以在 5 个其他节点之间传播 Runnables。我的问题是:Hazelcast ExecuterService 是否也在每个计算节点内并行执行计算?

我的意思是,如果我的每个计算节点都有 4 个 CPU(或单个 CPU 上有 4 个内核),那么参与计算的线程总数是多少? 5(每个节点的线程)还是 5*4=20(每个 CPU/内核的线程)?

【问题讨论】:

    标签: java multithreading hazelcast


    【解决方案1】:

    您发送给成员的 runnable 将为每个成员运行一次,这意味着它将仅使用单线程。所以 5

    【讨论】:

    • 其实我对此表示怀疑。我进行了一个实验,显示每个节点上的 CPU 负载为 100%(每个 CPU 内核都已满载)。所以我打赌 Hazelcast 在每台机器内并行计算,我只是想要一些证据。
    • 签出这段代码 sn -p: gist.github.com/gurbuzali/a87bc828404d9a062267 它表明每个节点上只使用一个线程来执行callable。
    【解决方案2】:

    好吧,我们可以手动解决:

    public class HazelcastTest {
    
        @Test
        public void test() {
            HazelcastInstance instance = Hazelcast.newHazelcastInstance();
    
            IExecutorService exec = instance.getExecutorService("exec");
            for (int i = 0; i < 100; i++) {
                exec.submit(new MyRunnable());
            }
        }
    
    }
    
    public class MyRunnable implements Runnable, Serializable {
    
        @Override
        public void run() {
            long threadId = Thread.currentThread().getId();
            System.err.println("threadId: " + threadId);
        }
    
    }
    

    结果是:

    threadId: 48
    threadId: 48
    threadId: 46
    threadId: 48
    threadId: 46
    threadId: 48
    threadId: 46
    threadId: 46
    threadId: 54
    threadId: 48
    ...etc...
    

    另一个证据是 CPU 监视器显示所有可用内核的负载为 100%。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-09-26
      • 1970-01-01
      • 2016-05-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-10
      相关资源
      最近更新 更多