Treadpool:简单的例子,等待时间和执行时间来确定池的大小
Treadpool: Simple example for the wait time and execution time to determine the size of the pool
我试图找到一些简单的例子来说明确定线程池大小的等待时间和执行时间究竟是多少。根据布赖恩戈茨的说法:
For tasks that may wait for I/O to complete -- for example, a task
that reads an HTTP request from a socket -- you will want to increase
the pool size beyond the number of available processors, because not
all threads will be working at all times. Using profiling, you can
estimate the ratio of waiting time (WT) to service time (ST) for a
typical request. If we call this ratio WT/ST, for an N-processor
system, you'll want to have approximately N*(1+WT/ST) threads to keep
the processors fully utilized.
我真的不明白他的意思Input/output。谁在执行 I/O 任务。
想象一个从磁盘读取一些数据的任务。实际发生了什么:
- 打开文件。
- 等待(旋转的)磁盘从睡眠中醒来,将磁头定位在正确的位置,并等待所需的块出现在磁头下方,直到所有字节都到达缓冲区。
- 从缓冲区读取。
整个任务需要0.1s完成。在这 0.1 秒中,10% 用于步骤 1 和 3,其余 90% 用于步骤 2。因此 0.01 秒 "working time" 和 0.09 秒 "wait time" 用于等待磁盘。
我试图找到一些简单的例子来说明确定线程池大小的等待时间和执行时间究竟是多少。根据布赖恩戈茨的说法:
For tasks that may wait for I/O to complete -- for example, a task that reads an HTTP request from a socket -- you will want to increase the pool size beyond the number of available processors, because not all threads will be working at all times. Using profiling, you can estimate the ratio of waiting time (WT) to service time (ST) for a typical request. If we call this ratio WT/ST, for an N-processor system, you'll want to have approximately N*(1+WT/ST) threads to keep the processors fully utilized.
我真的不明白他的意思Input/output。谁在执行 I/O 任务。
想象一个从磁盘读取一些数据的任务。实际发生了什么:
- 打开文件。
- 等待(旋转的)磁盘从睡眠中醒来,将磁头定位在正确的位置,并等待所需的块出现在磁头下方,直到所有字节都到达缓冲区。
- 从缓冲区读取。
整个任务需要0.1s完成。在这 0.1 秒中,10% 用于步骤 1 和 3,其余 90% 用于步骤 2。因此 0.01 秒 "working time" 和 0.09 秒 "wait time" 用于等待磁盘。