[erlang-questions] spawn problem
Fernando Ipar
fipar@REDACTED
Tue Mar 27 03:17:50 CEST 2007
Hello all,
I'm writing a little module to make use of erlang's lightweight
processes and load test external programs/servers.
Here's a very simple first version:
---- code ----
test(_, 0) ->
true;
test(Command, Threads) when number(Threads) ->
spawn('os', 'cmd', [Command]),
test(Command, Threads - 1).
start() ->
Command = list_to_atom(os:getenv("Command")),
Threads = list_to_integer(os:getenv("Threads")),
test(Command,Threads).
--- end code ----
I know this is a very rudimentary first version and I would have to take
more things into account, like the period of time
over which the processes are created (ala Jakarta James) and all, but
this is just a pet project to learn the basics of erlang by
doing something I find more useful than Fibonacci :)
My problem is that if I call this with more than 508 'Threads' (bear
with me on the variable name selection..) I get this error:
Error in process <0.1046.0> with exit value:
{emfile,[{erlang,open_port,[{spawn,"sh -s unix:cmd
2>&1"},[stream]]},{os,start_port,0},{os,unix_cmd1,2}]}
I get as many error messages as times I exceed the number 508.
I've looked around and it seems 'emfile' means too many open files,
which is strange, given the output of ulimit -a:
[fipar@REDACTED testing]$ ulimit -a
core file size (blocks, -c) 0
data seg size (kbytes, -d) unlimited
max nice (-e) 0
file size (blocks, -f) unlimited
pending signals (-i) 7663
max locked memory (kbytes, -l) 32
max memory size (kbytes, -m) unlimited
open files (-n) 1024
pipe size (512 bytes, -p) 8
POSIX message queues (bytes, -q) 819200
max rt priority (-r) 0
stack size (kbytes, -s) 10240
cpu time (seconds, -t) unlimited
max user processes (-u) 7663
virtual memory (kbytes, -v) unlimited
file locks (-x) unlimited
file locks (-x) unlimited
I've looked around sysctl -a and it seems everything's fine too.
While this project in particular is not important, I'll appreciate any
help with this problem, since I'd like to know how many processes I can
create in erlang, and what tweaking needs to be
done to the OS (if any).
On another note, I'm working on a rewrite of my HA project for MySQL in
erlang, also as a learning experience. This is still green, but if
anyone wants to let me know what you think
about the code, you can browse the svn repository here:
https://svn.sourceforge.net/svnroot/mysql-ha/trunk/mysql-ha-erl/
The script tabs.sh lets you replace \t (I use vim for programming) for
any given amount of whitespace.
Thanks in advance for any help.
Regards,
Fernando.
More information about the erlang-questions
mailing list