2023.03.27 07:29 PM
Hi Everyone,
our team is one of the users of Rserve for integrating KDB with R. Recently we noticed that one of our processes working with a R server was bloating in memory. Oddly, the .Q.w did not show any bloating in memory and .Q.gc didnt release any memory either. However the OS view of the memory consumed by the process was high and different from KDB view of its own memory.
We dug bit deeper and found that this was specifically happening in RSet function of the library.
While we are unable to view the implementation of Rserve at https://code.kx.com/q/interfaces/r/#remote-r-rserve I believe we are missing de-allocating memory in Rset function. Can someone help in fixing this issue or provide more insight.
regards,
Muneish
2023.03.28 01:40 AM
a month ago
Hi Rocuinneagain ,
1. I believe it is embedR project indeed.
2. yes we are using the latest code.
3.
meminfo:{(5#system"w"), 1024*"J"$system "ps -eo size -h -q ",string .z.i};
m1:meminfo[];
RSet["temp";100000?100];
m2:meminfo[];
4 weeks ago
The src is available at https://github.com/KxSystems/embedR/blob/fa5101b64e15f9ba0aa5c20affc0cd041fb41bc0/src/rserver.c#L458
Have you tried calling
Rcmd "rm(temp)"
Rcmd "gc()"
q does not manage the memory for R - you must still delete variables and call garbage collection
4 weeks ago
Currently we reassign the same variable with new data, will just calling gc resolve the bloating in that case?
4 weeks ago
You can delete R variables and run R garbage collection using Rcmd
as above.
3 weeks ago
The solution didnt work.
meminfo:{(5#system"w"), 1024*"J"$system "ps -eo size -h -q ",string .z.i};
localhost:5042>meminfo[]
3264247792 3690987520 3959422976 83886080000 0 5337485312
localhost:5042>Rset["mu";200#enlist 1000000?100]
75i
localhost:5042>meminfo[]
3264255600 3690987520 3959422976 83886080000 0 6937485312
localhost:5042>Rcmd"rm(mu)"
0i
localhost:5042>meminfo[]
3264261936 3690987520 3959422976 83886080000 0 6937485312
localhost:5042>Rcmd"gc()"
0i
localhost:5042>meminfo[]
3264266608 3690987520 3959422976 83886080000 0 6937485312
localhost:5042>Rcmd"gc()"
0i
localhost:5042>meminfo[]
3264268144 3690987520 3959422976 83886080000 0 6937485312
3 weeks ago
https://github.com/KxSystems/cookbook/tree/master/r/rserve
You are only looking at the memory usage of the q process.
With Rserve R is a separate process. You need to monitor it's memory usage also.
To free memory in q after creating a large object use .Q.gc[]
. You can also start q with -g 1
.
3 weeks ago
Also, need to add that we are using a file called as rserve.so , I believe its not part of embedR project.
a week ago
Hi there
the memory bloating problem is with the kdb process and not the R process.
whenever the q process calls Rset there is orphan memory on the q process.
Also, .Q.gc does not release any memory. The q process and OS have different view on the amount of memory being consumed by the q process .in the end the q process shuts down even though it thinks it has low memory foot print.
EMEA
Tel: +44 (0)28 3025 2242
AMERICAS
Tel: +1 (212) 447 6700
APAC
Tel: +61 (0)2 9236 5700
KX. All Rights Reserved.
KX and kdb+ are registered trademarks of KX Systems, Inc., a subsidiary of FD Technologies plc.