473,721 Members | 2,259 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 4551
Kirby Angell <ka*****@alertr a.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_ne w_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_ne w_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_SI ZE 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_SI ZE 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_SI ZE 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_SI ZE 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*****@bullsey e.apana.org.au (pref) | Snail: PO Box 370
an*****@pcug.or g.au (alt) | Belconnen ACT 2616
Web: http://www.andymac.org/ | Australia
Jul 18 '05 #6
Jeremy Jones <za******@bells outh.net> wrote in message news:<ma******* *************** *************** *@python.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
30668
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 executing some logic with the server and close. Each session spend most of the time waiting for the server. At most there can be ~1000 open session. My questions are: 1. How many threads can be open at the same time (with response time of up to ~1...
0
3007
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 mysql_error(). This occurs even if the statements are closed after each use. >How-To-Repeat: The following program highlights the problem. Just change the connection details to some database. It also assumes there is a table called dummy,
2
28593
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
1928
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 tried a number of variants tied to the before update event, but always get the message "The field 'tripmain.trip_number' can't contain a Null value because the Required property for this field is set to True. Enter a value in this field."
3
12221
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 limits the number of connections to web server to 2. For example, if
1
9612
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 application, stress test shows that setting it to 2 gives a better performance result. In other words, web garden helps. My first question is if it helps to set a number larger than the number of processors in the server. Are they related at all? ...
4
6898
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
18992
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 "/home/sijben/ORCA/src/libmercury_mt.py", line 565, in __init__ MercuryObject.__init__(self,mylink) File "/home/sijben/ORCA/src/libmercury_mt.py", line 223, in __init__
5
2562
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 puts all the request information into a database. The request will be picked up from a sheduler which is installed in 8 different servers. The response is very slow if we have many requests.
6
10703
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 = m_vScrollBar.Maximum; The scroll bar is set to start from the bottom.
0
8840
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9367
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9215
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9131
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8007
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6669
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5981
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3189
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2130
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.