我怎样才能优雅地关闭Rserve呢?

时间:2022-08-22 13:42:21

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

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

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

and that for the Rserve and RSclient packages:

对于Rserve和RSclient包:

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

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

http://cran.r-project.org/web/packages/Rserve/Rserve.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'.

我不知道在rservice中打开/关闭连接和“优雅地”关闭rservice的正确工作流程是什么。

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.

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

In an Ubuntu terminal:

在一个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)

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

在关闭连接后,我还尝试了选项(也尝试了参数‘c’,即使连接是关闭的):

RS.server.shutdown()
RSshutdown()

So, my questions are:

所以,我的问题是:

1- How can I close Rserve gracefully?

1-我怎样才能优雅地结束关系?

2- Can Rserve be used without RSclient?

2- Rserve可以不使用RSclient吗?

I also looked at

我也看了

How to Shutdown Rserve(), running in DEBUG

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

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

如何与R客户端连接到rservice

Thanks so much!

非常感谢!

2 个解决方案

#1


16  

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

加载rservice和RSclient包,然后连接到实例。

> 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.

通过使用args和/或配置脚本启动rservice,可以使用w/o RSclient。然后您可以通过其他程序(如表)或您自己的代码连接到它。RSclient提供了一种方法,可以将命令/数据从R的实例中传递给rservice。

Hope this helps :)

希望这有助于:)

#2


4  

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:

在Windows系统中,如果您想关闭一个RServe实例,您可以使用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

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

如果您正确地使用PID关闭了您的rservice实例,则将出现以下消息:

SUCCESS: The process with PID xxxx has been terminated.

成功:PID xxxx的进程已经终止。

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

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

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

系统('tasklist /FI ' IMAGENAME eq . Rserve.exe ')

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

一次。如果不再运行rservice实例,您将获得消息

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.

请注意,前面提到的“RSClient”方法比这个方法更整洁、更容易,但我还是为那些不知道如何阻止它的人提出了这个问题。

#1


16  

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

加载rservice和RSclient包,然后连接到实例。

> 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.

通过使用args和/或配置脚本启动rservice,可以使用w/o RSclient。然后您可以通过其他程序(如表)或您自己的代码连接到它。RSclient提供了一种方法,可以将命令/数据从R的实例中传递给rservice。

Hope this helps :)

希望这有助于:)

#2


4  

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:

在Windows系统中,如果您想关闭一个RServe实例,您可以使用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

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

如果您正确地使用PID关闭了您的rservice实例,则将出现以下消息:

SUCCESS: The process with PID xxxx has been terminated.

成功:PID xxxx的进程已经终止。

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

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

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

系统('tasklist /FI ' IMAGENAME eq . Rserve.exe ')

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

一次。如果不再运行rservice实例,您将获得消息

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.

请注意,前面提到的“RSClient”方法比这个方法更整洁、更容易,但我还是为那些不知道如何阻止它的人提出了这个问题。