14 Mart 2023 Salı

ForkJoinPool Work Stealing Nedir?

Giriş
Açıklaması şöyle
If a thread is getting overwhelmed and its internal queue fills up another thread instead of picking up task from the main queue can “steal” task from another threads internal queue.
Şeklen şöyle. B thread'i A thread'inin kuyruğundan iş çalıyor.
Resimdeki her threadin kuyruğunun ismi ForkJoinPool.WorkQueue. Açıklaması şöyle
ForkJoinPool is that it’s created with the following ruling points.Each thread has its own task queue. 

- Each task queue is a cicular array.
- Each thread uses push and pop to add or remove tasks to its own queue.
- ForkJoinPool uses the work-stealing algorithm to balance the workload on different threads. The pool maintains a global work queue that stores externally submitted tasks. Each worker thread will pop tasks from its own task queue. If there are no tasks in its own queue, it will try to randomly steal tasks from the shared work queues or other workers. If it fails to find tasks from both shared queues or other threads, it will go to sleep.
ForkJoinPool.WorkQueue Sınıfı
3 tane temel metod sunuyor. Açıklaması şöyle
push: used by worker thread to push task to the top of its own work queue
pop: used by worker thread to pop task from the top of its own work
poll: used by other thread to steal task from the bottom of the work queue of a different thread

Hiç yorum yok:

Yorum Gönder