UNIX Socket FAQ

A forum for questions and answers about network programming on Linux and all other Unix-like systems

You are not logged in.

#1 2006-04-29 06:33 PM

teo_ramones
Member
Registered: 2006-04-29
Posts: 2

Re: max number of threads

hi

can u tell me please how can i find the nax numbers of threads in a sytem?

I thought that all i have to do was to run a while(1) for pthread_create() and when the number of threads the system can create is the max then it will stop and put me out of the while(1)....but as always my idea was wrong!

Can anyone help me please?

thanx a lot

Offline

#2 2006-05-04 10:50 AM

biologz
Administrator
From: Puking on the pavement
Registered: 2005-11-02
Posts: 396

Re: max number of threads

hi,

sorry but i know nothing about threads...but i'm just curious of what happenned with your infinite pthread_create?did your system crash?

I really don't know why nobody give you an answer... sorry again


gethostbyintuition() is still a dream of mine

                                                 -- quoted from bash

Offline

#3 2006-05-04 12:01 PM

i3839
Oddministrator
From: Amsterdam
Registered: 2003-06-07
Posts: 2,239

Re: max number of threads

On Linux you can read and set it with /proc/sys/kernel/threads-max. But with NPTL ulimit -u (max user processes) counts too. Though in practice it's probably the amount of memory and CPU speed which are the real big bottlenecks.

Offline

#4 2006-05-04 07:45 PM

teo_ramones
Member
Registered: 2006-04-29
Posts: 2

Re: max number of threads

hi biologz 

no reason to say sorry: )
no my system didnt crash......because when i create some threads i guess some other threads are deleted, so no reason to crash the system...

i'm still trying to do it work but i just cant do it....one friend of me did it and he used the cond_wait() , so the created threads wait and i can  count them...when i do it work i'll post the code.

yes i know about /proc/sys/kernel/threads-max .... but that doesn't means is the max threads my system can create because of memory and others parametres.for example ubuntu linux in the threads-max file has 8191 threads that can be created, but this doesnt mean my system can afford this number of threads as u also say.I have to see it in real time.Thnx for the answer.

sorry for the very bad english; )

Offline

#5 2006-05-04 08:46 PM

i3839
Oddministrator
From: Amsterdam
Registered: 2003-06-07
Posts: 2,239

Re: max number of threads

Oh, that kind of max number of threads. Well, that question isn't easy to answer, nor is it a very good question. It's like asking how many programs can run on your computer. It depends on your hardware and what you're running of course. Running hundred xterms is much easier than running hundred openoffice instances. With threads it's the same, though there CPU time is probably more scarse than memory, in the end.

The problem is that why else would you have thousands of threads if they've nothing to do? If they have nothing to do then they just waste memory, so let's assume they all have something to do, most of the time. Process timeslice is in general at least 5 ms. This means that, ignoring context switch overhead, at most 200 processes/threads can have the CPU each second. At 400 active threads the average scheduling latency will be one second. This is horrible for responsiveness, and practically not very useful. With a few thousand active threads the system is hardly usable.

As for plenty of inactive threads which do more or less nothing at all: They just waste memory, no real problem. Calculating how many you can have is slightly easier: Total ammount of free ram divided by 16Kb will give a good upper limit (assuming the program reduced the thread stack size from 8 Mb to 16 Kb).

Offline

#6 2006-05-15 01:02 AM

dazedandconfused
Guest

Re: max number of threads

Make sure you check your ulimit -u

This limit counts not just for processes but for threads within processes (apparently)

I was surprised to find a user under virtuozzo with redhat 9 only had a max ulimit of 20

that is 20 concurrent processes which includes threads

My app was running out of threads after starting just 7!!!!

when I ran the same app as root that jumped to the amount of available ram which meant I could start about 100 such threads.

This confused me for quite a while till I discovered this "feature"

#7 2006-07-05 07:12 PM

mlampkin
Administrator
From: Sol 3
Registered: 2002-06-12
Posts: 911
Website

Re: max number of threads

Been gone a while ( again )...

Just wanted to add the way to do the check programmatically... include limits.h and unistd.h and call...

sysconf( _SC_THREAD_THREADS_MAX )

Also - one comment on the total mem / thread size calculations...  that usually gives a good guestimate but you should make certain you are specifying a thread mem size that is on a page boundary for it to be as accurate as possible...


Michael


"The only difference between me and a madman is that I'm not mad."

Salvador Dali (1904-1989)

Offline

#8 2006-07-27 10:59 AM

mercy
Guest

Re: max number of threads

sorry but i know nothing about threads...but i'm just curious of what happenned with your infinite pthread_create?did your system crash?

I really don't know why nobody give you an answer... sorry again

#9 2006-07-27 11:20 AM

biologz
Administrator
From: Puking on the pavement
Registered: 2005-11-02
Posts: 396

Re: max number of threads

Pis* off mercy. Is it a bot again??


gethostbyintuition() is still a dream of mine

                                                 -- quoted from bash

Offline

#10 2006-08-02 09:58 PM

i3839
Oddministrator
From: Amsterdam
Registered: 2003-06-07
Posts: 2,239

Re: max number of threads

Oi, that's no way to talk to anyone biologz. If it isn't a bot, it's highly insulting, if it is, it just pollutes the forum.

But yes, I think it's a bot, so I've banned mercy. Mercy, if you aren't a bot then email me.

Offline

#11 2006-09-02 12:00 PM

max591
Guest

Re: max number of threads

?? ??? ?? ????????...

Yes max591...

How many users are you going to create... ?????????

Board footer

Powered by FluxBB