[R] how to run R as a daemon
mail at joeconway.com
Mon May 19 17:33:59 CEST 2003
Laurent Faisnel wrote:
> Hi all,
> Using R a as a real-time application called by Php for a website, I
> would like to run one R process only, which would manage user
> connections. For the time each user who asks for an analysis causes a
> new R process to start, which is not suitable in prevision of many
> users. R needs about 30 seconds to run the script which makes the
> analysis. The problem is that this waiting time is n times more
> important when n users ask for an analysis...
> Thanks for any help.
I have been using R as the processing engine behind a PHP application
(Intranet) by embedding it in PostgreSQL. In my case the data being
analyzed all resides in the Postgres database, and I use PL/R functions
to process and return data to PHP. Then in PHP I use JPGraph to generate
the charts. Recently I also started to play with using a virtual frame
buffer and R's own charting capability to create the charts as temporary
files and then simply use PHP to display them.
Further, I preload and pre-initialize the embedded R engine on
postmaster (Postgres) startup, which reduces the initial call in any
given session from 2+ seconds to 10s of milliseconds on my hardware.
You can get a copy of PL/R here: http://www.joeconway.com
The preloading functionality is avaialable only in Postgres 7.4devel at
this point, but I have a backpatched version 7.3.2 RPM available at the
same place. If you use the RPM, it has PL/R in it already, but
unfortunately it is not the latest (I'll get around to fixing that soon,
probably after Postgres 7.3.3 is released, which should be this week).
Although I'm still calling it an "alpha" release (partly due to lack of
feedback from others -- anyone have any?), it has worked pretty reliably
for my purposes, and I've started using it in a limited way on a
production application within the last few weeks.
Hope this helps,
More information about the R-help