Running multiple simultaneous interpreters/scripts

E

Earle Clubb

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
 
J

Joel VanderWerf

Earle said:
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?
 
R

Robert Klemme

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
 
B

Brian Candler

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top