Rails: Session and IO

T

treefrog

Hi,
I want to use Gnuplot as part of a Rails application to generate data
plots from a large database and filtering software via a web front-end.

The problem is that Gnuplot is fairly slow to start up, but I can't
keep it up via a session variable because IO won't serialize.

Any ideas

regards, treefrog
 
O

Olaf Klischat

treefrog said:
Hi,
I want to use Gnuplot as part of a Rails application to generate data
plots from a large database and filtering software via a web front-end.

The problem is that Gnuplot is fairly slow to start up, but I can't
keep it up via a session variable because IO won't serialize.

Any ideas

cgi.rb (which Rails is built on) provides different "session storage"
backends; see cgi/session.rb. PStore ((de)serializing to/from files)
is the default in Rails iirc; you'd need MemoryStore, which just puts
the objects in a global hash, which should work with anything,
including open files. I don't know how to set the storage type when
using Rails, but it shouldn't be too hard.

This method has the obvious disadvantage that it'll only work as long
as your web application runs in a single Ruby interpreter, i.e. it
won't scale very well to medium to large sites, where you want to use
things like FastCGI and/or more than one web server to balance the
load. If that is the case, the obvious alternative would be to write a
dedicated "mediator" application that runs and controls gnuplot as a
child process of itself, takes gnuplot commands from your Rails
application(s) over (short-lived) connections (most likely a named
pipe or a network socket). I'm not sure how much overhead there is in
establishing such a connection on every request, but it should be
faste than starting gnuplot each time.
 

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