|Syntactic Confectionery Delight|
Using signals in Perlby leons (Pilgrim)
|on Mar 28, 2001 at 19:49 UTC||Need Help??|
leons has asked for the
wisdom of the Perl Monks concerning the following question:
I hope someone can give me some advice on the following. Right now
I'm writing a program which will be used for load-test purposes on
one of our mailservers here.
The program can be configured to send a certain amount of messages
over a configurable number of sessions to another system. (No, this
is not for spam-purposes ..... just to make sure ;-)
At first I wrote the program in a kind of way that it would open the
preferred number of sessions and then it would send the messages over
these sessions. This would happen then, more or less, sequentially
I didn't take me long to figure out that it would definitely be a
lot quicker if I were to fork the same number of processes as there
needed to be sessions. Which would then, each start it's own session
to the mailserver
After that came the problem. The program had to have a progress-counter
which would state the number of messages that had been sent. The first
thing I tried was having all the child processes write a '.' to a text-
file, which would then be read by the parent (every 5 seconds or so) for
as long as the number of dots was less than the number of messages that
had need to be sent.
This worked perfectly although it wasn't a very elegant way of doing this,
I think. Then someone proposed to use signals ... which is what I did.
Every child would send a SIGUSR2 to the parent each time a message was sent.
But strange enough the total of signals sent to the parent never came close
to the actual number of messages sent. Not knowing how this signalling stuff
actually worked, someone told me a signal was nothing more than some flag in a
register. Which perfectly explained the fact that there were 'messages missing'
... this was ofcourse because of the fact that some signals were send simulta-
So I hope someone can give me some advice on this timing/signalling problem ...
or should I just stick with the Dot-solution ? Which, I must confess,
doesn't have my preference
Any advice is more than welcome !