redis之爲何redis是單線程?

  官方FAQ表示,由於Redis是基於內存的操做,CPU不是Redis的瓶頸,Redis的瓶頸最有多是機器內存的大小或者網絡帶寬。既然單線程容易實現,並且CPU不會成爲瓶頸,那就瓜熟蒂落地採用單線程的方案了redis

Redis is single threaded. How can I exploit multiple CPU / cores?

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.app

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.性能

 

        正是因爲在單線程模式的狀況下已經很快了,就沒有必要在使用多線程了!可是,咱們使用單線程的方式是沒法發揮多核CPU 性能,不過咱們能夠經過在單機開多個Redis 實例來完善!this

警告1:這裏咱們一直在強調的單線程,只是在處理咱們的網絡請求的時候只有一個線程來處理,一個正式的Redis Server運行的時候確定是不止一個線程的,這裏須要你們明確的注意一下!spa

警告2:在上圖中FAQ中的最後一段,表述了從Redis 4.0版本開始會支持多線程的方式,可是,只是在某一些操做上進行多線程的操做!因此該篇文章在之後的版本中是否仍是單線程的方式須要讀者考證!.net

轉自:http://www.javashuo.com/article/p-voxjuhgq-nq.html線程

相關文章
相關標籤/搜索