Thread or Not Thread

Bernie

Well-known member
Joined
Aug 13, 2007
Messages
98
Programming Experience
3-5
I have an application that prints statements for customers. Depending on the user's database size, it can pull anywhere from 1,000 to 10,000 customers from the database and then needs to calculate each one's bills.

The application currently creates a thread to handle the process of creating all the statements, so the GUI thread stays responsive and gives progress feedback to the user.

On the low end with around 2,000 customers, the single worker thread processes in a reasonable time, assuming fairly recent hardware in the server and workstation. On the high end, this process can take 10 to 20 minutes to complete.

I'm been doing some reading on threading and improving my knowledge about threading. My question is:

Would it be a good idea to take each customer statement creation process and cast that off as a seperate thread?

I'm currently researching thread pooling and how this would be done, but I'm looking for some guidance from the experts on if this is a good idea or not.

Thanks,
Bernie
 
Have a look at the CPU meter when running the work, if it's at 100% there isn't more hardware resources available anyway if you should distribute the work over more threads, actually you could see a performance decrease in this case. A thread itself takes some resources for memory so you wouldn't start 1000 simulatenous threads in any case, using Threadpool would be the way to go. So if you see you have CPU capasity available when using only one thread you can benefit from distributing the work over more threads. Take into account also if you have multiple cpu cores, one thread will only use one cpu, if you have more then using two or more threads will process faster as OS loads them to different CPUs.
 
On my dual core development machine, I can almost get up to 50% which would be one core, with the db local on that machine. On most customer's machines it around 20% running over a network. I'm assuming most of the delay is waiting on the data to return from the server.

Bernie
 
That is also a dependency and consideration, the waiting on the possible other machine to return data, how big that part of the task is, and if you can divide that part up in multiple threads. If you can process data while other data is retrieved, it would take less time than first waiting for all raw data - then process all.
 
Back
Top