3 ms·
It is, but not because you manipulate datastructures directly. You could "just" implement fine-grained locking around elements of the data structures and have a
by WJW 5y ago
It 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.