tags:

views:

41

answers:

2

I've used PPerl for deamon like processes.

This program turns ordinary perl scripts into long running daemons, making subsequent executions extremely fast. It forks several processes for each script, allowing many proceses to call the script at once.

Does anyone know of something like this for ruby? Right now I am planing on using a wrapper around curl to call a REST WebService written in Sinatra running on JRuby. I'm hoping there is a simpler option.

A: 

You mean like daemons?

Simple example of in-process daemonization

  require 'rubygems'
  require 'daemons'

  Daemons.daemonize


  loop do
    `touch /tmp/me`
    sleep 1
  end

Also, instead of using curl, have you looked at rest-client?

BaroqueBobcat
It's not a library you load into your script (the equivalent of that in Perl would be something like Proc::Daemon). It's outside of the script and doesn't require any modification.
mpeters
(Foolishly reads pperl docs which he should have to begin with) So you want to cache your script in memory to minimize start-up times? Are you using MRI or jruby?
BaroqueBobcat
The script I am using has a startup time of 2.1 seconds. I'd like it to be under 0.1 if possible. I can use MRI or JRuby.
sal
Have you looked at using nailgun? http://kenai.com/projects/jruby/pages/JRubyWithNailgun
BaroqueBobcat
@BaroqueBobcat nailgun seems to solve the problem. not perfect and I needed to tweak the WS calls a bit but this seems to solve the startup lag time problem.
sal
@BaroqueBobcat, you should add that as a second answer
sal
+1  A: 

Have you looked at using nailgun? It sets up a background JVM process that your scripts execute in. That way you can use jruby w/o incurring the JVM startup time you would normally get with each script run.

BaroqueBobcat