Max threads

Started by Jeff, September 18, 2007, 09:44:00 AM

Previous topic - Next topic

Jeff

I am throwing an error when starting 72 or more threads on OSX in the latest dev version (9.2 does the same).  It happens regardless of the expression I am forking.  I'm on a pretty powerful machine- there should be no way it's running out of memory.  The default max memory being used is 4 gigs (which is the ram in the machine) and setting the stack size makes no difference (and probably shouldn't).



Any ideas?
Jeff

=====

Old programmers don\'t die. They just parse on...



http://artfulcode.net\">Artful code

Jeff

#1
Ok, it's not always 72, but it doesn't go much higher, and it seems like even the simplest operations (like incrementing an integer) die around there.
Jeff

=====

Old programmers don\'t die. They just parse on...



http://artfulcode.net\">Artful code

jrh

#2
The default number of procs per user session in OS X is 100.  There is a configuration parameter maxprocperuid in a .conf file over in /etc (i forget which) that you can set to override this limit.

Jeff

#3
Thanks!  That fixed it (well, that and a wrapper for WindowServer that lets it run with a higher maxproc as well).
Jeff

=====

Old programmers don\'t die. They just parse on...



http://artfulcode.net\">Artful code

jrh

#4
There are a number of subsystems that have configurable settings at startup.  You can run the command sysctl -a to see all of them.



Everything is called from the /etc/rc file and it is usually a good idea to place your custom changes in the appropriate file called by rc such as (in this instance) sysctl.conf rather than editing rc as it is one of those files that may be overwritten by Apple during a software update.

Jeff

#5
The problem is that the window server apparently is setting ulimit -u 100 when it starts up, and anything run through the windowserver (including procs run by TextMate, the editor I use) has to obey that.
Jeff

=====

Old programmers don\'t die. They just parse on...



http://artfulcode.net\">Artful code

jrh

#6
You can stick the command ulimit -u 256 (or whatever number) in bashrc (or lower) and then all user privilege level shells and child processes will inherit that limit for the lifetime of the process.

Jeff

#7
What about processes launched through WindowServer?  If TextMate launches a process, doesn't it inherit its environment from WindowServer's?  Additionally, does WindowServer even run from bash?
Jeff

=====

Old programmers don\'t die. They just parse on...



http://artfulcode.net\">Artful code

jrh

#8
Hmmmm..  It looks like WindowServer is started by mach_init way before any global shell stuff is executed.  Just check to make sure your custom wrapper hasn't been nuked after a software upgrade.



So does OS X distribute your forked procs over all the processors?  :-)

Jeff

#9
Yep.  For small ops it is completely unhelpful, though, because of the serialization overhead.  But for something like writing a large number of files (the specific purpose I am using it for) it should make a nice difference.
Jeff

=====

Old programmers don\'t die. They just parse on...



http://artfulcode.net\">Artful code