14

我在 Mac 和 Ubuntu 中都尝试了很多选项。我阅读了 Rserve 文档

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

对于 Rserve 和 RSclient 包:

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

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

我无法弄清楚在 Rserve 中打开/关闭连接以及“优雅地”关闭 Rserve 的正确工作流程是什么。

例如,在 Ubuntu 中,我使用 ./config --enable-R-shlib 从源代码安装 R(遵循 Rserve 文档),还在 /etc/Rserve.conf 中添加了“控制启用”行。

在 Ubuntu 终端中:

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)

但是,我可以关闭连接:

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

关闭连接后,我还尝试了选项(也尝试使用参数“c”,即使连接已关闭):

RS.server.shutdown()
RSshutdown()

所以,我的问题是:

1- 如何优雅地关闭 Rserve?

2- 可以在没有 RSclient 的情况下使用 Rserve 吗?

我也看了

如何关闭 Rserve(),在 DEBUG 中运行

但问题是指调试模式,也没有解决。(我没有足够的声誉来评论/询问关机是否在非调试模式下工作)。

还看了:

如何使用 R 客户端连接到 Rserve

非常感谢!

4

3 回答 3

17

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 :)

于 2014-10-14T20:18:06.977 回答
5

在 Windows 系统上,如果要关闭RServe实例,可以使用systemin 函数R将其关闭。例如在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

如果您已正确关闭了具有该 PID 的 RServe 实例,则会出现以下消息:

SUCCESS:PID为xxxx的进程已经终止。

您可以通过输入检查 RServe 实例是否已关闭

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

再次。如果不再有 RServe 实例在运行,您将收到消息

信息:没有运行符合指定条件的任务。

有关此主题的更多帮助和信息可以在这个相关问题中看到。

请注意,较早的答案中提到的“RSClient”方法比这个方法更简洁、更容易,但我还是为那些开始RServe不知道如何停止它的人提出了它。

于 2016-02-11T11:32:43.440 回答
2

如果您无法在 R 中将其关闭,请运行以下代码以在终端中将其杀死。这些代码适用于 Mac。

$ ps ax | grep Rserve  # get active Rserve sessions

您将看到如下所示的输出。29155 是活动 Rserve 会话的作业 ID。

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

38562  0:00.00 grep Rserve

然后运行

$ kill 29155 
于 2018-07-20T22:11:26.510 回答