Redis和Memcache对比及选择
http://www.cnblogs.com/EE-NovRain/p/3268476.html
我這段時間在用redis,感覺挺方便的,但比較疑惑在選擇內存數據庫的時候到底什么時候選擇redis,什么時候選擇memcache,然后就查到下面對應的資料,是來自redis作者的說法(stackoverflow上面)。
? ??You should not care too much about performances. Redis is faster per core with small values, but memcached is able to use multiple cores with a single executable and TCP port without help from the client. Also memcached is faster with big values in the order of 100k. Redis recently improved a lot about big values (unstable branch) but still memcached is faster in this use case. The point here is: nor one or the other will likely going to be your bottleneck for the query-per-second they can deliver.
? ? You should care about memory usage. For simple key-value pairs memcached is more memory efficient. If you use Redis hashes, Redis is more memory efficient. Depends on the use case.
? ??You should care about persistence and replication, two features only available in Redis. Even if your goal is to build a cache it helps that after an upgrade or a reboot your data are still there.
? ??You should care about the kind of operations you need. In Redis there are a lot of complex operations, even just considering the caching use case, you often can do a lot more in a single operation, without requiring data to be processed client side (a lot of I/O is sometimes needed). This operations are often as fast as plain GET and SET. So if you don’t need just GEt/SET but more complex things Redis can help a lot (think at timeline caching).
? ? 有網友翻譯如下[1]:
? ??沒有必要過多的關注性能。由于Redis只使用單核,而Memcached可以使用多核,所以在比較上,平均每一個核上Redis在存儲小數據時比Memcached性能更高。而在100k以上的數據中,Memcached性能要高于Redis,雖然Redis最近也在存儲大數據的性能上進行優化,但是比起Memcached,還是稍有遜色。說了這么多,結論是,無論你使用哪一個,每秒處理請求的次數都不會成為瓶頸。
? ??你需要關注內存使用率。對于key-value這樣簡單的數據儲存,memcache的內存使用率更高。如果采用hash結構,redis的內存使用率會更高。當然,這些都依賴于具體的應用場景。
? ??你需要關注關注數據持久化和主從復制時,只有redis擁有這兩個特性。如果你的目標是構建一個緩存在升級或者重啟后之前的數據不會丟失的話,那也只能選擇redis。
? ??你應該關心你需要的操作。redis支持很多復雜的操作,甚至只考慮內存的使用情況,在一個單一操作里你常常可以做很多,而不需要將數據讀取到客戶端中(這樣會需要很多的IO操作)。這些復雜的操作基本上和純GET和POST操作一樣快,所以你不只是需要GET/SET而是更多的操作時,redis會起很大的作用。
? ??對于兩者的選擇還是要看具體的應用場景,如果需要緩存的數據只是key-value這樣簡單的結構時,我在項目里還是采用memcache,它也足夠的穩定可靠。如果涉及到存儲,排序等一系列復雜的操作時,毫無疑問選擇redis。
? ?
? ? 關于redis和memcache的不同,下面羅列了一些相關說法,供記錄:
? ??redis和memecache的不同在于[2]:
? ? 1、存儲方式:
? ? memecache 把數據全部存在內存之中,斷電后會掛掉,數據不能超過內存大小
? ? redis有部份存在硬盤上,這樣能保證數據的持久性,支持數據的持久化(筆者注:有快照和AOF日志兩種持久化方式,在實際應用的時候,要特別注意配置文件快照參數,要不就很有可能服務器頻繁滿載做dump)。
? ? 2、數據支持類型:
? ? redis在數據支持上要比memecache多的多。
? ? 3、使用底層模型不同:
? ? 新版本的redis直接自己構建了VM 機制 ,因為一般的系統調用系統函數的話,會浪費一定的時間去移動和請求。
? ? 4、運行環境不同:
? ? redis目前官方只支持LINUX 上去行,從而省去了對于其它系統的支持,這樣的話可以更好的把精力用于本系統 環境上的優化,雖然后來微軟有一個小組為其寫了補丁。但是沒有放到主干上
?
個人總結一下,有持久化需求或者對數據結構和處理有高級要求的應用,選擇redis,其他簡單的key/value存儲,選擇memcache。
總結
以上是生活随笔為你收集整理的Redis和Memcache对比及选择的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 线程池java.util.concurr
- 下一篇: java反斜杠\的用法