Top
Best
New

Posted by j03b 23 hours ago

In praise of memcached(jchri.st)
252 points | 101 commentspage 3
noirscape 10 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.)

tempest_ 21 hours ago||
I stopped using memcached a decade a go in favour of Redis and now use valkey.

Never felt the need to go back to memcached except when a legacy dependency needed it.

jimbokun 21 hours ago|
OK.

What do you think of the argument made in the article?

tempest_ 20 hours ago||
I don't want my cache to silently fail.

Clustering redis is not that hard even if you do it manually and I have only had to do it once.

I never use redis persistence and have a max size set with LRU or whatever the application requires.

With memcached I remember having to mess around the LD_LIBRARY path to link whatever python module I was using at the time

crabmusket 19 hours ago||
> silently fail

Mature ops would be tracking cache hit ratios right?

It sounds like memcached would be really good in a use case where you really just need an optional stateless pure cache with absolutely zero rope to hang yourself on. A use case where "cache hit ratio" is the goal, not "fiddly in-memory data store".

tempest_ 19 hours ago|||
> Mature ops would be tracking cache hit ratios right?

Sure, and sentry integrates well with redis in python which is what I use primarily with redis.

I don't think memcached is bad, I just think its old and industry has moved to redis because it offers more while covering the previous use case.

Calling redis fiddly is a mischaracterization. For many use cases I have not had to think more than 30s to setup redis.

(also when I say redis I mean Valkey at this point, even if they are starting to diverge)

hparadiz 19 hours ago||
There's basically zero reason to use redis. Pretty much every rdbms like mariadb, postgres, etc is just as fast. So then why redis? It's basically needless complexity in your system.
robotresearcher 18 hours ago|||
Postgres etc are more complex than Redis, are they not?

Does your argument assume you already have a database, so you might as well use it for your cache mechanism?

hparadiz 17 hours ago||
Modern rdbms databases already have an in-memory cache. For 99% of projects there's no actual difference. The round trip will end up around 12-22 ms in all best possible cases.
nchmy 15 hours ago||
If you're getting 12-22ms latency for your cache reads, the network is your bottleneck. If stored locally, you would get many orders of magnitude faster than that.
hparadiz 15 hours ago||
The network IS your bottleneck. That's exactly what I'm saying.

  APCu       count=1000 min=0.000290 avg=0.000318 p50=0.000320 p95=0.000331 max=0.000992 ms
  Memcached  count=1000 min=0.032422 avg=0.039714 p50=0.037211 p95=0.053261 max=0.091343 ms
  MariaDB    count=1000 min=0.015680 avg=0.019541 p50=0.018485 p95=0.023855 max=0.103867 ms

Don't even start a socket if possible.

Now then do a traceroute. Even to my router it costs 0.547 ms but that's only 1 direction. And a cloud space is hosting many servers, many routers, many switches, with lots of moving pieces so you're realistically adding 1.1 ms per subnet hop and in pretty much every data center that's probably 3-5 hops inside the LAN.

nchmy 9 hours ago||
Gotcha. Yes, if you have your cache (let alone services) all across different machines, then this is all irrelevant.

The real question, which few ever ask, is whether your app actually needs more than one server. Servers are so insanely large (up to like 400 Cores) and powerful now that you can get meaningful scale on a single box.

If you can colocate the app and cache (and maybe also the db) on the same server, you can get many orders of magnitude better performance, regardless of which cache it is. Redis, memcached etc all can do 100k or more gets per second (dragonflydb etc claim 10x that due to multithreading).

Hell, with RAM being so expensive now and NVME so fast, sqlite is a VERY attractive option for cache. Plenty written about projects adopting it. Rails in particular is a champion of it.

imp0cat 18 hours ago|||
Security. More precisely, the ability to secure access to redis with a password.
hparadiz 18 hours ago||
Okay but I can do that with any rdbms and I can secure memcached too lol. So what? How is redis better than a fixed length table in MySQL?
foobarian 10 hours ago|||
> absolutely zero rope to hang yourself on

Yeah I thought so too. Google "memcache slab starvation" if you want the long story

dvt 21 hours ago||
Memcached is meant to be a lightweight memory cache, which makes sense, but contrary to the article's claim that "Redis is brought into a stack as a cache, and it is run with the assumption that people treat it that way"—I have very very rarely experienced this. Redis is brought into a stack because (most importantly!) it's fast and (almost as importantly!) because it's simple. I don't think this article is written by AI, but (and I'm trying to be charitable here), it's just like.. dumb.

> Dealing with memcached downtime is incredibly easy, because client libraries generally ignore connection exceptions. For instance, a simple get will just return the default value (or none) if the server is down.

This is a terrible idea in the context of things that might use Redis. If you use Redis with some kind of complex state (say, a document if you're working on a Notion clone, for instance), wtf even is a "default value"? In fact, I actually also want to know when the thing is down.

> Clustering memcached is wonderful, because memcached actually has no clustering built-in.

Yeah bro, this is yet another one of the reasons people use Redis: it handles consensus and clustering for you. What even is this article? It's a master class in straw-manning architectural decisions: most people use hammers as hammers, but screwdrivers make great hammers too, especially if you also need to screw stuff in! I mean.. technically true?

groundzeros2015 21 hours ago||
> it handles consensus and clustering for you

Considering how complex and error prone this is, I don’t want it in my stack.

dvt 19 hours ago||
> Considering how complex and error prone this is, I don’t want it in my stack.

Have you ever used Redis before? I've literally never had to manage clustering or had any issues with it, and I've been using Redis for like 15 years (including for games where state had to live in multiple regions and could change on a 30- or 60-tick basis).

foobarian 21 hours ago|||
The memcache slab pools are a leaky abstraction that you may end up having to manage operationally, and it's another way Redis is simpler.
gnz11 13 hours ago|||
Agreed. Memcache is great until you get into the business of having to configure slabs. Most people just reach for redis at that point.
functional_dev 8 hours ago||
I always used memcached without knowing how it stores things.. never knew about the slab thing.

It is more sophisticated than grab memory per item.

This helped be to understand it better - https://vectree.io/c/memcached-internals-slab-allocation-lru...

vshulcz 12 hours ago|||
[flagged]
jszymborski 21 hours ago||
> wtf even is a "default value"?

The article mentions the default value is a null, which would be the cue to run whatever computationally expensive op or query the db or hit the disk etc... that you would normally run if you had no cache to begin with.

> but screwdrivers make great hammers too

I don't know what your screwdrivers look like but that sounds like a rough time.

sethherr 20 hours ago||
Generally you can use the back of a screwdriver like a hammer.

It works pretty well when you need to hit something with a solid object a couple times.

bch 19 hours ago||
Sounds like a trip to the hospital.
leoprctmp 19 hours ago||
[dead]
Beigale 14 hours ago||
[flagged]
stefantalpalaru 14 hours ago||
[dead]
masa-kozu 21 hours ago||
[flagged]
CBLT 21 hours ago|
I'm not really sure memcached optimizes for operational simplicity. The only time I've run it at scale, it would have low cpu utilization then unexpectedly hit lock contention and fall over without warning.
groundzeros2015 21 hours ago||
Compared to what?
abofh 22 hours ago|
Oh God I'm tired of ai written thought pieces
hoppoli 21 hours ago||
I see this comment frequently in this site and it doesn't provide any value. If this isn't part of the hackernews rules, I hope it becomes one soon.
newfocogi 21 hours ago|||
I don’t think LLMs would write this:

“Anyways, Redis homepage aside, you deploy it, and off you go - your trusty cache. You hand the connection string to the people who asked for it, and off you go.”

abofh 21 hours ago|||
So many it's not X it's Y. It might have been polished, but it was claude
roncesvalles 18 hours ago|||
there are only 2 and they don't seem to be AI-written
bigstrat2003 18 hours ago|||
You do realize that actual humans use that formulation, right? I know Claude is fond of it, but it didn't just invent the practice ex nihilo.
newfocogi 21 hours ago|||
Or this:

“None of these things are impossible with Redis, it’s just that memcached’s architecture in general more leans towards these directions, which makes it much, much more straightforward from an operations point of view.”

chipotle_coyote 21 hours ago||
It's become de rigueur on HN to accuse any article one thinks is trite, obvious, or simply disagreeable of being AI-written. ("That comment has three items in a list! No human would ever put three items in a list! Checkmate, bot!")
throw310822 21 hours ago|||
Somebody call Deckard.
poly2it 21 hours ago||
I don't see how this is AI-written?