Closed kevinnowland closed 2 years ago
The source
configuration parameter is only used by the Rserve daemon before forking the server. However, RestRserve()
uses the current session and run.Rserve
, so using the source
directive would be pointless since you can simply run anything you want in the session, so simply add
source("startup.R")
in server.R
before you call backend$start
So that's what we basically had been doing. We loaded in a data file that was about 250 MB before starting the application. This data file was used in a read-only manner by one of the route functions. However, our memory was spiking at the rate of ~ 1 GB per every 4 concurrent requests. We were wondering if we needed to preload it in a different way and tried to go down this path of using source
/ Rserve.conf
. Is it expected that the 250 MB would be loaded into memory separately per request or is that a likely artifact of something we did inadvertently in our code?
Regardless of the particular shenanigans we were up to, should it be possible to pass in source
or use the Rserve.conf
file? It does not seem to be happening for us. I am probably not clear on how run.Rserve
differs from using the Rserve
function directly or something like that, as I'm not super familiar with the R ecosystem.
Thanks for taking the time to respond!
So that's what we basically had been doing. We loaded in a data file that was about 250 MB before starting the application. This data file was used in a read-only manner by one of the route functions. However, our memory was spiking at the rate of ~ 1 GB per every 4 concurrent requests. We were wondering if we needed to preload it in a different way and tried to go down this path of using source / Rserve.conf. Is it expected that the 250 MB would be loaded into memory separately per request or is that a likely artifact of something we did inadvertently in our code?
Likely you do something in the request handler which causing high memory usage / copying of large objects. As Simon suggested you can load data with readRDS()
at any place before backend$start()
.
Regardless of the particular shenanigans we were up to, should it be possible to pass in source or use the Rserve.conf file? It does not seem to be happening for us. I am probably not clear on how run.Rserve differs from using the Rserve function directly or something like that, as I'm not super familiar with the R ecosystem.
What is the use case? You can provide most of the Rserve config parameters when calling backend$start(...)
.
@kevinnowland Please note that standard Linux tools (like ps
) duplicate shared memory in reports, i.e., they report all memory the process uses whether it is shared with another process or not. The actually used memory is much less than the total you see. You can use smem
to see the difference.
And, no, you cannot use source
nor eval
in the configuration, because you are not starting a Rserve
process at all. Instead you use run.Rserve()
to run a server in the R process in which you defined your application.
Thank you everyone for the responses! Very helpful.
Hello! I have been trying to take advantage of pre-loading data via the
source
and / oreval
arguments inRserve
for an app that is usingRestRserve
. The ideas was to prevent memory spikes when receiving many concurrent requests by pre-loading objects before the forking happens.The following set of files give an example setup that is not working as I would have thought. This is using
RestRserve_1.1.1
.Dockerfile
which is built with the command
server.R
docker-compose.yaml
I have been starting the image using
docker-compose up
with the followingdocker-compose.yaml
file which loadsRserve.conf
to/etc/Rserve.conf
(tried also asRserv.conf
).The server starts up fine.
Rserve.conf
orRserv.conf
Then I am trying to configure
Rserve
using the following file which gets put into the image at runtime to/etc/Rserve.conf
(I have also tried/etc/Rserv.conf
without the e):Which should be referencing the following file
startup.R
However, I cannot see either the statement getting printed in the docker-compose logs and cannot use the variable
x
in the ping route, for example.Any help would be appreciated. Thank you!