[R] R gets slow

pau carre pau.carre at gmail.com
Sun Mar 26 11:38:53 CEST 2006


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