These things obviously require careful testing and the availability of code to carefully analyze and provide good suggestions. However, this is not always possible, and I hope that it will be possible to provide me with useful tips based on the information presented below.
I have a server application that uses a listener thread to listen for incoming data. Incoming data is interpreted in the messages of specific applications, and these messages then lead to events.
Until this moment, I have no control over how everything is done.
Since this is an outdated application, these events previously dealt with the same listener thread (mostly a single-threaded application). Events are sent to the black box, and the output appears, which should be written to disk.
To increase throughput, I wanted to use threadpool to monitor events. The idea was that the listener thread could simply create new tasks every time an event is created, and the threads would take care of calling the black box. Finally, I have a background thread that writes to disk.
Only with the previous installation and the background author does everything work fine, and the throughput is 1.6 times more than before.
When I add a thread pool, but performance degrades. From the very beginning everything seems smooth, but after a while everything happens very slowly, and finally I get OutOfMemoryExceptions. The strange thing is that when I print the number of active threads every time a task is added to the pool (along with information about how many tasks are queued, etc.), it seems that the thread pool has no problems with to keep up with the producer (stream of listeners).
Using top -H to test CPU usage, it is fairly evenly distributed from the start, but in the end, worker threads are barely active, and only the listener thread is active. However, it does not seem to represent any more tasks ...
Can anyone suggest the cause of these symptoms? Do you find it more likely that there is something wrong with the legacy code (which I donβt control) that when adding multiple threads? The problem with the lack of memory should be due to the fact that some queue is somewhere too large, but since the thread stream almost never contains tasks in the queue, it cannot be.
Any ideas are welcome. Especially ideas on how to more effectively diagnose a similar situation. How can I get a better profile on what my threads do, etc.
Thanks.