Skip to content
Prev 31577 / 398506 Next

RMySQL connection very slow compared with PHP

Prof Brian Ripley wrote:

            
OK. Clearly, I'm disadvantaged by my slow machine ! But there is another 
element I have to give you to help you understand my scepticism. R is 
called by PHP (which manages the web pages that  display amongst others 
statistical results). The first version of our system did not use R. 
Indeed PHP can access the database, and it did the work fine (and fast ! ).
Now I want to use R for a better analysis (in a in evolutive view), but 
I'm very disappointed to note how slow requests are treated. The problem 
cannot be at MySQL's level since it was so fast with PHP (about 100x 
faster I think). So I think there must be a problem with R/RMySQL. 
However, isn't there fast C code in RMySQL ?

Perhaps I do not use the best commands for the requests :

/# beginning of R program (once only)
library(DBI);
library(RMySQL);
con <- dbConnect("MySQL");

# typical request
dbGetQuery(con,"select avg(mark) from table1 where critere=1");
# this takes 2 sec. (instant with PHP & MySQL)
# table1 being a table without index, with 3 columns and only 500 rows/

By the way, how should I close ResultSets to clean the workspace (I 
tried dbSendQuery instead of dbGetQuery) ? Should I give an object name 
to dbSendQuery's result (res) and then delete it (how ? seems to be a 
problem with dbClearResult) ?

Thanks again,
Laurent