暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

《快学BigData》--Redis 总结(G)(32)

小徐的技术之路 2018-03-14
305

Redis 总结 - - - - - - - - - - - - -  - - - - - - - - - - - - - - - 138

概述    - - - - - - - - - - - - -  - - - - - - - - - - - - - - - 139

 Redis的特点 - - - - - - - - - - -  - - - - - - - - - - - - - - - 139

 Redis储存类型 - - - - - - - - - -  - - - - - - - - - - - - - - - 139

 Redis 的安装  - - - - - - - - - -  - - - - - - - - - - - - - - - 149

 Redis 常用命令- - - - - - - - - -  - - - - - - - - - - - - - - - 172

 Redis 内部工具- - - - - - - - - -  - - - - - - - - - - - - - - - 173

代码示例- - - - - - - - - - - - -  - - - - - - - - - - - - - - - 173

 RedisStudio客户端连接工具 - - - -  - - - - - - - - - - - - - - - 184

  Redis 持久化储存机制- - - - - - -  - - - - - - - - - - - - - - - 185

  Redis 事物的处理  - - - - - - - -  - - - - - - - - - - - - - - - 186

  Redis 发布订阅  - - - - - - - - -  - - - - - - - - - - - - - - - 188

  Redis 的性能测试  - - - - - - - -  - - - - - - - - - - - - - - - 189

  Redis-trib.rb详解 - - - - - - - -  - - - - - - - - - - - - - - - 191

Redis 发布订阅

Redis 的消息订阅/发布(pub/sub)是一种消息的模型,Redis客户端可以订阅任意数量级的频道,一旦某频道接收到消息时,订阅他的客户端就会收到信息,接下来演示一下实例:

1-1)、订阅窗口

[root@hadoop3 src]# ./redis-cli

127.0.0.1:6379> SUBSCRIBE message

Reading messages... (press Ctrl-C to quit)

1) "subscribe"

2) "message"

3) (integer) 1

1-2)、发布窗口

[root@hadoop3 src]# ./redis-cli

127.0.0.1:6379> PUBLISH message "new message"

(integer) 1

127.0.0.1:6379> PUBLISH message "new message1"

(integer) 1

 

1-3)、查看订阅窗口

127.0.0.1:6379> SUBSCRIBE message

Reading messages... (press Ctrl-C to quit)

1) "subscribe"

2) "message"

3) (integer) 1

1) "message"

2) "message"

3) "new message"

1) "message"

2) "message"

3) "new message1"


Redis 的性能测试

我们使用Redis自带的redis-benchmark进行测试

1-1)、查看帮助信息

[root@hadoop3 src]# ./redis-benchmark -h

Invalid option "-h" 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 2)

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

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

1-2)、实例

A)、测试并发

100个并发连接,100000个请求,检测hostlocalhost 端口为6379redis服务器性能

[root@hadoop3 src]# ./redis-benchmark -h localhost -p 6379 -c 100 -n 1000

====== PING_INLINE ======

  1000 requests completed in 0.04 seconds

  100 parallel clients

  3 bytes payload

  keep alive: 1

****************

 

 

详细的参数请参考Blog

http://blog.csdn.net/xfg0218/article/details/52825874

 

B)、测试数据包的问题

测试存取大小为100字节的数据包的性能

[root@hadoop3 src]# ./redis-benchmark -h localhost -p 6379 -q -d 100

PING_INLINE: 31172.07 requests per second

PING_BULK: 33886.82 requests per second

SET: 30998.14 requests per second

GET: 30693.68 requests per second

INCR: 33079.72 requests per second

LPUSH: 29403.12 requests per second

LPOP: 32530.91 requests per second

SADD: 31377.47 requests per second

SPOP: 33134.53 requests per second

LPUSH (needed to benchmark LRANGE): 32393.91 requests per second

LRANGE_100 (first 100 elements): 12055.46 requests per second

LRANGE_300 (first 300 elements): 4528.58 requests per second

LRANGE_500 (first 450 elements): 2971.68 requests per second

LRANGE_600 (first 600 elements): 2184.22 requests per second

MSET (10 keys): 19361.08 requests per second

 

 

C)、测试set,lpush的性能

[root@hadoop3 src]# ./redis-benchmark -t set,lpush -n 1000 -q

SET: 33333.34 requests per second

LPUSH: 33333.34 requests per second

 

-q  是只显示测试的结果

D)、只测试某些数值存取的性能

[root@hadoop3 src]# ./redis-benchmark -n 1000 -q script load "redis.call('set','username','xiaozhang')"

script load redis.call('set','username','xiaozhang'): 27777.78 requests per second

 

Redis-trib.rb详解

[root@hadoop1 src]# ./redis-trib.rb help

Usage: redis-trib <command> <options> <arguments ...>

 

  set-timeout     host:port milliseconds

  info            host:port

  check           host:port

  call            host:port command arg arg .. arg

  fix             host:port

                  --timeout <arg>

  help            (show this help)

  add-node        new_host:new_port existing_host:existing_port

                  --slave

                  --master-id <arg>

  rebalance       host:port

                  --timeout <arg>

                  --use-empty-masters

                  --threshold <arg>

                  --auto-weights

                  --pipeline <arg>

                  --weight <arg>

                  --simulate

  import          host:port

                  --from <arg>

                  --replace

                  --copy

  del-node        host:port node_id

  create          host1:port1 ... hostN:portN

                  --replicas <arg>

  reshard         host:port

                  --from <arg>

                  --timeout <arg>

                  --yes

                  --slots <arg>

                  --to <arg>

                  --pipeline <arg>

 

For check, fix, reshard, del-node, set-timeout you can specify the host and port of any working node in the cluster.

 

可以看到redis-trib.rb具有以下功能:

1create:创建集群

2check:检查集群

3info:查看集群信息

4fix:修复集群

5reshard:在线迁移slot

6rebalance:平衡集群节点slot数量

7add-node:将新节点加入集群

8del-node:从集群中删除节点

9set-timeout:设置集群节点间心跳连接的超时时间

10call:在集群全部节点上执行命令

11import:将外部redis数据导入集群

 

 

具体的每一个功能请查看:

http://blog.csdn.net/xfg0218/article/details/56505216

或者

http://blog.csdn.net/xfg0218/article/details/56678783



文章转载自小徐的技术之路,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论