Suppose I have an application with the following basic flow and design:
- A single thread is receiving requests and queues them for further processing (CPU heavy) in another thread which belongs to a thread pool.
- The other thread, upon completion of the task, is sending the result back to the network and is pending a response. To avoid I/O blocks in the worker threads, it actually queues it in another thread responsible only for the networking.
- Upon receiving a response, the networking thread again queues the data of another CPU heavy task to a thread belonging to the aforementioned thread pool.
The thread pool's management is done from a separate thread.
To further clarify, note that there are 3 non-worker threads. The first (denoted A) handles the requests only, a second (denoted B) thread handles the networking of steps 2-3 and the third (denoted C) is responsible for dispatching the heavy tasks.
So the basic flow is actually A->C->Some worker->Back to C->B send request, get response->C->Some worker->Back to C for quick cleanup.
I would like to assign as many threads for the workers and to optimize A,B,C in some fashion, perhaps implementing them as a single thread. However I'm not sure how it can be done wisely and also how to measure it against alternatives.
Gurus, please advise.
Aucun commentaire:
Enregistrer un commentaire