Top
Best
New

Posted by j03b 21 hours ago

In praise of memcached(jchri.st)
251 points | 101 commentspage 2
jitl 10 hours ago|
memcached is about a bazillion times faster than redis at doing the simple KV cache job. it’s got threads. it’s highly optimized to do its one job super well, where redis is more a arbitrary shared Python heap kinda thing with all the data structures and single thread and whatnot.

at notion we use redis for a lot of things, but actual caching we leave to memcached

foobarian 8 hours ago||
Can confirm it's not that much faster at k/v. 300 vs 350 microseconds per read on average. The single thread thing doesn't matter much since it's not cpu bound, it's reactive I/O
citrin_ru 9 hours ago||
Threads are not free - they allow to use more CPU cores but if you load is not too high than with a single thread memcached uses less CPU than with multiple.
freediddy 8 hours ago||
Burning memory for a pure memory/RAM service like memcached in today's environment is not going to work given the price of memory and especially for larger customers. Especially in cloud environments, it's going to be inordinately expensive so having hybrid solutions like Redis and their flash memory solution is probably going to be the compromise going forward.
dijit 8 hours ago||
Sometimes you just need some networked RAM, man.
drchaim 12 hours ago||
WHEN do you move to Redis/Memcached? None of my projects have exceeded 1000 rps at peak, and in none of them have I felt the need to move from unlogged PostgreSQL tables to Redis.

Just trying to get a sense of where people draw the line.

calpaterson 12 hours ago||
Mostly is no rule, adding a cache can just save you from having to buy a bigger database instance in many cases.

The most common first thing to cache is getting the current user, because this ends up being a very hot path for most stateless systems. Because you need to get the current user for almost every request, it's quite easy for getting the current user to be 50% of database load: first you get the user, then you do the thing. tada, user lookup is now half your app by volume

foobarian 8 hours ago|||
You could ask the opposite question too, could you move your bespoke Redis/mcd workload to a boring old database? We have some workloads from 100k-1M ops/s that I would love to streamline but the load is too high. So... 100k in this case? :-)
hylaride 8 hours ago||
As always it depends. Are there noticeable bottlenecks/latency in the app? No? Why pre-optimize then?

Look at this image: https://cs61.seas.harvard.edu/site/img/storage-hierarchy.png

At scale, the timing and order of magnitude increases in latency can add up. Caching the most requested data the higher you go can keep up performance (at added cost). On a busy website, that could be things like session tokens or other data that is part of every request. On a landing page, it could be images or other static data (I mean, you'd use a CDN for this, but you get the idea). Database calls can be expensive (computationally and IO wise), so if you can recalculate and cache certain operations, you can keep up.

Also, do you really need memcached/redis? If you have session affinity, you can also have nodes each keep their own caches in memory, with the caveat that if there's a failover, you'll have to re-fetch the data. Redis/memcached would be more of a shared cache, for things that you may not want to interrupt the user if they hit a different front-end endpoint.

It also doesn't have to be a cache. We've used redis for distributed task coordination as a shared state with the caveat that if something happened to redis, we'd just restart the task.

TL;DR If you need a SHARED cache when the performance of your app slows down enough that the cost of caching makes up for it.

jessinra98 7 hours ago||
I inherited a Django app once where Redis was doing everythinga nd a single bad pub/sub message locked up the whole thing. We pulled the cache layer into memcached.
inigyou 9 hours ago||
Redis got replaced by Valkey FYI. It still has the same problems except for being driven by AI marketing, and even if you are doing AI you will find it has useful features, like vector lookup.
dosint21h 14 hours ago||
Perhaps you should try aerospike which provides a data-in-memory mode and reliable persistence and of course, automatic scale-out. Your mum will stop worrying about you and your job once and for all.
kijin 20 hours ago||
Redis works great as a cache, but there are a few things you need to do in order to use it reliably as a cache.

1) Wrap your client library so that it's impossible to store anything without an expiry date. You don't want 6-months-old data suddenly coming up in your app!

2) Either turn off persistence, or use a separate database for the cache. In other words, don't mix volatile data with stuff you actually care about.

3) Set up a reasonable maxmemory value with an appropriate maxmemory-policy, so that Redis doesn't eat up all your RAM.

4) Resist the urge to use complex data structures. If you try to update a single field on an expired hash, you will end up with an incomplete object.

If you don't want all that hassle, then yes, Memcached probably works better out of the box.

dvt 20 hours ago|
> 1) Wrap your client library so that it's impossible to store anything without an expiry date. You don't want 6-months-old data suddenly coming up in your app!

No need for this client-side complexity, as you should be using `allkeys-lru`. FWIW, should likely be doing this anyway, as (generally speaking) all data stored in Redis is usually regarded as volatile because of what Redis actually is.

kijin 18 hours ago||
> as (generally speaking) all data stored in Redis is usually regarded as volatile because of what Redis actually is.

If you know this already, then you didn't need to read OP or any of this thread. :)

The problem is that Redis tries very hard to position itself as a persistent data store, with defaults that lean toward persistence (no default eviction policy). Beginners need to fight these defaults every step of the way if all they want is a cache.

dvt 18 hours ago||
> The problem is that Redis tries very hard to position itself as a persistent data store

What are you talking about? On their website, the top 3 use cases (under the Platform menu) are: caching, streaming, and session management. Literally all of these three are volatile.

FridgeSeal 16 hours ago||
I haven encountered a _shocking_ number of people who treat Redis as a persistent store. There mere mention that it has some kind of persistence machinery is enough to convince some that is therefore durable and stable and should be treated like a DB.
deepsun 16 hours ago||
To me the only difference that mattered is that Redis allows to do range queries, while Memcached only by key. Aka TreeMap vs HashMap. Or B-tree index vs Hash index.
noirscape 8 hours ago|
Great post. Redis is just kinda overkill whenever I've had to use it. Memcached by contrast is very simple, fast and works without needing to do much fiddling with it.

One big tip I should recommend is to increase the default memory size limit to something more realistic for modern hardware (and arguably this should just be increased on the upstream's side as well, instead of making everyone reconfigure shitty defaults). It's very easy to exceed the memcached default key value, since it's just 1mb; the maximum size of memcached as a whole is 64mb, which is similarly very low. Outside of that, it works very well and the lack of persistence is great at making it not do things it's not supposed to do (which is a big problem with Redis' feature creep, the projects mainpage promoting AI drivel alone should point towards that.)

More comments...