简体   繁体   English

Java线程池吞吐量

[英]Java Thread Pool Throughput

I am observing a very strange problem in a java client server application. 我在java客户端服务器应用程序中观察到一个非常奇怪的问题。 I am sending following Runnable objects to the server at 80 requests per second. 我以每秒80个请求向服务器发送以下Runnable对象。 The thread pool keeps pool size equal to the request rate ie approximately 80 threads in the pool. 线程池使池大小等于请求率,即池中大约80个线程。 My laptop is intel Core i5-3230M dual core(Windows show me 4 processor). 我的笔记本电脑是英特尔酷睿i5-3230M双核(Windows显示我4处理器)。 Strange thing is that the Throughput(jos completed per second) is also 80. I could not understand this. 奇怪的是,吞吐量(每秒完成一次)也是80.我无法理解这一点。 How 4 processors and 80 threads are completing 80 jobs of 100 milliseconds in one second ? 4个处理器和80个线程如何在一秒钟内完成80个100毫秒的作业? That is: 那是:

Processors=4
Request rate=80
Thread pool size=80
Each job service time=100milliseconds.
Throughput=80 How?

I was expecting throughput=40 because each processor should approximately complete 10 jobs in 1 second so 4 processors should give throughput=40 but it is 80 ? 我期望吞吐量= 40,因为每个处理器应该在1秒内大约完成10个作业,因此4个处理器应该提供吞吐量= 40但是它是80? Laptop specification link says 笔记本电脑规格链接

Also, the cores can handle up to four simultaneous threads, which improves the performance and resource-utilization of the CPU. 此外,内核最多可以处理四个并发线程,从而提高了CPU的性能和资源利用率。

Does this means 8 threads can run at the same time b 2 cores? 这是否意味着8个线程可以同时运行b 2个核心?

public class CpuBoundJob  implements Runnable {

    public void run() {

     long startTime = System.nanoTime();
         while ((System.nanoTime() - startTime) < (100)*1000000L) {}

    }
}

You have written tasks which run for a fixed amount of time, not a fix amount of work. 您编写的任务在固定的时间内运行,而不是一定数量的工作。 This means they should always complete at a fixed rate regardless of the number of CPUs you have. 这意味着无论您拥有多少CPU,它们都应始终以固定的速率完成。 You could just have them sleep for 100 ms. 你可以让他们睡100毫秒。

How 4 processors and 80 threads are completing 80 jobs of 100 milliseconds in one second ? 4个处理器和80个线程如何在一秒钟内完成80个100毫秒的作业?

Your computer is running far more threads than you have processes all the time. 您的计算机运行的线程比您一直运行的线程多得多。 The OS uses scheduling to stop and start running thread (faster than you can see) to give the illusion they all running at once but they are not and cannot (never could if you think about it) 操作系统使用调度来停止并开始运行线程(比你看到的更快)给出他们一次运行的错觉但它们不是也不能(如果你想的话,永远不会)

Also, the cores can handle up to four simultaneous threads, which improves the performance and resource-utilization of the CPU. 此外,内核最多可以处理四个并发线程,从而提高了CPU的性能和资源利用率。

Its means it's two cores have hyper threading allowing the processor to running up to four threads without context switching (as mentioned above) 这意味着它的两个内核具有超线程,允许处理器在没有上下文切换的情况下运行多达四个线程(如上所述)

Does this means 8 threads can run at the same time b 2 cores? 这是否意味着8个线程可以同时运行b 2个核心?

The i5 mentioned has 2 cores it supports 4 threads as it states. 提到的i5有2个内核,它支持4个线程。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM