1、單實例安裝git
標題 | 內容 |
---|---|
測試環境 | Centos 7 |
虛擬機 | vbox |
redis版本 | redis 5.0.5 |
1.編譯安裝redisredis
#使用wget從官網如今redis數據庫tar壓縮包 $ wget http://download.redis.io/releases/redis-5.0.5.tar.gz #使用tar解壓tar壓縮包 $ tar xzf redis-5.0.5.tar.gz #進入redis解壓後的目錄 $ cd redis-5.0.5 #使用make編譯安裝redis數據庫,直接make會報錯,詳細錯誤信息查看第5節錯誤分析內容 $ make MALLOC=libc
2.redis編譯測試shell
#直接make test報錯,須要安裝相關依賴包,運行測試時候須要tcl-Tool Command Language 包 $ yum install tcl #執行make test 測試 $ make test
測試結果以下:
數據庫
3.運行redis數據庫服務器
運行完成編譯後,在源碼文件夾中的src文件夾中會生成redis相關的二進制文件。運行編譯好的二進制文件啓動redis數據庫:
The binaries that are now compiled are available in the src directory. Run Redis with:併發
#運行redis-server 二進制執行文件,啓動redis服務端程序。 $ src/redis-server
redis server啓動以下圖:
dom
可使用redis-cli命令鏈接數據庫與數據庫服務端進行交互。
You can interact with Redis using the built-in client:socket
#運行redis-cli啓動數據庫客戶端,鏈接默認redis數據庫 $ src/redis-cli #測試redis數據庫,插入一個foo bar 鍵值對 redis> set foo bar #插入成功 OK #獲取foo key的值 redis> get foo "bar"
4.redis性能測試ide
redis 數據庫自帶性能測試工具,工具名稱:redis-benchmark,使用此工具對數據庫進行性能測試。函數
Invalid option "-help" or option argument missing 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) -a <password> Password for Redis Auth -c <clients> Number of parallel connections (default 50) -n <requests> Total number of requests (default 100000) -d <size> Data size of SET/GET value in bytes (default 3) --dbnum <db> SELECT the specified db number (default 0) -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 expand the string __rand_int__ inside an argument with a 12 digits number in the specified range from 0 to keyspacelen-1. The substitution changes every time a command is executed. Default tests use this to hit random keys in the specified range. -P <numreq> Pipeline <numreq> requests. Default 1 (no pipeline). -e If server replies with errors, show them on stdout. (no more than 1 error per second is displayed) -q Quiet. Just show query/sec values --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. Examples: Run the benchmark with the default configuration against 127.0.0.1:6379: $ redis-benchmark Use 20 parallel clients, for a total of 100k requests, against 192.168.1.1: $ redis-benchmark -h 192.168.1.1 -p 6379 -n 100000 -c 20 Fill 127.0.0.1:6379 with about 1 million keys only using the SET test: $ redis-benchmark -t set -n 1000000 -r 100000000 Benchmark 127.0.0.1:6379 for a few commands producing CSV output: $ redis-benchmark -t ping,set,get -n 100000 --csv Benchmark a specific command line: $ redis-benchmark -r 10000 -n 10000 eval 'return redis.call("ping")' 0 Fill a list with 10000 random elements: $ redis-benchmark -r 10000 -n 10000 lpush mylist __rand_int__ On user specified command lines __rand_int__ is replaced with a random integer with a range of values selected by the -r option.
use redis-benchmark tools test redis performance .
#實例同時執行 1000 個請求來檢測性能 ./redis-benchmark -n 1000 -q
#測試存取大小爲100字節的數據包的性能 redis-benchmark -h 127.0.0.1 -p 6379 -q -d 100
#100個併發鏈接,100000個請求,檢測host爲localhost 端口爲6379的redis服務器性能 redis-benchmark -h 127.0.0.1 -p 6379 -c 100 -n 100000
5.錯誤記錄與分析
直接make報以下錯誤:
緣由是jemalloc重載了Linux下的ANSI C的malloc和free函數。解決辦法:make時添加參數。
make MALLOC=libc
運行後編譯成功。以下圖: