Esrally性能测试步骤与调优

1,928 阅读3分钟

esrally一个对ElasticSearch做基准性能测试的工具,是 elastic 官方开源的一款基于 python3 实现的针对ES 的压测工具,ES官方也是基于 esrally 进行 es 的性能测试。

安装部署

python、git是必要的依赖,需先行安装好。

python3.8安装

使用root用户操作:


yum install libffi-devel

tar zxvf Python-3.8.0.tgz

cd Python-3.8.0

./configure --prefix=/usr/local/python3

make -j120

make install

rm -rf /usr/bin/python3

ln -s /usr/local/python3/bin/python3 /usr/bin/python3

ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3

自行查找python官网:www.python.org/

或直接下载安装包: wget www.python.org/ftp/python/…

Git安装

我的测试环境已安装git version 2.23.0,如果git不满足要求,参考以下内容:

git 源码可以通过下面的链接获取,有各种版本:

mirrors.edge.kernel.org/pub/softwar…

卸载旧版本:

yum remove git

编译安装git到环境中:


tar -xzvf git-2.23.0.tar.gz

cd git-2.23.0

./configure --prefix=/usr/local/git --with-openssl=/usr/local/openssl

sudo make && make install

配置GIT的环境变量去修改 /etc/profile

export GIT_HOME=/usr/local/git-2.23.0

export PATH=\$PATH:\$GIT_HOME

保存后执行source /etc/pfofile

使用 git version 查看GIT版本。

在线安装esrally

# 可自行选择其他版本,这里使用的是2.0.2版本

pip3 install esrally==2.0.2 -i https://pypi.tuna.tsinghua.edu.cn/simple --trusted-host pypi.tuna.tsinghua.edu.cn

错误1

报错的关键信息如下: ERROR: botocore 1.13.50 has requirement urllib3<1.26,>=1.20; python_version >= "3.4", but you'll have urllib3 1.26.9 which is incompatible.

解决办法:

pip3 install urllib3==1.25

重新执行安装命令,显示所有依赖均满足条件。

错误2

执行configure时提示错误:

[root@worker1 opt]# esrally configure

-bash: esrally:未找到命令

这不是安装失败,是因为esrally命令不会自动加入到环境变量!

我们先cd到工作目录下运行:

cd /usr/local/python3/bin

./esrally configure

错误3

最后一行报错ImportError: cannot import name ‘soft_unicode‘ from ‘markupsafe‘……

查到弃用警告:“soft_unicode”已重命名为“soft_str”.旧名称将在 MarkupSafe 2.1 中删除,刚好这里已经是2.1.1版本了,看来需要回退低版本。

解决办法:

pip3 install markupsafe==2.0.1

再次执行./esrally configureesrally就成功安装了!

测试命令

数据集下载

这部分测试所需要的数据集可以在测试中下载,但数据集大且网络不稳定,因此预下载。

如下操作:


# downloads the script from Github

curl -O https://raw.githubusercontent.com/elastic/rally-tracks/master/download.sh

chmod u+x download.sh

chown elasticsearch download.sh

# download all data for the geonames track

su elasticsearch

cd /usr/local/python3/bin/

./esrally configure

cd ~

./download.sh geonames

测试命令

geonames测试实例:


./esrally --pipeline=benchmark-only --target-hosts=192.168.1.104:9200,192.168.1.106:9200,192.168.1.108:9200 --track=geonames --offline --track-params="number_of_shards:32,bulk_indexing_clients:128" --report-file=/opt/report_geonames_32_128-numa.csv --report-format=csv

性能调优

ES参数

  1. ES的内存(heap size)

堆内存配置文件 jvm.options设置(相同大小,不超过32g情况下尽可能大):


-Xms16g

-Xmx16g

  1. ES的thread_pool

主要是不超过物理机的cpu核心数,一般越大越好。

  1. 关闭ES的监控(xpack),设置xpack.monitoring.collection.enabled 为false,提高稳定性。

  2. 调整ES的数据盘为多目录

    对ES读性能影响不大,可能略微对写ES性能有影响。

esrally参数

主要是分片数(shards)和客户端并发数需要调整!

客户端并发数非常重要!客户端并发数非常重要!客户端并发数非常重要!

如果不调大这个clients数其他参数基本白搭。

这个参数踩坑2天

参考文档

01:Elasticsearch压测之Esrally压测标准 - 腾讯云开发者社区-腾讯云

02:esrally:Elasticsearch 官方压测工具及运用详解-阿里云开发者社区

03:es7.3的性能参数调优_thread_pool.write.size

ES集群异常修复与进阶实践 - 掘金 (juejin.cn)