hello all,
i have run into a problem where i cannot start more than 1021 threads
in a python program, no matter what my ulimit or kernel settings are.
my program crashes with 'thread.error: can't start new thread' when it
tries to start the 1021st thread.
in addition to tweaking my ulimit settings, i have also verified that
the version of glibc i'm using has PTHREAD_THREADS _MAX defined to be
16374. i have posted my test program below as well as the ulimit
settings i was running it with. any help would be greatly appreciated.
thanks in advance,
dan smith
<program>
import os
import sys
import time
import threading
num_threads = int(sys.argv[1])
def run ():
# just sleep
time.sleep(1000 0)
for i in range(1,num_thr eads+1):
print 'starting thread %d' %i
t=threading.Thr ead (None, run)
t.start()
os._exit(1)
</program>
<ulimit -a>
core file size (blocks, -c) 0
data seg size (kbytes, -d) unlimited
file size (blocks, -f) unlimited
max locked memory (kbytes, -l) 4
max memory size (kbytes, -m) unlimited
open files (-n) 1000000
pipe size (512 bytes, -p) 8
stack size (kbytes, -s) unlimited
cpu time (seconds, -t) unlimited
max user processes (-u) unlimited
virtual memory (kbytes, -v) unlimited
</ulimit -a> 11 4348
also, on the same box a similar C program (posted below) has no problem
starting 5000+ threads.
#include <stdlib.h>
#include <stdio.h>
#include <sys/time.h>
#include <pthread.h>
void *
run (void *arg) {
sleep(1000);
}
int main(int argc, char *argv[]) {
int j;
pthread_t tid;
int num_threads = atoi(argv[1]);
for (j=0; j < num_threads; j++) {
pthread_create (&tid, NULL, run, NULL);
printf("created thread %d\n",j);
fflush(stdout);
}
sleep(1000);
}
disregard the C example. wasn't checking the return code of
pthread_create. the C program breaks in the same place, when creating
the 1021st thread. da**********@gm ail.com wrote: disregard the C example. wasn't checking the return code of pthread_create. the C program breaks in the same place, when creating the 1021st thread.
So that's pretty good evidence that it's an OS limit, not a
Python limit. The most likely problem is that the stack size is
too large, so you're running out of virtual address space.
--
--Bryan
i modified my C test program (included below) to explicitly set the
default thread stack size, and i'm still running into the same
problem. can you think of any other thing that would possibly be
limiting me?
and sorry to continue to post here. since this is occurring in both c
and python, i think there's no question i'm running into an os limit.
#include <stdlib.h>
#include <stdio.h>
#include <sys/time.h>
#include <pthread.h>
void *
run (void *arg) {
sleep(1000);
}
int main(int argc, char *argv[]) {
int j;
int ret;
pthread_t tid;
int num_threads = atoi(argv[1]);
pthread_attr_t attr;
int stacksize;
pthread_attr_in it(&attr);
pthread_attr_ge tstacksize (&attr, &stacksize);
printf("Default stack size = %d\n", stacksize);
// set stack size to 64K
pthread_attr_se tstacksize (&attr, 0x10000);
pthread_attr_ge tstacksize (&attr, &stacksize);
printf("New stack size = %d\n", stacksize);
for (j=0; j < num_threads; j++) {
ret = pthread_create (&tid, NULL, run, NULL);
if (ret != 0) {
printf("thread create failed\n",j);
fflush(stdout);
exit(0);
}
printf("created thread %d\n",j);
fflush(stdout);
}
sleep(1000);
} da**********@gm ail.com wrote: and sorry to continue to post here. since this is occurring in both c and python, i think there's no question i'm running into an os limit.
Probably, but I haven't yet seen anyone ask the real important question.
What possible use could you have for more than 1000 *simultaneously
active* threads? There are very likely several alternative approaches
that will fit your use case and have better characteristics (e.g. higher
performance, simpler code, safer architecture, etc).
-Peter
Peter Hansen wrote: Probably, but I haven't yet seen anyone ask the real important question. What possible use could you have for more than 1000 *simultaneously active* threads? There are very likely several alternative approaches that will fit your use case and have better characteristics (e.g. higher performance, simpler code, safer architecture, etc).
Threading systems have come a long way in the last decade or so,
and they're still advancing. 64-bit, multi-core processors make
mega-threading even more attractive.
To read why zillions of threads are good, see: http://www.usenix.org/events/hotos03...vonbehren.html
For an example of a high-performance server that uses massive
threading, I'd nominate MySQL.
Prediction: Ten years from now, someone will ask that same
"What possible use..." question, except the number of threads
will be a million.
--
--Bryan da**********@gm ail.com wrote: i modified my C test program (included below) to explicitly set the default thread stack size, and i'm still running into the same problem. can you think of any other thing that would possibly be limiting me?
Hrm, you're on an A64, so that might very well mean you're dealing with
4MB pages. If each thread gets its own page of memory for stack space
regardless of how small you've set it, then ~1k threads * 4MB ~= 4GB of
virtual memory.
Bryan Olson wrote: Peter Hansen wrote: > Probably, but I haven't yet seen anyone ask the real important question. > What possible use could you have for more than 1000 *simultaneously > active* threads? There are very likely several alternative approaches > that will fit your use case and have better characteristics (e.g. higher > performance, simpler code, safer architecture, etc). Threading systems have come a long way in the last decade or so, and they're still advancing. 64-bit, multi-core processors make mega-threading even more attractive.
To read why zillions of threads are good, see: http://www.usenix.org/events/hotos03...vonbehren.html
Judging by the abstract alone, that article promotes "user-level"
threads, not OS threads, and in any case appears (with a quick scan) to
be saying nothing more than that threads are not *inherently* a bad
idea, just that current implementations suffer from various problems
which they believe could be fixed.
My question was in the context of the OP's situation. What possible use
for 1000 OS threads could he have? (Not "could his requirements be
answered with a non-existent proposed improved-performance
implementation of threads?")
Prediction: Ten years from now, someone will ask that same "What possible use..." question, except the number of threads will be a million.
Perhaps. And in ten years it will still be a valid question whenever
the context is not fully known. Is the OP's situation IO-bound,
CPU-bound, or just an experiment to see how many threads he can pile on
the machine at one time? The fact that these threads are all sleeping
implies the latter, though what he posted could have been a contrived
example. I'm interested in the real requirements, and whether more than
1000 threads in this day and age (not some imaginary future) might not
be a poor approach.
(For the record, Bryan, I am a strong proponent of thread systems for
many of the reasons the authors of that article put forth. None of
which means my question was without merit.)
-Peter
Peter Hansen wrote: My question was in the context of the OP's situation. What possible use for 1000 OS threads could he have?
Is this a language thing? Surely you realize that "what possible
use could <thing> be" carries an insinuation that <thing> is not
such a good idea. Possible uses are many and perfectly
reasonable, such as building a quick, responsive server like
MySQL.
Is the OP's situation IO-bound, CPU-bound, or just an experiment to see how many threads he can pile on the machine at one time? The fact that these threads are all sleeping implies the latter, though what he posted could have been a contrived example. I'm interested in the real requirements, and whether more than 1000 threads in this day and age (not some imaginary future) might not be a poor approach.
If you're interested in his requirements, why not just ask him
about his requirements? Kind of premature to condemn his
approach.
--
--Bryan This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Stephen Horne |
last post by:
I started making up a Python extension module to wrap a C++ library of
mine using Boost Python. Trouble is, the library has a number of
classes each of which has a lot of methods. I seem to have hit an
internal limit in the Visual C++ 7 compiler.
The output I get is...
"""
....found 2031 targets...
....updating 4 targets...
|
by: Anthony Baxter |
last post by:
On behalf of the Python development team and the Python community, I'm
happy to announce the release of Python 2.3.1 (final).
Python 2.3.1 is a pure bug fix release of Python 2.3, released in late
July. A number of obscure crash-causing bugs have been fixed, various
memory leaks have been squished, but no new features have been added to
the language or to the library.
For more information on Python 2.3.1, including download links for...
|
by: Leandro |
last post by:
There is an upper memory limit in Python?
I have 2GB RAM and 2 processors Xeon 2.4 - (Windows XP), but I just can use
1.2G of memory, after this python crashes.
Does someone know if python has some memory limit?
|
by: Axel Mittendorf |
last post by:
Hi, I have an app that writes text messages into a pipe and reads it out.
Other programs write into this pipe too. Sometimes the pipe is full and
my app freezes if it wants to write in that moment. It is not an option
for me to open the pipe with O_NONBLOCK, so I thought I could
use threads. Always when something shall be written into the pipe a new
thread is created. These threads may hang on os.write, but they'll write out
the data ASAP....
|
by: phil |
last post by:
And sorry I got ticked, frustrating week
>And I could help more, being fairly experienced with
>threading issues and race conditions and such, but
>as I tried to indicate in the first place, you've
>provided next to no useful (IMHO) information to
>let anyone help you more than this
This is about 5% of the code.
Uses no locks.
| |
by: zxo102 |
last post by:
Hi,
I am doing a small project using socket server and thread in python.
This is first time for me to use socket and thread things.
Here is my case. I have 20 socket clients. Each client send a set
of sensor data per second to a socket server. The socket server will
do two things: 1. write data into a file via bsddb; 2. forward the data
to a GUI written in wxpython.
I am thinking the code should work as follow (not sure it is
feasible)...
|
by: Kevin |
last post by:
Using this:
http://msdn2.microsoft.com/en-us/library/3dasc8as(VS.80).aspx
as an example I have a question concerning the reuse of objects. In
the example 10 instances of the Fibonacci class are made and then all
put in the threadpool at once, which is well within the limits of the
threadpool.
However, what happens if you want to do 10,000 Fibonacci calculations
|
by: Adam Olsen |
last post by:
It seems to be a commonly held belief that basic dict operations (get,
set, del) are atomic. However, since I know searching the hash table
is a multistep process, I thought I'd check it out for sure.
First, my assumption is that one thread is attempting to get a single
key, while other threads are getting, setting, and deleting different
keys. Obviously you could fail anyway if they were modifying the same
key.
The avenue of attack...
|
by: Creativ |
last post by:
Why does Thread class not support IDisposable? It's creating quite
some problem. Namely, it can exhaust the resource and you have not
control over it.
|
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...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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...
|
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,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
| |
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...
| |