How many threads do I use ?


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users How many threads do I use ?
# 1  
Old 07-16-2007
How many threads do I use ?

Hi,

I have a program that has two types of threads:

1) Reader threads
2) Worker Threads

Readers: Their only job is to read files. They just read data from the files and put them into a buffer. They are obviously I/O intensive.

Workers: These are CPU intensive. They do some computation on the data which has been put into these buffers.

How many threads:

1) Worker: I think this answer is obvious. The number of worker threads should be equal to the number of CPUs in the sytem.

2) Reader: What about these? How can I determine the capability of I/O system ?

Specifically, I want the user to be able to specify the number of Reader and Worker threads the would like the program to use.

QUESTION: What guidelines should the user follow or use to determing this number ? How can they determine the capabilities of the I/O subsystem?

(The program uses 1 reader and 4 worker threads by default)
# 2  
Old 07-16-2007
I guess the best way would be to include some sort of short benchmark testing ability in your program: the user tweaks the number of threads, chooses to benchmark, then the program tries for say 30 seconds to do as much work as possible, then outputs how many work units each type of thread got through?

I guess the number of workers would be platform specific, so for example, on Linux 2.6 you probably want nCPUs+1, whereas on Solaris10 on a T2000 you only want nCPUs worth of workers.

For readers, you probably don't want a hard disk to be in contention between 2 threads, but having a channel (SCSI or ATA) shared is probably a good move - to ensure that channel is saturated. So i guess readers boils down to the number of hard disk spindles you'll be touching.

Cheers,

-c

p.s. i tried to find some material that backs up my assertion you want nCPUs+1 worker threads on Linux2.6 (i heard this somewhere before), but i couldn't find any, so maybe i'm wrong there? Anyone else know?
# 3  
Old 07-16-2007
Quote:
Originally Posted by the_learner
Readers: Their only job is to read files. They just read data from the files and put them into a buffer. They are obviously I/O intensive.
Are these reading from files or from sockets? If so you could multiplex using select() so you only need a couple of threads to manage the select rather than a thread per socket.

If they are reading from files, do the files have to be read in parallel?
# 4  
Old 07-16-2007
Thanks for the replies !

Quote:
Originally Posted by porter
If they are reading from files, do the files have to be read in parallel?
Not necessarily. They just have to read the files into a buffer.
# 5  
Old 07-17-2007
Hey, I have another question. Lets say I start this program on one machine. Then while it is running, I open up another console, log into the same machine and run the same program. Now there are two programs running. So now these two processes will compete against each other for the system resources right. So, obviously the program will take more time to complete. Am I right ? In general, as system load increases.. more users log onto the same system and start their own programs, the time taken by my program will increase right ?
# 6  
Old 07-17-2007
Quote:
Originally Posted by the_learner
the time taken by my program will increase right ?
Yes, no and maybe but not necessarily in that order Smilie.

1. You can adjust processes priority with nice.

2. A multi-user system shares it's resources, that's what they do.

3. Different architectures scale differently, some linearly, some exponentially.

4. A multiple CPU machine will exhibit different characteristics to a single CPU system.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Post Here to Contact Site Administrators and Moderators

Threads disappeared

Dear admins, it seems that some threads or even users have recently (~ 2 days or so) disappeared. Examples: giuliangiuseppe and greycells. The latter asked me for the solution I provided earlier this week. What happened? Can you help? Regards Rüdiger (10 Replies)
Discussion started by: RudiC
10 Replies

2. What is on Your Mind?

Why not more DEVOPS threads?

Hello all, searching for answers about our upcomming infrastructure in my compagny i was sadden by the fact that in my favorite programming forum there was basicly no threads about devops subjects or continious integration platform. Would be fun to know people workflows in their compagny and... (0 Replies)
Discussion started by: maverick72
0 Replies

3. Programming

Java Threads

Hi guys, I want to start studding about java threads. but the only book available on the market is "Java Threads" by O'Reilly... (0 Replies)
Discussion started by: majid.merkava
0 Replies

4. Programming

problem with threads in C

I have problem that if I create for example 100 threads program work correctly but if I define more threads for example 1000 // if I change static int NUM_E from 100 to 1000 than program stop about 350 threads and doesn't continue where should be problem please? #include <pthread.h>... (4 Replies)
Discussion started by: Sevco777
4 Replies

5. Programming

Threads help

Hello! I started studying studying about POSIX Threads a few days ago... so I am a little confused and I would appreciate some help! I isolated this code... and I wonder if I could use threads in it! #include <unistd.h> #endif #include <math.h> //#include "main.h" #include <sys/time.h>... (1 Reply)
Discussion started by: smurf2
1 Replies

6. UNIX for Advanced & Expert Users

Threads and Threads Count ?

Hi all, How can I get the list of all Threads and the Total count of threads under a particular process ? Do suggest !! Awaiting for the replies !! Thanks Varun:b: (2 Replies)
Discussion started by: varungupta
2 Replies

7. Solaris

threads

Hi all! 1)Is there a way to write a program that will work on both solaris and intel based machines. 2)How can I achive this for a program that creates and synchronizes three threads. Thank you. vij. (3 Replies)
Discussion started by: vijlak
3 Replies

8. UNIX for Dummies Questions & Answers

threads

i am tring to sort lots of data thats in many columns by just one column but, if I use sort +16 inputfile the column fluctuates because some of the rows have spaces etc within the text, so the end result is just a mess as it jumps around the columns depending whether it has spaces or not ....ie... (2 Replies)
Discussion started by: Gerry405
2 Replies

9. Post Here to Contact Site Administrators and Moderators

old threads

Neo, if I have an old thread that is a few months old, and a few pages back in the forum it was posted in, is it ok to 'bump' it back to the front? or, would you rather i deleted the old thread, and just create a new one? btw the thread has no replies. (2 Replies)
Discussion started by: norsk hedensk
2 Replies
Login or Register to Ask a Question