KX Community

Find answers, ask questions, and connect with our KX Community around the world.
KX Community Guidelines

Home Forums kdb+ Orphan memory in KDB process using Rserve

  • Orphan memory in KDB process using Rserve

    Posted by muneishadya on March 28, 2023 at 12:00 am

    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

    muneishadya replied 8 months, 2 weeks ago 2 Members · 8 Replies
  • 8 Replies
  • rocuinneagain

    Member
    March 28, 2023 at 12:00 am
    1. Is it the embedR project that your are using?
    2. Are you on the latest release of the code? https://github.com/KxSystems/embedR/releases
    3. Is it possible share a small generic piece of code to reproduce the issue?
  • muneishadya

    Member
    May 11, 2023 at 12:00 am

    Hi Rocuinneagain ,

    1. I believe it is embedR project indeed.

    2. yes we are using the latest code.

    3.

    Rset:`rserve 2:(`rsset;2);

    meminfo:{(5#system”w”), 1024*”J”$system “ps -eo size -h -q “,string .z.i};

    m1:meminfo[];

    RSet[“temp”;100000?100];

    m2:meminfo[];

  • rocuinneagain

    Member
    May 11, 2023 at 12:00 am

    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

  • rocuinneagain

    Member
    May 12, 2023 at 12:00 am

    You can delete R variables and run R garbage collection using Rcmd as above.

  • muneishadya

    Member
    May 12, 2023 at 12:00 am

    Currently we reassign the same variable with new data, will just calling gc resolve the bloating in that case?

  • muneishadya

    Member
    May 16, 2023 at 12:00 am

    Also, need to add that we are using a file called as rserve.so , I believe its not part of embedR project.

  • rocuinneagain

    Member
    May 16, 2023 at 12:00 am

    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.

  • muneishadya

    Member
    May 29, 2023 at 12:00 am

    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.

     

Log in to reply.