
cassandra-stress工具用于对ScyllaDB和Cassandra集群进行基准测试和负载测试。该工具还支持测试自定义CQL表和查询,允许用户基准测试其数据模型。本文档重点介绍用户模式,因为这允许测试实际的schema。
本文档撰写时,cassandra-stress的最新版本为3.17.0。请在https://github.com/scylladb/cassandra-stress/releases%E6%9F%A5%E7%9C%8B%E6%9C%80%E6%96%B0%E7%89%88%E6%9C%AC%E3%80%82
ScyllaDB提供了多种安装cassandra-stress的方法,选择最适合您环境的方式:
使用cassandra-stress的推荐和官方方式是通过ScyllaDB提供的Docker镜像,这确保了一致且即用型的环境。
您可以从Docker Hub拉取最新的Docker镜像:
shelldocker pull scylladb/cassandra-stress:latest
latest标签始终与GitHub上的版本标签(如3.17.0)对应。要查看所有可用标签,请访问:
https://hub.docker.com/r/scylladb/cassandra-stress/tags
下载后,可直接运行cassandra-stress:
shelldocker run --rm scylladb/cassandra-stress <命令>
如需使用特定版本,将latest替换为所需版本标签:
shelldocker pull scylladb/cassandra-stress:3.17.0 docker run --rm scylladb/cassandra-stress:3.17.0 <命令>
在Docker容器中运行时,可能会因容器化开销导致性能损失。为缓解此问题,可使用--network=host选项让容器共享主机网络栈,提升性能:
shelldocker run --rm --network=host --security-opt seccomp=unconfined scylladb/cassandra-stress <命令>
--security-opt seccomp=unconfined允许容器内不受限制的系统调用(主要是ioctl、iopl和clone)。
可直接从GitHub发布页面下载预编译二进制文件。
前提条件:确保系统已安装Java Runtime Environment (JRE) 11或更高版本。
使用curl下载:
shellcurl -LO https://github.com/scylladb/cassandra-stress/releases/download/v3.17.0/cassandra-stress-3.17.0-bin.tar.gz curl -LO https://github.com/scylladb/cassandra-stress/releases/download/v3.17.0/cassandra-stress-3.17.0-bin.tar.gz.sha256
使用wget下载:
shellwget https://github.com/scylladb/cassandra-stress/releases/download/v3.17.0/cassandra-stress-3.17.0-bin.tar.gz wget https://github.com/scylladb/cassandra-stress/releases/download/v3.17.0/cassandra-stress-3.17.0-bin.tar.gz.sha256
使用sha256sum验证下载:
shellsha256sum -c cassandra-stress-3.17.0-bin.tar.gz.sha256
验证成功将显示:
textcassandra-stress-3.17.0-bin.tar.gz: OK
从源码构建cassandra-stress需确保安装以下依赖:
步骤如下:
克隆仓库:
shellgit clone --depth=1 https://github.com/scylladb/cassandra-stress.git
检出特定版本(3.17.0):
shellcd cassandra-stress git checkout tags/3.17.0
使用Apache Ant构建二进制文件:
shellant -Drelease=true artifacts
编译后的二进制文件位于build目录。
如需Docker化构建,按以下步骤操作:
克隆仓库:
shellgit clone --depth=1 https://github.com/scylladb/cassandra-stress.git
构建Docker镜像:
shellcd cassandra-stress docker build -t cassandra-stress --compress .
如需使用自定义驱动jar,将jar放入仓库根目录并运行:
shelldocker build -t cassandra-stress --build-args BUILD_OPTS=-Dlib.override.com.scylladb.scylla-driver-core=/app/<jar文件名>.jar --compress .
构建完成后,可本地运行镜像:
shelldocker run --rm cassandra-stress <命令>
consoletools/bin/cassandra-stress write n=1000000 -node 192.168.1.101 # 向指定主机插入100万条数据 tools/bin/cassandra-stress read n=10000000 -node 192.168.1.101 -o read # 100万次读取 tools/bin/cassandra-stress write -node 192.168.1.101,192.168.1.102 n=10000000 # 向两个节点分布插入1000万条数据 tools/bin/cassandra-stress help -pop # 打印人口分布选项的帮助信息
容器中运行时,注意命令行需加引号:
consoledocker run scylladb/cassandra-stress 'cassandra-stress write n=100000 -node 1.2.3.4'
交互式运行容器:
consoledocker run --rm -d --name c-s -it --entrypoint=/bin/bash -i scylladb/cassandra-stress:latest docker exec -it c-s /bin/bash
cassandra-stress <命令> [选项]。如需了解特定命令或选项的更多信息,运行cassandra-stress help-pop:人口分布和分区内访问顺序-insert:与批处理和拆分分区更新的各种方法相关的插入特定选项-col:列详细信息,如大小和计数分布、数据生成器、名称、比较器以及是否使用超级列-rate:线程数、速率限制或自动模式(默认自动)-mode:Thrift或CQL及选项-errors:压力测试期间遇到错误时的处理方式-sample:指定用于测量延迟的样本数-schema:复制设置、压缩、压缩策略等-node:要连接的节点-log:进度日志位置和间隔-transport:自定义传输工厂-port:连接Cassandra节点的端口-sendto:指定要发送命令的压力服务器-graph:图表记录指标-tokenrange:令牌范围设置用户模式允许测试自定义schema。从长远来看,这比构建应用后才发现schema无法扩展更节省时间。
用户模式需要YAML格式的配置文件。可指定多个YAML文件,此时ops参数中的操作需引用为specname.opname。
配置文件标识符:
cqlspecname: staff_activities
测试的keyspace:
cqlkeyspace: staff
keyspace的CQL定义(如已存在则可选):
cqlkeyspace_definition: | CREATE KEYSPACE stresscql WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 3};
要测试的表:
cqltable: staff_activities
表的CQL定义(如已存在则可选):
cqltable_definition: | CREATE TABLE staff_activities ( name text, when timeuuid, what text, PRIMARY KEY(name, when, what) )
上述表中生成列的可选元信息。min和max仅适用于text和blob类型。distribution字段表示该列在行中的总体唯一分布:
cqlcolumnspec: - name: name size: uniform(5..10) # 员工姓名长度在5-10字符之间 population: uniform(1..10) # 从10个可能的员工中选择 - name: when cluster: uniform(20..500) # 员工有20到500个事件 - name: what size: normal(10..100,50)
支持的分布类型:
指数分布,范围[min..max]:
cqlEXP(min..max)
极值(Weibull)分布,范围[min..max]:
cqlEXTREME(min..max,shape)
高斯/正态分布,mean=(min+max)/2,stdev=(mean-min)/stdvrng:
cqlGAUSSIAN(min..max,stdvrng)
高斯/正态分布,显式定义mean和stdev:
cqlGAUSSIAN(min..max,mean,stdev)
均匀分布,范围[min, max]:
cqlUNIFORM(min..max)
固定分布,始终返回相同值:
cqlFIXED(val)
如前缀为~,则分布反转
所有列的默认值:size: uniform(4..8),population: uniform(1..100B),cluster: fixed(1)
插入分布:
cqlinsert: # 每批插入的分区数 partitions: fixed(1) # 每个分区更新的行数 select: fixed(1)/500 # 插入使用的批处理类型:UNLOGGED或LOGGED batchtype: UNLOGGED
当前所有插入均在批处理中完成。
测试期间使用的读取语句:
cqlqueries: events: cql: select * from staff_activities where name = ? fields: samerow latest_event: cql: select * from staff_activities where name = ? LIMIT 1 fields: samerow
运行用户模式测试:
cqlcassandra-stress user profile=./example.yaml duration=1m "ops(insert=1,latest_event=1,events=1)" truncate=once
这将创建schema,然后运行测试1分钟,插入、latest_event查询和events查询的数量相等。此外,测试前会截断表一次。
完整示例可在yaml中找到。
使用多个yaml文件运行用户模式测试:
shellcassandra-stress user profile=./example.yaml,./example2.yaml duration=1m "ops(ex1.insert=1,ex1.latest_event=1,ex2.insert=2)" truncate=once
这将运行example.yaml和example2.yaml中指定的操作。example.yaml和example2.yaml可引用同一张表,但需确保表定义相同(数据生成规范可不同)。
每次压力测试运行均可生成图表。
!https://github.com/scylladb/cassandra-stress/raw/master/example-stress-graph.png
创建新图表:
cqlcassandra-stress user profile=./stress-example.yaml "ops(insert=1,latest_event=1,events=1)" -graph file=graph.html title="Awesome graph"
向现有图表添加新运行,指向现有文件并添加修订名称:
cqlcassandra-stress user profile=./stress-example.yaml duration=1m "ops(insert=1,latest_event=1,events=1)" -graph file=graph.html title="Awesome graph" revision="Second run"
您可以使用以下命令拉取该镜像。请将 <标签> 替换为具体的标签版本。如需查看所有可用标签版本,请访问 标签列表页面。

探索更多轩辕镜像的使用方法,找到最适合您系统的配置方式
通过 Docker 登录认证访问私有仓库
无需登录使用专属域名
Kubernetes 集群配置 Containerd
K3s 轻量级 Kubernetes 镜像加速
VS Code Dev Containers 配置
Podman 容器引擎配置
HPC 科学计算容器配置
ghcr、Quay、nvcr 等镜像仓库
Harbor Proxy Repository 对接专属域名
Portainer Registries 加速拉取
Nexus3 Docker Proxy 内网缓存
需要其他帮助?请查看我们的 常见问题Docker 镜像访问常见问题解答 或 提交工单
docker search 限制
站内搜不到镜像
离线 save/load
插件要用 plugin install
WSL 拉取慢
安全与 digest
新手拉取配置
镜像合规机制
manifest unknown
no matching manifest(架构)
invalid tar header(解压)
TLS 证书失败
DNS 超时
域名连通性排查
410 Gone 排查
402 与流量用尽
401 认证失败
429 限流
D-Bus 凭证提示
413 与超大单层
来自真实用户的反馈,见证轩辕镜像的优质服务