From: Olaf Klischat Date: 2005-07-18T17:00:55+09:00 Subject: Re: Rails: Session and IO "treefrog" writes: > 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.