cassandra-stress 压测使用介绍

 

Cassandra从很早的版本就自带了cassandra-stress压力测试工具,它的使用方法在cassandra-stress后添加命令和选项。其中常用的命令一般只用到:write、read、mixed、user。其中单纯的write和read只测试读和写,mixed则测试同时读写。user是2.1之后新增的,通过自定义配置文件,在配置文件中可以指定insert和query查询语句。
命令command没有以-开头,而选项[options]有两种方式:-选项名称 选项值或者选项名称=选项值。

常用的选项有

 
  1. counter_read: 多个并发读,必须首先通过counter_write测试填充群集。

  2. counter_write:多个并发写。

  3. legacy:传统模式的支持。

  4. mixed:混合模式和可配置的读写比例和分布。集群必须先写测试数据填充。

  5. read: 多个并发读取。必须首先通过写入测试填充群集。

  6. write: 针对群集的多个并发写入。

  7. user: 交错用户提供具有可配置比率和分布的查询。

  8. version: 打印cassandra-stress版本。

  9. print: 打印定义输出

子选项

-COL

列详细信息,例如大小和计数分布,数据生成器

 
  1. 用法:

  2. -col names =?[slice] [super =?] [comparator =?] [timestamp =?] [size = DIST(?)]

  3. 要么

  4. -col [n = DIST(?)] [slice] [super =?] [comparator =?] [timestamp =?] [size = DIST(?)]

-rate

速率

 
  1. 使用以下选项设置费率:

  2. -rate threads=N [throttle=N] [fixed=N]

  3. 配置项:

  4. threads=N 并发运行的客户端数量。

  5. throttle=N 所有客户端的每秒操作达到最大速率,默认值为0。

  6. fixed=N 期望所有客户每秒的固定运行率。默认值为0。

  7.  
  8. 或者

  9. -rate [threads>=N] [threads<=N] [auto]

  10. 参数:

  11. threads > = N :同时运行至少这么多客户端。默认值为4。

  12. threads <= N :最多同时运行这么多客户端。默认值为1000。

  13. auto 一旦吞吐量饱和,就停止增加线程。

-errors

如何处理压力测试期间遇到的错误

 
  1. 用法:

  2. -errors [retries = N] [ignore] [skip-read-validation]

  3. retries=N 失败前尝试次数。

  4. ignore 忽略错误。

  5. skip-read-validation 跳过读取验证和消息输出。

-graph

压力测试生成结果图表,可以将多个测试一起绘制成图表。

 
  1. 用法:

  2. -graph file=? [revision=?] [title=?] [op=?]

-log

日志设置

 
  1. 用法:

  2. level=verbose

  3. or

  4. -log [level=?] [no-summary] [file=?] [hdrfile=?] [interval=?] [no-settings] [no-progress] [show-queries] [query-log-file=?]

-mode

Thrift or CQL 选项

 
  1. 用法:

  2. -mode thrift [smart] [user=?] [password=?]

  3. or

  4. -mode native [unprepared] cql3 [compression=?] [port=?] [user=?] [password=?] [auth-provider=?] [maxPending=?] [connectionsPerHost=?] [protocolVersion=?]

  5. or

  6. -mode simplenative [prepared] cql3 [port=?]

-node

要连接的节点

 
  1. 用法:

  2. -node [datacenter=?] [whitelist] [file=?] []

-port

指定用于连接Cassandra节点的端口。9042端口用于native协议的客户端连接。

-port [native=?] [thrift=?] [jmx=?]

:-schema

表结构设置

 
  1. 用法:

  2. -schema [replication(?)] [keyspace=?] [compaction(?)] [compression=?]

-sendto

指定要将压力命令发送到的服务器。

 
  1. 用法:

  2. -sendto <host>

-tokenrange
令牌范围设置。

 
  1. 用法:

  2. -tokenrange [no-wrap] [split-factor =?] [savedata =?]

额外选项

 
  1. profile=?:指定YAML配置文件,需要自己编写DML,插入,查询;(只能作为user选项的子选项)

  2. ops(?): 指定操作类型和数量,比如ops(inserts=1),或者ops(queries=2),其中queries需要用指定的查询名称代替;(只能作为user选项的子选项)

  3. n=?: 指定操作数量,比如要写入1万条数据,n=10000; 要读取1000条数据,n=1000;

  4. err<?: 指定均值的标准误差; 达到此值时, cassandra-stress将结束。默认值为0.02;

  5. truncate=?: 是否需要清空表,可选项有:never(默认值),one,always;

  6. cl=?: 一致性级别,可选项有:ONE,QUORUM,LOCAL_QUORUM,EACH_QUORUM,ALL,ANY,LOCAL_ONE(默认值);(只能作为user选项的子选项)

  7. no-warmup:不要预热过程,冷启动任务。

--注意
选项名称,选项值必须放在 子选项选项值前面,比如正确的用法:truncate=one -node xxx

简单读写压测示例

 
  1. #插入(写入)一百万行

  2. cassandra-stress write n = 1000000 -rate threads = 50 -node 172.20.101.166 -port native=9042

  3.  
  4. #读二十万行。

  5. cassandra-stress读n = 200000 -rate threads = 50 -node 172.20.101.157 -port native=9042

  6.  
  7. #读取行持续3分钟。

  8.  
  9. cassandra-stress read duration = 3m -rate threads = 50 -node 172.20.101.164 -port native=9042

  10.  
  11. #混合读写持续5分钟。

  12. cassandra-stress mixed duration = 5m -rate threads = 50 -node 172.20.101.164 -port native=9042

  13.  
  14. #首先读取200,000行而不预热50,000行。

  15. cassandra-stress read n = 200000 no-warmup -rate threads = 50 -node 172.20.101.160, 172.20.101.166 -port native=9042

  16.  
  17. #通过身份验证运行cassandra-stress

  18. 以下示例显示使用-mode选项提供用户名和密码:

  19. cassandra-stress -mode native cql3 user = cassandra password = cassandra no-warmup cl = QUORUM

复杂压测示例:

100万条数据写入,一致性级别为Local_Quorum,客户端线程数=500个,2个列,副本数据=3个

 
  1. cassandra-stress write n=1000000 cl=LOCAL_QUORUM -rate threads=500 \

  2. -col "size=fixed(2048)" "n=fixed(32)" -schema "replication(factor=3)" -node 172.20.101.157 -port native=9042

使用user profile 配置yaml

 
  1. #

  2. # This is an example YAML profile for cassandra-stress

  3. #

  4. # insert data

  5. # cassandra-stress user profile=/home/jake/stress1.yaml ops(insert=1)

  6. #

  7. # read, using query simple1:

  8. # cassandra-stress profile=/home/jake/stress1.yaml ops(simple1=1)

  9. #

  10. # mixed workload (90/10)

  11. # cassandra-stress user profile=/home/jake/stress1.yaml ops(insert=1,simple1=9)

  12.  
  13. #

  14. # Keyspace info

  15. #

  16. keyspace: load_test

  17.  
  18. #

  19. # The CQL for creating a keyspace (optional if it already exists)

  20. #

  21. keyspace_definition: |

  22. CREATE KEYSPACE load_test WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 1};

  23. #

  24. # Table info

  25. #

  26. table: event2

  27.  
  28. #

  29. # The CQL for creating a table you wish to stress (optional if it already exists)

  30. #

  31. table_definition: |

  32. CREATE TABLE event2 (

  33. cookie_id int,

  34. timestamp timestamp,

  35. event_name text,

  36. session_id uuid,

  37. page text,

  38. device text,

  39. PRIMARY KEY(cookie_id, timestamp, event_name, session_id)

  40. ) WITH CLUSTERING ORDER BY (timestamp DESC)

  41.  
  42. #

  43. # Optional meta information on the generated columns in the above table

  44. # The min and max only apply to text and blob types

  45. # The distribution field represents the total unique population

  46. # distribution of that column across rows. Supported types are

  47. #

  48. # EXP(min..max) An exponential distribution over the range [min..max]

  49. # EXTREME(min..max,shape) An extreme value (Weibull) distribution over the range [min..max]

  50. # GAUSSIAN(min..max,stdvrng) A gaussian/normal distribution, where mean=(min+max)/2, and stdev is (mean-min)/stdvrng

  51. # GAUSSIAN(min..max,mean,stdev) A gaussian/normal distribution, with explicitly defined mean and stdev

  52. # UNIFORM(min..max) A uniform distribution over the range [min, max]

  53. # FIXED(val) A fixed distribution, always returning the same value

  54. # Aliases: extr, gauss, normal, norm, weibull

  55. #

  56. # If preceded by ~, the distribution is inverted

  57. #

  58. # Defaults for all columns are size: uniform(4..8), population: uniform(1..100B), cluster: fixed(1)

  59. #

  60. columnspec:

  61. - name: cookie_id

  62. population: uniform(1..100M) # the range of unique values to select for the field (default is 100Billion)

  63. - name: timestamp

  64. size: fixed(13)

  65. population: uniform(1..100M)

  66. - name: event_name

  67. size: uniform(5..10)

  68. population: uniform(1..100M)

  69. - name: session_id

  70. size: fixed(32)

  71. population: uniform(1..100M)

  72. - name: page

  73. size: gaussian(16..64)

  74. population: uniform(1..100M)

  75. - name: device

  76. size: fixed(4)

  77. population: uniform(1..10)

  78.  
  79. insert:

  80. partitions: uniform(1..50) # number of unique partitions to update in a single operation

  81. # if batchcount > 1, multiple batches will be used but all partitions will

  82. # occur in all batches (unless they finish early); only the row counts will vary

  83. batchtype: UNLOGGED # type of batch to use

  84. select: fixed(10)/10 # uniform chance any single generated CQL row will be visited in a partition;

  85. # generated for each partition independently, each time we visit it

  86.  
  87. #

  88. # A list of queries you wish to run against the schema

  89. #

  90. queries:

  91. simple1:

  92. cql: select * from event2 where cookie_id = ?

  93. fields: samerow # samerow or multirow (select arguments from the same row, or randomly from all rows in the partition)

  94. Collapse

user profile 测试案例-1

不要预热过程,冷启动任务,插入1000000万条数据,读写比例3比1 ,一致性级别设置为:QUORUM
cassandra-stress user profile=./pttest-cassandra.yaml n=1000000 ops(insert=3,simple1=1) no-warmup cl=QUORUM -node 172.20.101.157 -port native=9042

结果

 
  1. Results:

  2. Op rate : 1,562 op/s [insert: 1,164 op/s, simple1: 398 op/s]

  3. Partition rate : 30,063 pk/s [insert: 29,667 pk/s, simple1: 396 pk/s]

  4. Row rate : 30,063 row/s [insert: 29,667 row/s, simple1: 396 row/s]

  5. Latency mean : 28.2 ms [insert: 37.0 ms, simple1: 2.7 ms]

  6. Latency median : 4.3 ms [insert: 6.5 ms, simple1: 1.1 ms]

  7. Latency 95th percentile : 126.2 ms [insert: 142.5 ms, simple1: 7.7 ms]

  8. Latency 99th percentile : 230.4 ms [insert: 254.1 ms, simple1: 23.8 ms]

  9. Latency 99.9th percentile : 476.8 ms [insert: 554.2 ms, simple1: 96.6 ms]

  10. Latency max : 2581.6 ms [insert: 2,581.6 ms, simple1: 2,264.9 ms]

  11. Total partitions : 999,932 [insert: 986,756, simple1: 13,176]

  12. Total errors : 0 [insert: 0, simple1: 0]

  13. Total GC count : 43

  14. Total GC memory : 12.565 GiB

  15. Total GC time : 3.0 seconds

  16. Avg GC time : 69.4 ms

  17. StdDev GC time : 13.4 ms

  18. Total operation time : 00:00:33

  19.  
  20. Improvement over 181 threadCount: -7%

user profile 测试案例-2

不要预热过程,冷启动任务,500并发,插入1000000万条数据,读写比例3比1 ,一致性级别设置为:QUORUM
cassandra-stress user profile=./pttest-cassandra.yaml n=1000000 ops(insert=3,simple1=1) no-warmup cl=QUORUM -rate threads=500 -node 172.20.101.157 -port native=9042

 
  1. Results:

  2. Op rate : 1,496 op/s [insert: 1,145 op/s, simple1: 396 op/s]

  3. Partition rate : 28,763 pk/s [insert: 29,221 pk/s, simple1: 394 pk/s]

  4. Row rate : 28,763 row/s [insert: 29,221 row/s, simple1: 394 row/s]

  5. Latency mean : 49.5 ms [insert: 64.0 ms, simple1: 7.5 ms]

  6. Latency median : 4.9 ms [insert: 7.0 ms, simple1: 1.3 ms]

  7. Latency 95th percentile : 251.3 ms [insert: 286.0 ms, simple1: 29.7 ms]

  8. Latency 99th percentile : 513.0 ms [insert: 561.0 ms, simple1: 118.3 ms]

  9. Latency 99.9th percentile : 909.1 ms [insert: 940.0 ms, simple1: 477.1 ms]

  10. Latency max : 1416.6 ms [insert: 1,416.6 ms, simple1: 820.0 ms]

  11. Total partitions : 999,847 [insert: 986,542, simple1: 13,305]

  12. Total errors : 0 [insert: 0, simple1: 0]

  13. Total GC count : 41

  14. Total GC memory : 12.277 GiB

  15. Total GC time : 3.0 seconds

  16. Avg GC time : 72.3 ms

  17. StdDev GC time : 25.0 ms

  18. Total operation time : 00:00:34

发现并发并没有提升效率!

user profile 测试案例-3

连接多节点,
不要预热过程,冷启动任务,插入1000000万条数据,读写比例3比1 ,一致性级别设置为:QUORUM

cassandra-stress user profile=./pttest-cassandra.yaml n=1000000 ops(insert=3,simple1=1) no-warmup cl=QUORUM -node 172.20.101.157,172.20.101.160,172.20.101.167 -port native=9042

结果:

 
  1. Results:

  2. Op rate : 1,570 op/s [insert: 1,181 op/s, simple1: 389 op/s]

  3. Partition rate : 30,638 pk/s [insert: 30,250 pk/s, simple1: 389 pk/s]

  4. Row rate : 30,638 row/s [insert: 30,250 row/s, simple1: 389 row/s]

  5. Latency mean : 32.6 ms [insert: 42.4 ms, simple1: 2.6 ms]

  6. Latency median : 4.4 ms [insert: 6.6 ms, simple1: 1.3 ms]

  7. Latency 95th percentile : 128.6 ms [insert: 146.9 ms, simple1: 7.7 ms]

  8. Latency 99th percentile : 283.4 ms [insert: 336.3 ms, simple1: 21.6 ms]

  9. Latency 99.9th percentile : 2334.1 ms [insert: 2,344.6 ms, simple1: 78.0 ms]

  10. Latency max : 2730.5 ms [insert: 2,730.5 ms, simple1: 414.7 ms]

  11. Total partitions : 999,987 [insert: 987,306, simple1: 12,681]

  12. Total errors : 0 [insert: 0, simple1: 0]

  13. Total GC count : 43

  14. Total GC memory : 12.817 GiB

  15. Total GC time : 3.1 seconds

  16. Avg GC time : 72.1 ms

  17. StdDev GC time : 14.9 ms

  18. Total operation time : 00:00:32

user profile 测试案例-4

生成测试结果图
连接多节点,不要预热过程,冷启动任务,插入1000000万条数据,读写比例3比1 ,一致性级别设置为:QUORUM

cassandra-stress user profile=./pttest-cassandra.yaml n=1000000 ops(insert=3,simple1=1) no-warmup cl=QUORUM -graph file=test.html title=test revision=test1 -node 172.20.101.157,172.20.101.160,172.20.101.167 -port native=9042

 
  1. Results:

  2. Op rate : 1,602 op/s [insert: 1,204 op/s, simple1: 398 op/s]

  3. Partition rate : 30,941 pk/s [insert: 30,543 pk/s, simple1: 398 pk/s]

  4. Row rate : 30,941 row/s [insert: 30,543 row/s, simple1: 398 row/s]

  5. Latency mean : 15.6 ms [insert: 20.1 ms, simple1: 2.1 ms]

  6. Latency median : 4.1 ms [insert: 5.9 ms, simple1: 1.2 ms]

  7. Latency 95th percentile : 67.2 ms [insert: 74.7 ms, simple1: 5.4 ms]

  8. Latency 99th percentile : 111.9 ms [insert: 118.9 ms, simple1: 11.7 ms]

  9. Latency 99.9th percentile : 274.2 ms [insert: 289.4 ms, simple1: 71.3 ms]

  10. Latency max : 2231.4 ms [insert: 2,231.4 ms, simple1: 271.1 ms]

  11. Total partitions : 999,996 [insert: 987,127, simple1: 12,869]

  12. Total errors : 0 [insert: 0, simple1: 0]

  13. Total GC count : 41

  14. Total GC memory : 12.276 GiB

  15. Total GC time : 2.7 seconds

  16. Avg GC time : 66.9 ms

  17. StdDev GC time : 15.4 ms

  18. Total operation time : 00:00:32

  19.  
  20. Improvement over 81 threadCount: -8%

参考文档:
https://docs.datastax.com/en/dse/5.1/dse-admin/datastax_enterprise/tools/toolsCStress.html
https://www.instaclustr.com/deep-diving-cassandra-stress-part-3-using-yaml-profiles/
https://zqhxuyuan.github.io/2015/10/15/Cassandra-Stress/

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值