[R] R Production Performance

Paul Meagher paul at datavore.com
Wed Sep 24 04:24:02 CEST 2003

Hi Zitan,

Below is the test I ran awhile back on invoking R as a system call.  It
might be faster if you had a c-extension to R but before I went that route I
would want to know 1) roughly how fast Python and Perl are in returning
results with their c-bindings/embedded stuff/dcom stuff, 2) whether R can be
run as a daemon process so you don't incur start up costs, and 3) whether R
can act as a math server in the sense that it will fork children or threads
as multiple users establish sessions with it.  I agree it would be nice to
have a better interface to R than via a system call.

Paul Meagher


I just timed how long it took to pipe a file containing 2 lines below into R
(via a PHP script executed from my browser):

x = cbind(4,5,3,2,3,4)

// timer.php

function getmicrotime(){
  list($usec, $sec) = explode(" ",microtime());
  return ((float)$usec + (float)$sec);

$time_start = getmicrotime();

$Input  = "./input.R";
$Output = "./output.R";
$RPath = "/usr/local/bin/R";
system("$RPath --no-save < $Input > $Output");
$fp = fopen("$Output", "r");
while (!feof($fp)) {
  $line = fgets($fp,4096);
  echo $line ."<br>";

$time_end = getmicrotime();
$time = $time_end - $time_start;
echo "<p>Time To Execute: $time seconds</p>";

The time to execute this script was 3.1081320047379 seconds (if I execute
the script a few times this around what I get).

I then removed the line that calls R only.  There was something in the
output.R file so, in essense, the only difference between the original
script and modified script is the removal of the system call to R.

The time to execute was 0.0010089874267578 seconds

By subtractive logic, this means the call to R incurs an overhead of around
3 seconds on a average web server box using the php-apache module.


----- Original Message ----- 
From: "Zitan Broth" <zitan at mediasculpt.net>
To: <james.holtman at convergys.com>
Cc: <r-help at stat.math.ethz.ch>
Sent: Wednesday, September 24, 2003 2:46 PM
Subject: Re: [R] R Production Performance

> Hi James,
> Thanks for your response :-)
> ----- Original Message -----
> > It is like anything else that you want to run as part of web services:
> what
> > do you want it to do?  Yes, it is fast in doing computations, but what
> will
> > you have it do?  It is probably as fast as anything else that you will
> find
> > out there that is fairly general purpose.
> I just want to use R for mathematical computations, and will call it via
> from the commandline with infile. We'll need to obviously test this
> ourselves, but I just thought I'd raise the question :-))
> > Are you going to be creating a lot of graphics that have to be displayed
> > back on the screen?  How is the user going to input data (flat files,
> > Excel worksheets, Oracle database, ...)?  Will you be invoking a unique
> > process each time a user calls, or will you be using a 'daemon' that
> > communicate with DCOM and such?  How many people will be trying to
> > it once and what is the mix of transactions that they will use?
> Well for sure the rest of the app needs to scale as well and be fast,
> failsafe etc..., but I am just asking about R.
> I was imagining using a unique process call each time I access R, which is
> how the apache/php/*nix environment works best (although keeping processes
> in memory is achievable as well).  My experience to date on integration
> C packages deploying to *nix is that this works quite effectively although
> certain packages require process management that are not multiprocess (to
> ensure that R for example only executes one computation at a time), but
> is no problem. There are ways to call c packages directly with PHP (swig)
> and I am investigating this at present.
> > You can probably get a real good feel by enclosing the operations that
> > want to do in a "system.time" function to see how long it will take.
> > really depends on what you are trying to do.  I can definitely say that
> > is faster than trying to code the algorithm in PERL or another scripting
> > language.
> Makes sense because R is written in C, where PERL and PHP are also written
> in C, so R is a "layer deep" so to speak :-)
> Thanks again,
> Z.
> > Greetings All,
> >
> > Been playing with R and it is very easy to get going with the UI or
> > batch commands :-)
> >
> > What I am wondering is how scalable and fast R is for running as part of
> > web service.  I believe R is written in C which is a great start, but
> > are peoples general thoughts on this?
> >
> > Thanks greatly,
> > Z.
> >
> >              [[alternative HTML version deleted]]
> >
> > ______________________________________________
> > R-help at stat.math.ethz.ch mailing list
> > https://www.stat.math.ethz.ch/mailman/listinfo/r-help
> >
> >
> >
> >
> > --
> > "NOTICE:  The information contained in this electronic mail transmission
> is
> > intended by Convergys Corporation for the use of the named individual or
> > entity to which it is directed and may contain information that is
> > privileged or otherwise confidential.  If you have received this
> electronic
> > mail transmission in error, please delete it from your system without
> > copying or forwarding it, and notify the sender of the error by reply
> email
> > or by telephone (collect), so that the sender's address records can be
> > corrected."
> >
> >
> >
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help

More information about the R-help mailing list