yatp icon indicating copy to clipboard operation
yatp copied to clipboard

adjust active thread count adaptively

Open sticnarf opened this issue 4 years ago • 0 comments

Edit: The self-adaptive strategy still needs some tuning. It's not so responsive in front of changing workloads

This PR adds another parking lot called backup. The threads parking in backup are much less often waked up. The workers except the backup ones are called active workers. The workers which are not parked are called running workers.

The working threads checks and records whether enough threads are utilized. If not enough threads are utilized continuously, a thread will be parked to the backup queue.

In contrast, if all threads are keeping utilized, it means we don't have enough working threads and we should unpark one from backup.

~~In this PR, the spawn method unparks threads only if the current running threads are less than min_thread_count. This reduces the latency in spawn side because unpark_one is a bit costy. In most cases, ensure_workers is called by working threads when they pop a task from the queue.~~

sticnarf avatar May 19 '20 07:05 sticnarf