Hacker News new | ask | show | jobs
by kiennt 4891 days ago
Redis used event loop model to handle requests. So basically, at any time, there is only 1 thread change data. This model make redis fast and still guarantee data is atomic. I wonder if thredis use thread how thredis solve that issue?
2 comments

A single-threaded event loop gives you low latency... when you're not under load and servicing multiple concurrent connections. As the amount of load on Redis (or for that matter, any single-threaded program) increases, the amount of time Redis spends servicing other requests increases, and so the average latency increases proportional to load.

If Redis could actually process requests in parallel instead of one-at-a-time, this would not be an issue and Redis could actually have a reliable latency profile under load.

About the only solution in this case is to turn Redis into a distributed system via sharding/slaves, and as soon as you do that, you lose Redis's guarantees around atomicity. Furthermore, Redis provides few tools that are really essential in a distributed system, like read repair/quorums or a failover system that isn't a joke (i.e. sentinel, although redis-failover could fit the bill)

Threads are used because SQLite calls block.