elastic / go-freelru

Apache License 2.0
167 stars 12 forks source link

Add a benchmark comparison with ristretto #2

Closed joshdover closed 11 months ago

joshdover commented 1 year ago

We use this library for caching a few different things in Fleet Server: https://github.com/dgraph-io/ristretto

It would be great to add this library to the list of benchmarks run here to help us understand if this would help Fleet Server performance.

rockdaboot commented 1 year ago

Please be aware that the main goal of FreeLRU is not the performance of Add/Get. It is the reduction of CPU wasted in GC. The Go GC has to walk every heap-allocated object... which potentially is responsible for a large share of your CPU usage. This comes to play when there are many cached items in a long-running process that itself doesn't eat much CPU.

The Go benchmarks do not reflect the work of the GC in a long running process. As long as the Add/Get functions do not appear in the top CPU-using functions, their latency (shown in the benchmarks) are likely completely irrelevant to you.

Profiling a well-used fleet server after several hours or days of operation (when caches are reasonably filled) should give you an impression of how much CPU time is spent in the GC.

Feel free to ping me to talk about more details.