Running multiple simultaneous interpreters/scripts

I have a setup where cron is calling N instances of a particular Ruby
script simultaneously. It seems that as N increases, the delay before
each script executes its first line of code increases by a little less
than N seconds. I’m not sure if this is an issue with cron or if it’s
the cumulative startup time for N ruby interpreters. An ideas on how to
speed this up to a near constant (~<1sec) delay? Is there a way to run
all N scripts simultaneously with a single interpreter process? Thanks.

I’m using 1.8.5 on fc6.

Earle

Earle C. wrote:

I have a setup where cron is calling N instances of a particular Ruby
script simultaneously. It seems that as N increases, the delay before
each script executes its first line of code increases by a little less
than N seconds. I’m not sure if this is an issue with cron or if it’s
the cumulative startup time for N ruby interpreters. An ideas on how to
speed this up to a near constant (~<1sec) delay? Is there a way to run
all N scripts simultaneously with a single interpreter process? Thanks.

I’m using 1.8.5 on fc6.

Why not fork the N instances from one ruby script called by cron?

On 01.06.2007 21:57, Joel VanderWerf wrote:

Why not fork the N instances from one ruby script called by cron?

Or use threads to implement parallel execution. OP, what do your
scripts do?

Kind regards

robert

On Sat, Jun 02, 2007 at 06:00:43PM +0900, Robert K. wrote:

Earle C. wrote:

I have a setup where cron is calling N instances of a particular Ruby
script simultaneously. It seems that as N increases, the delay before
each script executes its first line of code increases by a little less
than N seconds. I’m not sure if this is an issue with cron or if it’s
the cumulative startup time for N ruby interpreters. An ideas on how to
speed this up to a near constant (~<1sec) delay? Is there a way to run
all N scripts simultaneously with a single interpreter process? Thanks.

Well, you can’t make a CPU run faster than itself. So let’s say for the
sake
of argument Ruby has a one-second startup time, and this is a CPU
limitation. Then if you run five Ruby scripts in five separate
interpreters,
it’s going to take 5 CPU-seconds of CPU time to start them all. If they
all
share the CPU time equally, then it’ll be shared 5 ways, so it will take
each of them 5 seconds of real time to execute their 1 CPU-second of
work.

If the startup overhead is a problem to you, you could just try running
all
the scripts one after the other within the same Ruby interpreter:

#!/usr/bin/ruby

allscripts.rb

require ‘script1.rb’
require ‘script2.rb’
require ‘script3.rb’
require ‘script4.rb’
require ‘script5.rb’

This may work as long as they are written in such a way that this
doesn’t
matter (e.g. they don’t pollute the interpreter so badly that the
following
one doesn’t run, or depend on atexit {} or the like to function)

Alternatively, you write a single ruby process which starts and then:
(1) forks off a new child for each script, or
(2) starts each script in a new thread.

Brian.