redis - redis如何处理并发1000个请求?

标签 redis

有这样一个场景,1000个请求要求redis获取name为goods_stock的key,同时在redis中设置key的vaule等于goods_stocks-1,redis服务器如何处理这些请求?它是否处理默认队列,就像每个请求都是 block 请求一样?

最佳答案

您的应用程序可以是多线程的,但在服务器端 Redis 本身是单线程的。 Redis 中的所有操作都是原子的。所以它在 Redis 端的工作方式类似于顺序。 此处引用要点:

The fact that Redis operations are atomic is simply a consequence of the single-threaded event loop. The interesting point is atomicity is provided at no extra cost (it does not require synchronization). It can be exploited by the user to implement optimistic locking and other patterns without paying for the synchronization overhead.


Redis 是单线程的。我如何利用多个 CPU/内核?

It's not very frequent that CPU becomes your bottleneck with Redis, as usually Redis is either memory or network bound. For instance, using pipelining Redis running on an average Linux system can deliver even 1 million requests per second, so if your application mainly uses O(N) or O(log(N)) commands, it is hardly going to use too much CPU. However, to maximize CPU usage you can start multiple instances of Redis in the same box and treat them as different servers. At some point a single box may not be enough anyway, so if you want to use multiple CPUs you can start thinking of some way to shard earlier. You can find more information about using multiple Redis instances in the Partitioning page. However with Redis 4.0 we started to make Redis more threaded. For now this is limited to deleting objects in the background, and to blocking commands implemented via Redis modules. For the next releases, the plan is to make Redis more and more threaded.

Hava 查看以下帖子以获取更多详细信息:

关于redis - redis如何处理并发1000个请求?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49304856/

相关文章:

linux - redis中repl-buffer和backlog的区别?

node.js - EXPIRE Redis key (如果未修改)

Redis-Sentinel 在每个节点上都使用 slaveof

.net - Redis 用于频繁更改的市场信息

c# - ConnectionStrings 或 AppSettings 的存储库

python - 键值数据库选项

node.js - ioredis-如果redis关闭,则忽略请求

node.js - 多 channel 取决于路径与nodejs和redis

python - 向 Redis 组 SADD 添加许多值

python - 从给定的 Redis 集群,我如何运行 Redis CLI 或 API 调用来获取整个集群上的每个键的列表,而不仅仅是一台机器?