Java 线程池吞吐量
Java Thread Pool Throughput
我在 java 客户端服务器应用程序中观察到一个非常奇怪的问题。我以每秒 80 个请求向服务器发送以下 Runnable 对象。线程池保持池大小等于请求率,即池中大约有 80 个线程。我的笔记本电脑是 intel Core i5-3230M 双核(Windows 显示 4 处理器)。奇怪的是 Throughput(jos completed per second) 也是 80。我无法理解这一点。 4 个处理器和 80 个线程如何在一秒钟内完成 100 毫秒的 80 个作业?即:
Processors=4
Request rate=80
Thread pool size=80
Each job service time=100milliseconds.
Throughput=80 How?
我期望吞吐量=40,因为每个处理器应该在 1 秒内大约完成 10 个作业,所以 4 个处理器应该提供吞吐量=40,但它是 80?笔记本电脑规格 link 表示
Also, the cores can handle up to four simultaneous threads, which
improves the performance and resource-utilization of the CPU.
这是否意味着 8 个线程可以同时 运行 2 个内核?
public class CpuBoundJob implements Runnable {
public void run() {
long startTime = System.nanoTime();
while ((System.nanoTime() - startTime) < (100)*1000000L) {}
}
}
您编写了 运行 固定时间而不是固定工作量的任务。这意味着无论您拥有多少 CPU,它们都应始终以固定速率完成。你可以让他们睡 100 毫秒。
How 4 processors and 80 threads are completing 80 jobs of 100 milliseconds in one second ?
您的计算机 运行 线程数量远远超过您一直拥有的进程数量。 OS 使用调度来停止和启动 运行ning 线程(比你看到的要快)给人一种错觉,它们都同时 运行ning 但它们不是也不能(永远不可能,如果你想想看)
Also, the cores can handle up to four simultaneous threads, which improves the performance and resource-utilization of the CPU.
这意味着它的两个内核具有超线程功能,允许处理器 运行在不进行上下文切换的情况下最多启用四个线程(如上所述)
Does this means 8 threads can run at the same time b 2 cores?
提到的 i5
有 2 个核心,它支持 4 个线程。
我在 java 客户端服务器应用程序中观察到一个非常奇怪的问题。我以每秒 80 个请求向服务器发送以下 Runnable 对象。线程池保持池大小等于请求率,即池中大约有 80 个线程。我的笔记本电脑是 intel Core i5-3230M 双核(Windows 显示 4 处理器)。奇怪的是 Throughput(jos completed per second) 也是 80。我无法理解这一点。 4 个处理器和 80 个线程如何在一秒钟内完成 100 毫秒的 80 个作业?即:
Processors=4
Request rate=80
Thread pool size=80
Each job service time=100milliseconds.
Throughput=80 How?
我期望吞吐量=40,因为每个处理器应该在 1 秒内大约完成 10 个作业,所以 4 个处理器应该提供吞吐量=40,但它是 80?笔记本电脑规格 link 表示
Also, the cores can handle up to four simultaneous threads, which improves the performance and resource-utilization of the CPU.
这是否意味着 8 个线程可以同时 运行 2 个内核?
public class CpuBoundJob implements Runnable {
public void run() {
long startTime = System.nanoTime();
while ((System.nanoTime() - startTime) < (100)*1000000L) {}
}
}
您编写了 运行 固定时间而不是固定工作量的任务。这意味着无论您拥有多少 CPU,它们都应始终以固定速率完成。你可以让他们睡 100 毫秒。
How 4 processors and 80 threads are completing 80 jobs of 100 milliseconds in one second ?
您的计算机 运行 线程数量远远超过您一直拥有的进程数量。 OS 使用调度来停止和启动 运行ning 线程(比你看到的要快)给人一种错觉,它们都同时 运行ning 但它们不是也不能(永远不可能,如果你想想看)
Also, the cores can handle up to four simultaneous threads, which improves the performance and resource-utilization of the CPU.
这意味着它的两个内核具有超线程功能,允许处理器 运行在不进行上下文切换的情况下最多启用四个线程(如上所述)
Does this means 8 threads can run at the same time b 2 cores?
提到的 i5
有 2 个核心,它支持 4 个线程。