News for hackers. Stuff that matters.
Re:The State of Caching in Go by northwindfoo on Sunday March 10, 2019 @11:49PM (#19356513)
I'm not very familiar with go but one thing I don't understand is why the caches need to be distributed. I wonder, why not just have one cache per thread?
Re:The State of Caching in Go by scottlamb on Monday March 11, 2019 @01:26PM (#19360821)
You're probably imagining an async, thread-per-core model. One cache per thread might be reasonable then (although having more, smaller caches decreases hit rate, so might fail their requirement #5).

Go programs are written in a synchronous, thread-per-request model. You'd end up with _tons_ of small, very cold caches and a miserable hit rate.

You could approximate the former in Go by just having an array of N caches and picking from them randomly. This is similar to their "lock striping" with less contention (no stripe is a hot spot) but a lower hit rate.

Re:The State of Caching in Go by jadbox on Monday March 11, 2019 @05:44PM (#19363142)
This was wonderfully simple and concise. Thank you.
Re:The State of Caching in Go by tpetry on Monday March 11, 2019 @04:32AM (#19357478)
Cache invalidation is pretty hard if you need to clear data from local caches for every thread.
Re:The State of Caching in Go by jitl on Monday March 11, 2019 @12:00AM (#19356562)
That requires N times more memory, where N is the number of threads. 32x more memory??
Re:The State of Caching in Go by Twirrim on Monday March 11, 2019 @01:40AM (#19356927)
Given the Zipf distribution, I wonder if just a small LRU cache per thread might not be a terrible thing?

Juggling caches on databases is a challenging thing, and there has been some back-and-forth on best practices. MySQL for the longest time shipped with a query cache. As of MySQL 5.7.20 it was deprecated, and has now been removed in MySQL 8, largely because it was as likely to hurt you badly as help you, particularly with correctly sized InnoDB buffering.

Re:The State of Caching in Go by NovaX on Monday March 11, 2019 @01:53AM (#19356974)
Zipf is a little idealistic. It is perfect for a quick analysis as the base case that a cache should excel at. Unfortunately LRU doesn't because it can be easily polluted. (examples: https://github.com/ben-manes/caffeine/wiki/Efficiency)

A database will often scan many records which would flush an LRU. Postgres uses small LRU buffer caches in your per-thread model, backed by a larger LRU-like cache. The buffer caches are easily flushed by scans, but protect the shared cache from this noise. That shared cache could probably benefit from a smarter policy and this is an on going topic.

Re:The State of Caching in Go by andonisus on Monday March 11, 2019 @10:16AM (#19359118)
This is assuming that all threads need a global view of the data. When this is not the case, it is sufficient to have many async goroutines ingest on a channel and fill their own local map, lock-free. This is our general strategy for high-performance streaming routines.
Re:The State of Caching in Go by northwindfoo on Monday March 11, 2019 @12:23AM (#19356653)
Right, fair enough. I only thought of that after I posted. Not used to thinking that memory is limited lol

The author did indicate that they had problems with oom and memory eviction so it probably is a memory limited use case.