Threading Slow Down
Hi,
I've developed a server application that constantly request data from 50 clients. I use threading for that.
My problem is:
a) There's discrepancy in the number of requested data from each client. For 1000 round of request, there's a difference of 10 to 20.
b) My application hangs. This usually happens when there's a lot of data coming from the client. As a result, I have to restart the server application.
Any one know anything about this?...help please?
Thx in advance :)
# 1 Re: Threading Slow Down
Are you using Threadpool? I seem to remember that these threads may be ignored(!) if your system is stressed. Use Threading.Thread instead.
# 2 Re: Threading Slow Down
Are you using Threadpool? I seem to remember that these threads may be ignored(!) if your system is stressed. Use Threading.Thread instead.
Hi there,
i am using one thread (threading.thread) for each connection to the client. What i does in each thread is to request data from the client. Cant really use threadpool because the threads have to run at the same time, not one by one.
I also notice the system seems to be stressed by the 50 threads i created because i put the thread to sleep for 0.5 second and request the next data when it wakes again. However, the performance that i get shows that the request for next data was done after 2 or 3 seconds, and during period where there is many data coming in, the delay could go up to 20 seconds.
Please advise.
Thx
# 3 Re: Threading Slow Down
There's no difference regarding the simultaneousness of your threads. Unless you are running a multiprocessor system, your threads must wait for processor-time.
Most threading-articles recommend using threading for small tasks that are not too time-consuming. Switching between threads is also costly.
Have you considered using a queue? Then you can have one or two threads (send / receive), where the send-thread is executing request-objects with requestId's from the queue.
# 4 Re: Threading Slow Down
There's no difference regarding the simultaneousness of your threads. Unless you are running a multiprocessor system, your threads must wait for processor-time.
Most threading-articles recommend using threading for small tasks that are not too time-consuming. Switching between threads is also costly.
Have you considered using a queue? Then you can have one or two threads (send / receive), where the send-thread is executing request-objects with requestId's from the queue.
Thx for the reply.
Maybe im new to this so i again missed some details of the system i'm maintaining. The system is monitoring the network transactions, so it has to constantly request data from the clients.
So the server will have 3 types of threads:
i) eg. 50 threads sending request for data,
ii) 1 thread listening for incoming data,
iii) other threads to do other task e.g. writing data received to log, and displaying received data in the UI.
As for the queue thing, i should use them for the sending of request for data right? i'll give that a try.
Or, could it be that the bottleneck is coming from the 1 thread that's listening for incoming data? Because the server hangs during period when there's alot incoming data. Hmm, what do you guys think?
Thanks again for the suggestion.
=)
# 5 Re: Threading Slow Down
Yes the queue would be for the requests.
I'm starting to doubt my suggestion though. I agree that the bottleneck seems to be the incoming thread. Or maybe GUI interaction.
Have you tried without displaying the received data in GUI? If several threads need access to GUI then at least you have a bottleneck, since this must use the same GUI-thread.
Also make sure the listening thread does as little work as possible. Actually you could use a queue here aswell (or instead). Just put the incoming message on a queue that another thread reads (for logging/GUI).