3 ms·
Presumably that means Redis is fundamentally single threaded?
by clon 5y ago
Presumably that means Redis is fundamentally single threaded?
- WJW 5y agoIt is, but not because you manipulate datastructures directly. You could "just" implement fine-grained locking around elements of the data structures and have a multi-threaded Redis-like system. Indeed, there are several forks of Redis that do this. Redis itself is single-threaded because it makes for a very straightforward implementation that is easy to expand with new data structures and easy to grok for users. For 99% of applications, read scaling through replicas and write scaling through keyspace sharding is still more than fast enough, because the biggest time sink is in the latency between servers and not in the execution of the commands themselves. Therefore, multithreading would not win you much throughput except when you have very hot keys containing hashmaps or something like that. In those cases, consider one of the multi-threaded variants.
- compsciphd 5y agoit's single threaded, but event driven. it doesn't block the whole server when it does blocking IO. for good or bad, that means you scale it horizontally by running an instance per core and shard appropriately to that.
- avinassh 5y agoWhat kind of IO operations Redis does? The replication or disk persistence? I thought that prolly runs in other threads not the one which is serving clients
- compsciphd 5y agoyes, I believe (haven't actually looked closely at it, just based on other stuff I've done with redis module interface) that they occur in the single process, just via event driven architecture so the process doesn't block on them.