473,382 Members | 1,710 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Maximum number of threads

We are porting our applications from Python 2.2 on RH9 to Python 2.3 on
RH9. One of our apps used to be able to create threads with wild
abandon, 800 or more if necessary. With Python 2.3 we are hitting a
hard limit of 254 on RH9 and around 400 on FC2.

What is the limiting factor for the number of threads we can create? Is
there a way to increase it?

-- Kirby
Jul 18 '05 #1
6 4532
Kirby Angell <ka*****@alertra.com> writes:
We are porting our applications from Python 2.2 on RH9 to Python 2.3 on
RH9. One of our apps used to be able to create threads with wild
abandon, 800 or more if necessary. With Python 2.3 we are hitting a
hard limit of 254 on RH9 and around 400 on FC2.
What happens when you hit this "hard limit"? If there's an error
message then it might hint at the problem.
What is the limiting factor for the number of threads we can create? Is
there a way to increase it?


I'm not current on Linux threading models -- do these versions of
Linux create a new process for each thread? If so, could resource
limits be preventing you from creating more threads?

--
Michael Fuhr
http://www.fuhr.org/~mfuhr/
Jul 18 '05 #2
Michael Fuhr wrote:
What happens when you hit this "hard limit"? If there's an error
message then it might hint at the problem.
If I run this program:

import thread, time

def t(parm1,parm2):
time.sleep( 1000 )

tc = 0
try:
while 1:
thread.start_new_thread( t, (None,None) )
tc += 1
time.sleep( 0.05 )
finally:
print tc
This is the result:
$ python t.py
404
Traceback (most recent call last):
File "t.py", line 12, in ?
thread.start_new_thread( t, (None,None) )
thread.error: can't start new thread
I'm not current on Linux threading models -- do these versions of
Linux create a new process for each thread? If so, could resource
limits be preventing you from creating more threads?


I don't think Linux creates a new process for each thread. Sure seems
like this would have to be something related to python since 2.2 could
create a thousand or more threads. Although I have to admit that it is
odd that the maximum number of threads I can create on RH9 is different
than on FC2.
Jul 18 '05 #3
Kirby Angell wrote:
Michael Fuhr wrote:
What happens when you hit this "hard limit"? If there's an error
message then it might hint at the problem.

If I run this program:

<snip>
I'm not current on Linux threading models -- do these versions of
Linux create a new process for each thread? If so, could resource
limits be preventing you from creating more threads?

I don't think Linux creates a new process for each thread. Sure seems
like this would have to be something related to python since 2.2 could
create a thousand or more threads. Although I have to admit that it
is odd that the maximum number of threads I can create on RH9 is
different than on FC2.

Versions of RedHat prior to 9 did something that made it appear that
each thread was a process. I don't know all the ins and outs (I think
it had something to do with user-space vs. kernel-space), but when the
Native Posix Thread Library (NPTL) appeard in RH9, each thread did not
show up as its own process (say, in top). I think it's probably an OS
limitation. I kicked off the same script on Windows XP that I kicked
off on FC2 and XP was able to generate over 2000 threads as opposed to
around 400 for FC2. I may be wrong, but I think Python relies on the
underlying OS threading libraries for everything threading related.
Which is probably why the recent change in either 2.2 or 2.3 for a dummy
threading module that simulates threading on systems that do not support
threading. I know my babbling isn't getting you any closer to a
solution.....
Jeremy Jones
Jul 18 '05 #4
Jeremy Jones wrote:

around 400 for FC2. I may be wrong, but I think Python relies on the
underlying OS threading libraries for everything threading related.
Which is probably why the recent change in either 2.2 or 2.3 for a dummy
threading module that simulates threading on systems that do not support
threading. I know my babbling isn't getting you any closer to a
solution.....


No, your babbling has gotten me much closer. I'm not sure what changed
between Python 2.2 and Python 2.3, but the problem is the stack size
allocated to each thread. Apparently with glibc on RH9 something along
the order of 8 MB of virtual memory is allocated for the stack of each
thread. 256 threads takes us to the virtual memory limit of the process
itself. Glibc on FC2 must be using a different default stack size, or
the virtual memory limit is higher; I've only recently started running
FC2 on our test servers so I'm not sure which it is.

The only way to change the stack size is to define THREAD_STACK_SIZE in
the thread_pthread.h header. There is an ifdef for the Mac that sets
this to 64k. Just as a test I forced THREAD_STACK_SIZE to that value
and recompiled Python. I can now create 16k threads although I'm not
sure yet whether our application will run; some tuning is probably in
order. I'm going to get the 2.2 source code and see what is different
between the two and maybe get an idea of what a reasonable stack size is.

There is a very nice write-up on the basic issue here:

http://www.kegel.com/stackcheck/

Thanks for your help.
Jul 18 '05 #5
On Wed, 29 Sep 2004, Kirby Angell wrote:
No, your babbling has gotten me much closer. I'm not sure what changed
between Python 2.2 and Python 2.3, but the problem is the stack size
allocated to each thread. Apparently with glibc on RH9 something along
the order of 8 MB of virtual memory is allocated for the stack of each
thread. 256 threads takes us to the virtual memory limit of the process
itself. Glibc on FC2 must be using a different default stack size, or
the virtual memory limit is higher; I've only recently started running
FC2 on our test servers so I'm not sure which it is.

The only way to change the stack size is to define THREAD_STACK_SIZE in
the thread_pthread.h header. There is an ifdef for the Mac that sets
this to 64k. Just as a test I forced THREAD_STACK_SIZE to that value
and recompiled Python. I can now create 16k threads although I'm not
sure yet whether our application will run; some tuning is probably in
order. I'm going to get the 2.2 source code and see what is different
between the two and maybe get an idea of what a reasonable stack size is.


ISTR that the default stacksize for the LinuxThreads threading
implementation (prior to NPTL) was 1MB.

It is also worth noting that more recent versions of gcc (3.x) are
generating larger stack frames than older versions; something that has
affected building the SRE module until it was made non-recursive for
Python 2.4. This has probably encouraged the bump in the default stack
size.

-------------------------------------------------------------------------
Andrew I MacIntyre "These thoughts are mine alone..."
E-mail: an*****@bullseye.apana.org.au (pref) | Snail: PO Box 370
an*****@pcug.org.au (alt) | Belconnen ACT 2616
Web: http://www.andymac.org/ | Australia
Jul 18 '05 #6
Jeremy Jones <za******@bellsouth.net> wrote in message news:<ma**************************************@pyt hon.org>...
I don't think Linux creates a new process for each thread. Sure seems
like this would have to be something related to python since 2.2 could
Versions of RedHat prior to 9 did something that made it appear that
each thread was a process.


Older versions of ps/top showed all threads instead of just processes.

You can still see them with the right flags (e.g. the H option to
ps, "ps auxH").
I think it's probably an OS limitation. I kicked off the same script on
Windows XP that I kicked off on FC2 and XP was able to generate over
2000 threads as opposed to around 400 for FC2.


I have no problems creating 2000 threads in FC2 from C. haven't tried
it in python. Resource limits are the first issue that comes to mind
for me, followed by kernel versions (esp. if you're running a 2.2 or
earlier kernel for some reason).
Jul 18 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Tzach | last post by:
I'm developing a simple Java client that runs over a CORBA server. The main client thread is waiting for notification from this server. On each notification, The client creates a new thread...
0
by: David.Tymon | last post by:
>Description: MySQL v4.1.0-alpha only allows a client to prepare a maximum of 254 statements. On the 255th mysql_prepare() call, a failure is returned with no information returned by...
2
by: Kums | last post by:
What is the maximum permissible size of a database? Is there any limitation. What is the maximum # of tablespace's allowed in a database? Thanks for your response.
1
by: K. Davis | last post by:
I need to increment the maximum value of a field of a table by 1 when a form opens a blank record. (e.g. =max(!![trip_number}) so the logic and references are working at the form level. I've...
3
by: Raghu Rudra | last post by:
By default, the machine.config contains following information: <system.net> ....... <connectionManagement> <add address="*" maxconnection="2"/> </connectionManagement> </system.net> This...
1
by: Dominic | last post by:
I'd like to tune the performance of my application in a web garden. Our server has dual processors. Is there any guideline to set this "maximum number of worker processes" for web garden? In my...
4
by: Amir Shitrit | last post by:
What is the maximum number of threads Windows supports (for all processes), and what's the maximum number of threads available per process? Thanks.
12
by: Paul Sijben | last post by:
I have a server in Python 2.5 that generates a lot of threads. It is running on a linux server (Fedora Core 6). The server quickly runs out of threads. I am seeing the following error. File...
5
by: linda.chen | last post by:
Hi all, We have a webservice (service1), which calls another webservice(service2) from another orginization. Our end users make requests throught service1. When service2 receives a quest, it...
6
by: =?Utf-8?B?U2hhcm9u?= | last post by:
I'm using the VScrollBar and set it as follow: m_vScrollBar.Minimum = -19602; m_vScrollBar.Maximum = 0; m_vScrollBar.SmallChange = 1; m_vScrollBar.LargeChange = 1089; m_vScrollBar.Value =...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.