[R] R gets slow

pau carre pau.carre at gmail.com
Mon Mar 27 00:24:36 CEST 2006


Hello, I finally solved the problem. The solution was just remove the
attach operations. When attach is called a copy of the data is
generated and since I know it is not possible to delete it with rm as
it is not associated to any object.

Pau

2006/3/26, pau carre <pau.carre at gmail.com>:
> Hello, I am still having the same problem, even removing the objects
> (with rm()).
> I checked the memory allocated by R and it is constant (about 4.5%),
> so I have no idea of what is happening...
> Moreover in few minutes (15) the models are generated 5 times
> slower... restarting the server is the only (but not acceptable)
> solution I have.
> (I do not generate any graph and/or extra object)
> Pau
>
>
> 2006/3/25, pau carre <pau.carre at gmail.com>:
> > Hello, I have R as a socket server that computes R code sent by some
> > scripts (the clients). These scrips send R code to generate models
> > (SVM). The problem is that first models are generated in less than one
> > second and one hour later, the same models are generated in more than
> > ten seconds (even training with same data). If I restart the server ,
> > then it works well (fast). I don't know if I have to free the memory
> > or something.
> >
> > Here you have the code:
> > R server:
> > FSsocket <- function(){
> >     continue = TRUE;
> >     while(continue){
> >         conn <- try(socketConnection(server = TRUE, port = 7890, blocking =
> > TRUE, open = "ab"), silent = FALSE);
> >         isOpened = !inherits(conn, "try-error");
> >         isOpened = isOpened && isOpen(conn);
> >         while(!isOpened){
> >             Sys.sleep(1);
> >             conn <- try(socketConnection(server = TRUE, port = 7890, blocking
> > = TRUE, open = "ab"), silent = FALSE);
> >             isOpened = !inherits(conn, "try-error");
> >             isOpened = isOpened && isOpen(conn);
> >         }
> >         print("Waitting for source");
> >         srcFile = readLines(conn, n = 1)
> >         print(srcFile)
> >         continue = srcFile != "--close"
> >         if(continue){
> >             print("Executing source");
> >             error <- try(source(srcFile), silent = FALSE);
> >             if(inherits(error, "try-error")){
> >                 writeLines("ERROR", conn)
> >             }
> >             print("Sending confirmation")
> >             writeLines("DONE", conn)
> >             print("Closing connection")
> >         }
> >         close(conn)
> >     }
> > }
> > FSsocket();
> >
> > Model generator example:
> > library("class");
> > library("e1071");
> > dd = read.table("sampling/adapteddataSet");
> > attach(dd);
> > ddv = read.table("sampling/adaptedvalidationDataSet");
> > attach(ddv);
> > dd[,1] = factor(dd[,1]);
> > ddv[,1] = factor(ddv[,1]);
> > attach(dd);
> > tr_in = as.matrix(dd[,2:(1 + 1)]);
> > tr_out = dd[,1];
> > val_in = as.matrix(ddv[,2:(1 + 1)]);
> > val_out = ddv[,1];
> > t = tune(svm, kernel = "radial", train.x = tr_in, train.y = tr_out,
> > validation.x = val_in, validation.y = val_out,
> >           range = list( gamma = 2^(-1:1), cost = 2^(2:4) ), tunecontrol =
> > tune.control(sampling = "fix") )
> > z = t$best.model
> > save(z, file = "./models/1/20", compress=FALSE);
> >
> > Thanks
> > Pau.
> >
>




More information about the R-help mailing list