How can I shut down Rserve gracefully?

回眸只為那壹抹淺笑 提交于 2019-12-18 11:27:50

问题


I have tried many options both in Mac and in Ubuntu. I read the Rserve documentation

http://rforge.net/Rserve/doc.html

and that for the Rserve and RSclient packages:

http://cran.r-project.org/web/packages/RSclient/RSclient.pdf

http://cran.r-project.org/web/packages/Rserve/Rserve.pdf

I cannot figure out what is the correct workflow for opening/closing a connection within Rserve and for shutting down Rserve 'gracefully'.

For example, in Ubuntu, I installed R from source with the ./config --enable-R-shlib (following the Rserve documentation) and also added the 'control enable' line in /etc/Rserve.conf.

In an Ubuntu terminal:

library(Rserve)
library(RSclient)
Rserve()
c<-RS.connect()
c ## this is an Rserve QAP1 connection

## Trying to shutdown the server
RSshutdown(c) 
Error in writeBin(as.integer....): invalid connection

RS.server.shutdown(c)
Error in RS.server.shutdown(c): command failed with satus code 0x4e: no control line present   (control commands disabled or server shutdown)

I can, however, CLOSE the connection:

RS.close(c)
>NULL
c ## Closed Rserve connection

After closing the connection, I also tried the options (also tried with argument 'c', even though the connection is closed):

RS.server.shutdown()
RSshutdown()

So, my questions are:

1- How can I close Rserve gracefully?

2- Can Rserve be used without RSclient?

I also looked at

How to Shutdown Rserve(), running in DEBUG

but the question refers to the debug mode and is also unresolved. (I don't have enough reputation to comment/ask whether the shutdown works in the non-debug mode).

Also looked at:

how to connect to Rserve with an R client

Thanks so much!


回答1:


Load Rserve and RSclient packages, then connect to the instances.

> library(Rserve)
> library(RSclient)

> Rserve(port = 6311, debug = FALSE)
> Rserve(port = 6312, debug = TRUE)

Starting Rserve...
 "C:\..\Rserve.exe" --RS-port 6311
Starting Rserve...
 "C:\..\Rserve_d.exe" --RS-port 6312 

> rsc <- RSconnect(port = 6311)
> rscd <- RSconnect(port = 6312)

Looks like they're running...

> system('tasklist /FI "IMAGENAME eq Rserve.exe"')
> system('tasklist /FI "IMAGENAME eq Rserve_d.exe"')

Image Name                     PID Session Name        Session#    Mem Usage
========================= ======== ================ =========== ============
Rserve.exe                    8600 Console                    1     39,312 K
Rserve_d.exe                 12652 Console                    1     39,324 K

Let's shut 'em down.

> RSshutdown(rsc)
> RSshutdown(rscd)

And they're gone...

> system('tasklist /FI "IMAGENAME eq Rserve.exe"')
> system('tasklist /FI "IMAGENAME eq Rserve_d.exe"')

INFO: No tasks are running which match the specified criteria.

Rserve can be used w/o RSclient by starting it with args and/or a config script. Then you can connect to it from some other program (like Tableau) or with your own code. RSclient provides a way to pass commands/data to Rserve from an instance of R.

Hope this helps :)




回答2:


On a Windows system, if you want to close an RServe instance, you can use the system function in R to close it down. For example in R:

library(Rserve)
Rserve() # run without any arguments or ports specified
system('tasklist /FI "IMAGENAME eq Rserve.exe"') # run this to see RServe instances and their PIDs
system('TASKKILL /PID {yourPID} /F') # run this to kill off the RServe instance with your selected PID

If you have closed your RServe instance with that PID correctly, the following message will appear:

SUCCESS: The process with PID xxxx has been terminated.

You can check the RServe instance has been closed down by entering

system('tasklist /FI "IMAGENAME eq Rserve.exe"')

again. If there are no RServe instances running any more, you will get the message

INFO: No tasks are running which match the specified criteria.

More help and info on this topic can be seen in this related question.

Note that the 'RSClient' approach mentioned in an earlier answer is tidier and easier than this one, but I put it forward anyway for those who start RServe without knowing how to stop it.




回答3:


If you are not able to shut it down within R, run the codes below to kill it in terminal. These codes work on Mac.

$ ps ax | grep Rserve  # get active Rserve sessions

You will see outputs like below. 29155 is job id of the active Rserve session.

29155  /Users/userid/Library/R/3.5/library/Rserve/libs/Rserve

38562  0:00.00 grep Rserve

Then run

$ kill 29155 


来源:https://stackoverflow.com/questions/26225066/how-can-i-shut-down-rserve-gracefully

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!