您好,登錄后才能下訂單哦!
Cassandra從很早的版本就自帶了cassandra-stress壓力測(cè)試工具,它的使用方法在cassandra-stress后添加命令和選項(xiàng)。其中常用的命令一般只用到:write、read、mixed、user。其中單純的write和read只測(cè)試讀和寫(xiě),mixed則測(cè)試同時(shí)讀寫(xiě)。user是2.1之后新增的,通過(guò)自定義配置文件,在配置文件中可以指定insert和query查詢(xún)語(yǔ)句。
命令command沒(méi)有以-開(kāi)頭,而選項(xiàng)[options]有兩種方式:-選項(xiàng)名稱(chēng) 選項(xiàng)值或者選項(xiàng)名稱(chēng)=選項(xiàng)值。
counter_read: 多個(gè)并發(fā)讀,必須首先通過(guò)counter_write測(cè)試填充群集。
counter_write:多個(gè)并發(fā)寫(xiě)。
legacy:傳統(tǒng)模式的支持。
mixed:混合模式和可配置的讀寫(xiě)比例和分布。集群必須先寫(xiě)測(cè)試數(shù)據(jù)填充。
read: 多個(gè)并發(fā)讀取。必須首先通過(guò)寫(xiě)入測(cè)試填充群集。
write: 針對(duì)群集的多個(gè)并發(fā)寫(xiě)入。
user: 交錯(cuò)用戶提供具有可配置比率和分布的查詢(xún)。
version: 打印cassandra-stress版本。
print: 打印定義輸出
列詳細(xì)信息,例如大小和計(jì)數(shù)分布,數(shù)據(jù)生成器
用法:
-col names =?[slice] [super =?] [comparator =?] [timestamp =?] [size = DIST(?)]
要么
-col [n = DIST(?)] [slice] [super =?] [comparator =?] [timestamp =?] [size = DIST(?)]
速率
使用以下選項(xiàng)設(shè)置費(fèi)率:
-rate threads=N [throttle=N] [fixed=N]
配置項(xiàng):
threads=N 并發(fā)運(yùn)行的客戶端數(shù)量。
throttle=N 所有客戶端的每秒操作達(dá)到最大速率,默認(rèn)值為0。
fixed=N 期望所有客戶每秒的固定運(yùn)行率。默認(rèn)值為0。
或者
-rate [threads>=N] [threads<=N] [auto]
參數(shù):
threads > = N :同時(shí)運(yùn)行至少這么多客戶端。默認(rèn)值為4。
threads <= N :最多同時(shí)運(yùn)行這么多客戶端。默認(rèn)值為1000。
auto 一旦吞吐量飽和,就停止增加線程。
如何處理壓力測(cè)試期間遇到的錯(cuò)誤
用法:
-errors [retries = N] [ignore] [skip-read-validation]
retries=N 失敗前嘗試次數(shù)。
ignore 忽略錯(cuò)誤。
skip-read-validation 跳過(guò)讀取驗(yàn)證和消息輸出。
壓力測(cè)試生成結(jié)果圖表,可以將多個(gè)測(cè)試一起繪制成圖表。
用法:
-graph file=? [revision=?] [title=?] [op=?]
日志設(shè)置
用法:
level=verbose
or
-log [level=?] [no-summary] [file=?] [hdrfile=?] [interval=?] [no-settings] [no-progress] [show-queries] [query-log-file=?]
Thrift or CQL 選項(xiàng)
用法:
-mode thrift [smart] [user=?] [password=?]
or
-mode native [unprepared] cql3 [compression=?] [port=?] [user=?] [password=?] [auth-provider=?] [maxPending=?] [connectionsPerHost=?] [protocolVersion=?]
or
-mode simplenative [prepared] cql3 [port=?]
要連接的節(jié)點(diǎn)
用法:
-node [datacenter=?] [whitelist] [file=?] []
指定用于連接Cassandra節(jié)點(diǎn)的端口。9042端口用于native協(xié)議的客戶端連接。
-port [native=?] [thrift=?] [jmx=?]
表結(jié)構(gòu)設(shè)置
用法:
-schema [replication(?)] [keyspace=?] [compaction(?)] [compression=?]
指定要將壓力命令發(fā)送到的服務(wù)器。
用法:
-sendto <host>
-tokenrange
令牌范圍設(shè)置。
用法:
-tokenrange [no-wrap] [split-factor =?] [savedata =?]
profile=?:指定YAML配置文件,需要自己編寫(xiě)DML,插入,查詢(xún);(只能作為user選項(xiàng)的子選項(xiàng))
ops(?): 指定操作類(lèi)型和數(shù)量,比如ops(inserts=1),或者ops(queries=2),其中queries需要用指定的查詢(xún)名稱(chēng)代替;(只能作為user選項(xiàng)的子選項(xiàng))
n=?: 指定操作數(shù)量,比如要寫(xiě)入1萬(wàn)條數(shù)據(jù),n=10000; 要讀取1000條數(shù)據(jù),n=1000;
err<?: 指定均值的標(biāo)準(zhǔn)誤差; 達(dá)到此值時(shí), cassandra-stress將結(jié)束。默認(rèn)值為0.02;
truncate=?: 是否需要清空表,可選項(xiàng)有:never(默認(rèn)值),one,always;
cl=?: 一致性級(jí)別,可選項(xiàng)有:ONE,QUORUM,LOCAL_QUORUM,EACH_QUORUM,ALL,ANY,LOCAL_ONE(默認(rèn)值);(只能作為user選項(xiàng)的子選項(xiàng))
no-warmup:不要預(yù)熱過(guò)程,冷啟動(dòng)任務(wù)。
--注意
選項(xiàng)名稱(chēng),選項(xiàng)值必須放在 子選項(xiàng)選項(xiàng)值前面,比如正確的用法:truncate=one -node xxx
#插入(寫(xiě)入)一百萬(wàn)行
cassandra-stress write n = 1000000 -rate threads = 50 -node 172.20.101.166 -port native=9042
#讀二十萬(wàn)行。
cassandra-stress讀n = 200000 -rate threads = 50 -node 172.20.101.157 -port native=9042
#讀取行持續(xù)3分鐘。
cassandra-stress read duration = 3m -rate threads = 50 -node 172.20.101.164 -port native=9042
#混合讀寫(xiě)持續(xù)5分鐘。
cassandra-stress mixed duration = 5m -rate threads = 50 -node 172.20.101.164 -port native=9042
#首先讀取200,000行而不預(yù)熱50,000行。
cassandra-stress read n = 200000 no-warmup -rate threads = 50 -node 172.20.101.160, 172.20.101.166 -port native=9042
#通過(guò)身份驗(yàn)證運(yùn)行cassandra-stress
以下示例顯示使用-mode選項(xiàng)提供用戶名和密碼:
cassandra-stress -mode native cql3 user = cassandra password = cassandra no-warmup cl = QUORUM
100萬(wàn)條數(shù)據(jù)寫(xiě)入,一致性級(jí)別為L(zhǎng)ocal_Quorum,客戶端線程數(shù)=500個(gè),2個(gè)列,副本數(shù)據(jù)=3個(gè)
cassandra-stress write n=1000000 cl=LOCAL_QUORUM -rate threads=500 \
-col "size=fixed(2048)" "n=fixed(32)" -schema "replication(factor=3)" -node 172.20.101.157 -port native=9042
#
# This is an example YAML profile for cassandra-stress
#
# insert data
# cassandra-stress user profile=/home/jake/stress1.yaml ops(insert=1)
#
# read, using query simple1:
# cassandra-stress profile=/home/jake/stress1.yaml ops(simple1=1)
#
# mixed workload (90/10)
# cassandra-stress user profile=/home/jake/stress1.yaml ops(insert=1,simple1=9)
#
# Keyspace info
#
keyspace: load_test
#
# The CQL for creating a keyspace (optional if it already exists)
#
keyspace_definition: |
CREATE KEYSPACE load_test WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 1};
#
# Table info
#
table: event2
#
# The CQL for creating a table you wish to stress (optional if it already exists)
#
table_definition: |
CREATE TABLE event2 (
cookie_id int,
timestamp timestamp,
event_name text,
session_id uuid,
page text,
device text,
PRIMARY KEY(cookie_id, timestamp, event_name, session_id)
) WITH CLUSTERING ORDER BY (timestamp DESC)
#
# Optional meta information on the generated columns in the above table
# The min and max only apply to text and blob types
# The distribution field represents the total unique population
# distribution of that column across rows. Supported types are
#
# EXP(min..max) An exponential distribution over the range [min..max]
# EXTREME(min..max,shape) An extreme value (Weibull) distribution over the range [min..max]
# GAUSSIAN(min..max,stdvrng) A gaussian/normal distribution, where mean=(min+max)/2, and stdev is (mean-min)/stdvrng
# GAUSSIAN(min..max,mean,stdev) A gaussian/normal distribution, with explicitly defined mean and stdev
# UNIFORM(min..max) A uniform distribution over the range [min, max]
# FIXED(val) A fixed distribution, always returning the same value
# Aliases: extr, gauss, normal, norm, weibull
#
# If preceded by ~, the distribution is inverted
#
# Defaults for all columns are size: uniform(4..8), population: uniform(1..100B), cluster: fixed(1)
#
columnspec:
- name: cookie_id
population: uniform(1..100M) # the range of unique values to select for the field (default is 100Billion)
- name: timestamp
size: fixed(13)
population: uniform(1..100M)
- name: event_name
size: uniform(5..10)
population: uniform(1..100M)
- name: session_id
size: fixed(32)
population: uniform(1..100M)
- name: page
size: gaussian(16..64)
population: uniform(1..100M)
- name: device
size: fixed(4)
population: uniform(1..10)
insert:
partitions: uniform(1..50) # number of unique partitions to update in a single operation
# if batchcount > 1, multiple batches will be used but all partitions will
# occur in all batches (unless they finish early); only the row counts will vary
batchtype: UNLOGGED # type of batch to use
select: fixed(10)/10 # uniform chance any single generated CQL row will be visited in a partition;
# generated for each partition independently, each time we visit it
#
# A list of queries you wish to run against the schema
#
queries:
simple1:
cql: select * from event2 where cookie_id = ?
fields: samerow # samerow or multirow (select arguments from the same row, or randomly from all rows in the partition)
Collapse
不要預(yù)熱過(guò)程,冷啟動(dòng)任務(wù),插入1000000萬(wàn)條數(shù)據(jù),讀寫(xiě)比例3比1 ,一致性級(jí)別設(shè)置為: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
結(jié)果
Results:
Op rate : 1,562 op/s [insert: 1,164 op/s, simple1: 398 op/s]
Partition rate : 30,063 pk/s [insert: 29,667 pk/s, simple1: 396 pk/s]
Row rate : 30,063 row/s [insert: 29,667 row/s, simple1: 396 row/s]
Latency mean : 28.2 ms [insert: 37.0 ms, simple1: 2.7 ms]
Latency median : 4.3 ms [insert: 6.5 ms, simple1: 1.1 ms]
Latency 95th percentile : 126.2 ms [insert: 142.5 ms, simple1: 7.7 ms]
Latency 99th percentile : 230.4 ms [insert: 254.1 ms, simple1: 23.8 ms]
Latency 99.9th percentile : 476.8 ms [insert: 554.2 ms, simple1: 96.6 ms]
Latency max : 2581.6 ms [insert: 2,581.6 ms, simple1: 2,264.9 ms]
Total partitions : 999,932 [insert: 986,756, simple1: 13,176]
Total errors : 0 [insert: 0, simple1: 0]
Total GC count : 43
Total GC memory : 12.565 GiB
Total GC time : 3.0 seconds
Avg GC time : 69.4 ms
StdDev GC time : 13.4 ms
Total operation time : 00:00:33
Improvement over 181 threadCount: -7%
不要預(yù)熱過(guò)程,冷啟動(dòng)任務(wù),500并發(fā),插入1000000萬(wàn)條數(shù)據(jù),讀寫(xiě)比例3比1 ,一致性級(jí)別設(shè)置為: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
Results:
Op rate : 1,496 op/s [insert: 1,145 op/s, simple1: 396 op/s]
Partition rate : 28,763 pk/s [insert: 29,221 pk/s, simple1: 394 pk/s]
Row rate : 28,763 row/s [insert: 29,221 row/s, simple1: 394 row/s]
Latency mean : 49.5 ms [insert: 64.0 ms, simple1: 7.5 ms]
Latency median : 4.9 ms [insert: 7.0 ms, simple1: 1.3 ms]
Latency 95th percentile : 251.3 ms [insert: 286.0 ms, simple1: 29.7 ms]
Latency 99th percentile : 513.0 ms [insert: 561.0 ms, simple1: 118.3 ms]
Latency 99.9th percentile : 909.1 ms [insert: 940.0 ms, simple1: 477.1 ms]
Latency max : 1416.6 ms [insert: 1,416.6 ms, simple1: 820.0 ms]
Total partitions : 999,847 [insert: 986,542, simple1: 13,305]
Total errors : 0 [insert: 0, simple1: 0]
Total GC count : 41
Total GC memory : 12.277 GiB
Total GC time : 3.0 seconds
Avg GC time : 72.3 ms
StdDev GC time : 25.0 ms
Total operation time : 00:00:34
發(fā)現(xiàn)并發(fā)并沒(méi)有提升效率!
連接多節(jié)點(diǎn),
不要預(yù)熱過(guò)程,冷啟動(dòng)任務(wù),插入1000000萬(wàn)條數(shù)據(jù),讀寫(xiě)比例3比1 ,一致性級(jí)別設(shè)置為: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
結(jié)果:
Results:
Op rate : 1,570 op/s [insert: 1,181 op/s, simple1: 389 op/s]
Partition rate : 30,638 pk/s [insert: 30,250 pk/s, simple1: 389 pk/s]
Row rate : 30,638 row/s [insert: 30,250 row/s, simple1: 389 row/s]
Latency mean : 32.6 ms [insert: 42.4 ms, simple1: 2.6 ms]
Latency median : 4.4 ms [insert: 6.6 ms, simple1: 1.3 ms]
Latency 95th percentile : 128.6 ms [insert: 146.9 ms, simple1: 7.7 ms]
Latency 99th percentile : 283.4 ms [insert: 336.3 ms, simple1: 21.6 ms]
Latency 99.9th percentile : 2334.1 ms [insert: 2,344.6 ms, simple1: 78.0 ms]
Latency max : 2730.5 ms [insert: 2,730.5 ms, simple1: 414.7 ms]
Total partitions : 999,987 [insert: 987,306, simple1: 12,681]
Total errors : 0 [insert: 0, simple1: 0]
Total GC count : 43
Total GC memory : 12.817 GiB
Total GC time : 3.1 seconds
Avg GC time : 72.1 ms
StdDev GC time : 14.9 ms
Total operation time : 00:00:32
生成測(cè)試結(jié)果圖
連接多節(jié)點(diǎn),不要預(yù)熱過(guò)程,冷啟動(dòng)任務(wù),插入1000000萬(wàn)條數(shù)據(jù),讀寫(xiě)比例3比1 ,一致性級(jí)別設(shè)置為: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
Results:
Op rate : 1,602 op/s [insert: 1,204 op/s, simple1: 398 op/s]
Partition rate : 30,941 pk/s [insert: 30,543 pk/s, simple1: 398 pk/s]
Row rate : 30,941 row/s [insert: 30,543 row/s, simple1: 398 row/s]
Latency mean : 15.6 ms [insert: 20.1 ms, simple1: 2.1 ms]
Latency median : 4.1 ms [insert: 5.9 ms, simple1: 1.2 ms]
Latency 95th percentile : 67.2 ms [insert: 74.7 ms, simple1: 5.4 ms]
Latency 99th percentile : 111.9 ms [insert: 118.9 ms, simple1: 11.7 ms]
Latency 99.9th percentile : 274.2 ms [insert: 289.4 ms, simple1: 71.3 ms]
Latency max : 2231.4 ms [insert: 2,231.4 ms, simple1: 271.1 ms]
Total partitions : 999,996 [insert: 987,127, simple1: 12,869]
Total errors : 0 [insert: 0, simple1: 0]
Total GC count : 41
Total GC memory : 12.276 GiB
Total GC time : 2.7 seconds
Avg GC time : 66.9 ms
StdDev GC time : 15.4 ms
Total operation time : 00:00:32
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/
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。