Redis
來源:程序員人生 發(fā)布時(shí)間:2016-06-16 17:48:37 閱讀次數(shù):3899次
edis是1個(gè)key-value存儲系統(tǒng)。和Memcached類似,它支持存儲的value類型相對更多,包括string(字符串)、list(鏈表)、set(集合)、zset(sorted set --有序集合)和hash(哈希類型)。這些數(shù)據(jù)類型都支持push/pop、add/remove及取交集并集和差集及更豐富的操作,而且這些操作都是原子性的。在此基礎(chǔ)上,redis支持各種不同方式的排序。與memcached1樣,為了保證效力,數(shù)據(jù)都是緩存在內(nèi)存中。區(qū)分的是redis會周期性的把更新的數(shù)據(jù)寫入磁盤或把修改操作寫入追加的記錄文件,并且在此基礎(chǔ)上實(shí)現(xiàn)了master-slave(主從)同步。Redis 是1個(gè)高性能的key-value數(shù)據(jù)庫。 redis的出現(xiàn),很大程度補(bǔ)償了memcached這類key/value存儲的不足,在部 分場合可以對關(guān)系數(shù)據(jù)庫起到很好的補(bǔ)充作用。它提供了Java,C/C++,C#,PHP,JavaScript,Perl,Object-C,Python,Ruby,Erlang等客戶端,使用很方便。[1] Redis支持主從同步。數(shù)據(jù)可以從主服務(wù)器向任意數(shù)量的從服務(wù)器上同步,從服務(wù)器可以是關(guān)聯(lián)其他從服務(wù)器的主服務(wù)器。這使得Redis可履行單層樹復(fù)制。存盤可以成心無意的對數(shù)據(jù)進(jìn)行寫操作。由于完全實(shí)現(xiàn)了發(fā)布/定閱機(jī)制,使得從數(shù)據(jù)庫在任何地方同步樹時(shí),可定閱1個(gè)頻道并接收主服務(wù)器完全的消息發(fā)布記錄。同步對讀取操作的可擴(kuò)大性和數(shù)據(jù)冗余很有幫助。
Redis-benchmark是官方自帶的Redis性能測試工具,可以有效的測試Redis服務(wù)的性能。
指令說明:
- Usage: redis-benchmark [-h <host>] [-p <port>] [-c <clients>] [-n <requests]> [-k <boolean>]
-
- -h <hostname> Server hostname (default 127.0.0.1)
- -p <port> Server port (default 6379)
- -s <socket> Server socket (overrides host and port)
- -c <clients> Number of parallel connections (default 50)
- -n <requests> Total number of requests (default 10000)
- -d <size> Data size of SET/GET value in bytes (default 2)
- -k <boolean> 1=keep alive 0=reconnect (default 1)
- -r <keyspacelen> Use random keys for SET/GET/INCR, random values for SADD
- Using this option the benchmark will get/set keys
- in the form mykey_rand:000000012456 instead of constant
- keys, the <keyspacelen> argument determines the max
- number of values for the random number. For instance
- if set to 10 only rand:000000000000 - rand:000000000009
- range will be allowed.
- -P <numreq> Pipeline <numreq> requests. Default 1 (no pipeline).
- -q Quiet. Just show query/sec values 只顯示每秒鐘能處理多少要求數(shù)結(jié)果
- --csv Output in CSV format
- -l Loop. Run the tests forever 永久測試
- -t <tests> Only run the comma separated list of tests. The test
- names are the same as the ones produced as output.
- -I Idle mode. Just open N idle connections and wait.
實(shí)例:redis-benchmark -h 127.0.0.1 -p 6379 -q -d 100
SET/GET 100 bytes 檢測host為127.0.0.1 端口為6379的redis服務(wù)器性能
redis-benchmark -h 127.0.0.1 -p 6379 -c 5000 -n 100000
5000個(gè)并發(fā)連接,100000個(gè)要求,檢測host為127.0.0.1 端口為6379的redis服務(wù)器性能
benchmark工具測試信息:
測試命令:
redis-benchmark -n 100000 -c 60
向redis服務(wù)器發(fā)送100000個(gè)要求,每一個(gè)要求附帶60個(gè)并發(fā)客戶端
結(jié)果(部份):
====== SET ======
對集合寫入測試
100000 requests completed in 2.38 seconds
100000個(gè)要求在2.38秒內(nèi)完成
60 parallel clients
每次要求有60個(gè)并發(fā)客戶端
3 bytes payload
每次寫入3個(gè)字節(jié)的數(shù)據(jù)
keep alive: 1
保持1個(gè)連接,1臺服務(wù)器來處理這些要求
93.06% <= 15 milliseconds
99.96% <= 31 milliseconds
99.98% <= 46 milliseconds
99.99% <= 62 milliseconds
100.00% <= 62 milliseconds
所有要求在62毫秒內(nèi)完成
42105.26 requests per second
每秒處理42105.26次要求
- [root@localhost ~]# redis-benchmark -h 127.0.0.1 -p 6379 -c 5000 -n 100000 -d 100 -q
- PING_INLINE: 34506.55 requests per second
- PING_BULK: 34059.95 requests per second
- SET: 31959.09 requests per second
- GET: 31466.33 requests per second
- INCR: 33311.12 requests per second
- LPUSH: 29265.44 requests per second
- LPOP: 36968.58 requests per second
- SADD: 32030.75 requests per second
- SPOP: 33344.45 requests per second
- LPUSH (needed to benchmark LRANGE): 29735.36 requests per second
- LRANGE_100 (first 100 elements): 16116.04 requests per second
- LRANGE_300 (first 300 elements): 6659.56 requests per second
- LRANGE_500 (first 450 elements): 4108.29 requests per second
生活不易,碼農(nóng)辛苦
如果您覺得本網(wǎng)站對您的學(xué)習(xí)有所幫助,可以手機(jī)掃描二維碼進(jìn)行捐贈