How should I interpret the output of the ghc heap profiler?

后端 未结 3 815
无人及你
无人及你 2021-02-01 18:57

I have a server process implemented in haskell that acts as a simple in-memory db. Client processes can connect then add and retrieve data. The service uses more memory than I

相关标签:
3条回答
  • 2021-02-01 19:06

    Not everything is included in the profile by default, for example threads and stacks. Try with +RTS -xT.

    0 讨论(0)
  • 2021-02-01 19:25

    I have a theory. My theory is that your program is using a lot of something like ByteStrings. My theory is that because the main content of ByteStrings is mallocated, they are not displayed while profiling. Thus you could run out of heap without the largest content of your heap showing up on the profiling graph.

    To make matters even worse, when you grab substrings of ByteStrings, they by default retain the pointer to the originally allocated block of memory. So even if you are trying to only store a small fragement of some ByteString you could end up retaining the whole of the originally allocated ByteString and this won't show up on your heap profile.

    That is my theory anyways. I don't know enough facts about how GHC's heap profiler works nor about how ByteStrings are implemented to know for certain. Maybe someone else can chime in and confirm or dispute my theory.

    Edit2: tibbe notes that the buffer used by ByteStrings are pinned. So if you are allocating/freeing lots of small Bytestrings, you can fragment your heap meaning you run out of useable heap with half of it unallocated.

    Edit: JaffaCake tells me that sometimes the heap profiler will not display the memory allocated by ByteStrings.

    0 讨论(0)
  • 2021-02-01 19:26

    You should use, e.g., hp2ps to get a graphical view of what's going on. Looking at the raw hp file is difficult.

    0 讨论(0)
提交回复
热议问题