Which Better Thread or ThreadPool
-
Hi all, I m doing work on application like remote desktop. I have made a server and client. Server Description: server first listen for client request. Upon receiving client request server Starts a thread using ThreadStart and delegates a function that handling all the things like capturing desktop image, break that image into parts, calculating checksum for updated parts, saving image into Networkstream and sending updated region to client. I m doing all the work in one thread function. Problem: I m facing problem of CPU usage. Currently My CPU usage on server side is 45 to 60% thats not acceptable. I think that CPU usage is due to the poor threading. Someone suggest me to use threadpool but threadpool is usefull for short time threads. Can someone suggest me how can i improve CPU usage and application performance. Is there any effect by increasing the number of threads? Keeping in mind that it is real time application. Tahnx for ur suggestions
-
Hi all, I m doing work on application like remote desktop. I have made a server and client. Server Description: server first listen for client request. Upon receiving client request server Starts a thread using ThreadStart and delegates a function that handling all the things like capturing desktop image, break that image into parts, calculating checksum for updated parts, saving image into Networkstream and sending updated region to client. I m doing all the work in one thread function. Problem: I m facing problem of CPU usage. Currently My CPU usage on server side is 45 to 60% thats not acceptable. I think that CPU usage is due to the poor threading. Someone suggest me to use threadpool but threadpool is usefull for short time threads. Can someone suggest me how can i improve CPU usage and application performance. Is there any effect by increasing the number of threads? Keeping in mind that it is real time application. Tahnx for ur suggestions
Thread context switching is expensive and having too many threads active in your application is no better than doing everything in one thread. The
ThreadPool
class is for bette scalable solutions because the system will enlarge the pool if necessary (based on the performance of the application and if it can handle more) and doesn't have to create new threads but, instead, reuses existing threads which also decreases overhead. There's a lot of blogging about this at http://blogs.msdn.com[^] you should check out if you're interested. This posting is provided "AS IS" with no warranties, and confers no rights. Software Design Engineer Developer Division Customer Product-lifecycle Experience Microsoft [My Articles] [My Blog] -
Thread context switching is expensive and having too many threads active in your application is no better than doing everything in one thread. The
ThreadPool
class is for bette scalable solutions because the system will enlarge the pool if necessary (based on the performance of the application and if it can handle more) and doesn't have to create new threads but, instead, reuses existing threads which also decreases overhead. There's a lot of blogging about this at http://blogs.msdn.com[^] you should check out if you're interested. This posting is provided "AS IS" with no warranties, and confers no rights. Software Design Engineer Developer Division Customer Product-lifecycle Experience Microsoft [My Articles] [My Blog]Thanx dear, But i have generated the profile of my server application while it is sending updated desktop regions and i have noticed that least CPU time is used by the code which capture images, calculate checksum , save into memory stream and writing data on network stream. Then where is CPU used? Why it goes to upper limit of usage? I think its due to the not properly managed thread.
-
Hi all, I m doing work on application like remote desktop. I have made a server and client. Server Description: server first listen for client request. Upon receiving client request server Starts a thread using ThreadStart and delegates a function that handling all the things like capturing desktop image, break that image into parts, calculating checksum for updated parts, saving image into Networkstream and sending updated region to client. I m doing all the work in one thread function. Problem: I m facing problem of CPU usage. Currently My CPU usage on server side is 45 to 60% thats not acceptable. I think that CPU usage is due to the poor threading. Someone suggest me to use threadpool but threadpool is usefull for short time threads. Can someone suggest me how can i improve CPU usage and application performance. Is there any effect by increasing the number of threads? Keeping in mind that it is real time application. Tahnx for ur suggestions
Thats not neccessarily true, you need a profiler to actually to find out whats going on, try checking some of the perf counters while your app is running, maybe you are allocating several objects and not disposing them causing the GC to run often, The network stream could also be acting asychronously If you are having more than one client connecting to your server then possibly the ThreadPool will be better as it will manage your thread allocation more efficiently.
-
Thats not neccessarily true, you need a profiler to actually to find out whats going on, try checking some of the perf counters while your app is running, maybe you are allocating several objects and not disposing them causing the GC to run often, The network stream could also be acting asychronously If you are having more than one client connecting to your server then possibly the ThreadPool will be better as it will manage your thread allocation more efficiently.
Thanx You have mentioned that network stream could also be acting asychronously. But i m not using it asynchronously then how?