How large should I set the cache size?

We’ve set the cache size to 128GB and noticed that GC time has become unusually high. How should we choose a reasonable cache size? Generally speaking, for a machine with 256GB of memory, what cache size would be appropriate?

Hey @gooohgb,

Tuning Dgraph takes a bit of trial and error. Lots of factors go in to turning the right dials. Did you see this article? Monitoring Graph Databases for Optimal Performance – Hypermode It’s a good start.

If that doesn’t get you oriented properly, maybe post your config on this thread.


I’ve checked the source code of PostingListCache reintroduced in v24.1.x. It seems that, regardless of how large the object is, it’s always counted as one byte. This leads to inconsistent behavior across different groups. I’m not sure how large I should set the cache size. Should I just disable the feature until it’s fixed?

Thanks for bringing it up — and also, really appreciate the PRs you sent.

Right now, the idea is that you can configure the cache size based on how many items you want in the cache. So if you can make a decision based on that, you can set the value accordingly.

We’re working on improving this — the plan is to make the cache size adapt automatically based on the total available memory. That’ll be part of an upcoming update.

Some context about the issue (since you seem quite familiar with the code):
I had tried setting the size of the list here, but it actually performed worse. There could be a couple of reasons for that, though I haven’t deeply investigated them yet:

  • Issue 1: Ristretto tends to evict large keys quickly. A list of size 100 was considered a “big key”, and this significantly reduced its cache usefulness.
  • Issue 2: Calculating the size of a posting list incurs some overhead, which impacts how useful the cache ends up being. The good news is we can now fix this — we can precompute and store the size when the posting list is created.

If you’d like to hop on a call to discuss this further, just let me know.

Thanks for your reply!

After noticing this issue, I spent some time thinking about possible improvements — and I’ve realized it’s actually quite a challenging problem. Compared to Badger, Dgraph has dynamic posting list sizes, which makes estimation much harder.

I think your idea of adapting the cache size automatically based on total available memory is a promising direction. I’ll also keep thinking about this and see if I can come up with any further suggestions.

Appreciate your input — hope you have a great day!