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.
______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html