albertosantini / node-rio

Integration with Rserve, a TCP/IP server for R framework
https://github.com/albertosantini/node-conpa
MIT License
176 stars 35 forks source link

Reusable connection #21

Closed alexproca closed 8 years ago

alexproca commented 9 years ago

Right now the connection to R server and implicitly the current session is short lived inside the scope of sendAction(..) method. I think it will be useful if we can create first a client client = net.createConnection(netOpts) then pass that client in the options to evaluateWithEntryPoint(cmd, {"client": client, ....}) in order to get back the same session (variables, functions, etc.) in a subsequent call.

albertosantini commented 9 years ago

I suppose we need to implement the support for CMD_detachSession, CMD_detachedVoidEval, CMD_attachSession.

See RSattach(session).

alexproca commented 9 years ago

I didn't know about RSattach. I needed this functionality for short periods of time because I had the business logic shared between javascript and R. Js called R code, analyzed the response and called again another R code or the conditions for end the routine are met. In this case not closing connection is faster because you do not save the session and retrieve it later.

I also like the approach with RSattach and it will be great if we can implement both.

albertosantini commented 9 years ago

@alexproca Please, feel free to go ahead with your original suggestion. It is a good thing not to be totally coupled with RServe APIs.

albertosantini commented 9 years ago

@alexproca any news or do you prefer I commit a draft?

christopherhex commented 9 years ago

Hi @albertosantini,

First of all: thx for creating this nice interface between Rserve and NodeJS!

I'm running this code in a Raspberry Pi environment. The overhead by constantly creating new (simultaneous) connections to the local Rserve instance causes the Pi to run out of memory quickly so in my case a persistent connection is needed.

Yesterday evening I gave it a try to start on implementing the ability to send multiple commands to Rserve while keeping the connection open. It's still quick & dirty (plan to refactor and improve in the following weeks), but I would appreciate it if you could take a quick look and comment on possible improvements. Here's the link to the forked repo: Forked Repo

Thanks!

albertosantini commented 9 years ago

@sparkycrisse Nice contribution!

It would be better to fork from dev-2.x branch. :)

And about the implementation would it be enough reusing client connection? https://github.com/albertosantini/node-rio/blob/dev-2.x/lib/main.js#L15

Something like:

var client = null;
function connect(netOpts, callback, isRecordMode) {
    var recordStream;

    if (!client) {
        client = net.createConnection(netOpts);
    }
...
albertosantini commented 8 years ago

dev-2.x is merged.

Contribution is welcome, because, tt the moment, is not my main use case.