Why is single threaded Redis so fast (2023)
pixelstech.net
pixelstech.net
In case of a database, the majority of the work done by the process is in accessing big, shared data structures, which can lead to a lot of congestion. One has to go out of their way to create structures that do not require writers to have exclusive access that penalizes read (e.g., a write log that is occasionally merged), but then you still have to sort out write congestion. When perfected to allow maximum performance, the structure still ends up more complicated and will not allow fully linear scaling.
With a single-threaded model you lose parallelism, but you gain the ability to use the simple structures with reckless abandon, and performance is linear over the average request processing time.
Other types of applications do not necessarily have these limitations. E.g., you can make a multi-threaded webserver that requires no synchronization as it works off static data with requests and connections being entirely thread-local. The application could also be compute-bound, with the time spend accessing contentious shared structures being just a minor part of the execution time.
antirez (Salvatore Sanfilippo) has been very clear about the reasons and benefits.
Article feels like the author was tasked with writing an article that was a certain number of words long and they phoned it in.
I would expect vertical scaling to have better performance for most use cases as you can get cheap servers with very large amounts of RAM and high number of CPU cores.
One of the strategies that is being used in the multi-threading is using CPU memory prefetching to pull memory closing to the CPU so that we aren't stalling on fetching data from main memory while executing commands. We still want to try to apply these techniques without multi-threading to improve the efficiency of single or double core installations.