為什么要壓測
俗話說 "知己知彼变抽,百戰(zhàn)不殆"蜻底,當我們上線一個新的系統(tǒng)或應用的時候,至少要知道這個系統(tǒng)或應用的上線在哪里拔稳,做直接的數據可能就是【吞吐量】是多少葛峻,【延時】是多少,【瓶頸】是什么巴比。更多關于壓測的指導可參考CoolShell 的性能測試應該怎么做术奖?
壓測工具
rally es 官方提供的一款壓測工具。同時官方也將 es 的實時壓測結果放在了 https://elasticsearch-benchmarks.elastic.co/ , 你可以將你自己的結果與它進行對比匿辩,官方是使用 2 臺服務器進行壓測腰耙,一臺運行 rally, 一臺運行 es, 服務器的配置如下:
CPU: Intel(R) Core(TM) i7-6700 CPU @ 3.40GHz
RAM: 32 GB
SSD: Crucial MX200
OS: Linux Kernel version 4.8.0-53
JVM: Oracle JDK 1.8.0_131-b11
rally
安裝
# 創(chuàng)建虛擬環(huán)境
virtualenv venv
pip3 install esrally
# 配置 rally,默認在 ~/.rally 目錄中
esrally configure
rally 相關術語
rally 是汽車拉力賽的意思铲球,所以關于它里面術語也是跟汽車的拉力賽有關挺庞。
-
track: 即賽道的意思,這里指壓測用到的樣本數據和壓測策略稼病,使用
esrally list tracks
列出选侨。rally 自帶的 track 可在 https://github.com/elastic/rally-tracks 中查看,每個 track 的文件名中都存在 README.md 對壓測的數據類型和參數做了詳細的說明然走。每個 track 都包含一個track.json
文件援制,track.json
中定義了樣本數據的獲取 url,具體的策略芍瑞,我們來看一個具體的eventdata/track.json
:corpora
定義了 eventdata 數據從 AWS S3 中獲取晨仑,這里獲取樣本數據比較坑爹,下載的速度很慢拆檬,國內基本就是無法下載洪己,我是通過 AWS 新加坡上的一個 ECS 下載下來在通過公網拉取到國內的服務器上,新加坡到國內用公網的速度還不錯竟贯,國內也有人將樣本數據都放在百度云了:https://pan.baidu.com/s/123zgferlhWflOj7qJxFD1w{% import "rally.helpers" as rally with context %} { "version": 2, "description": "This benchmark indexes HTTP access logs generated based sample logs from the elastic.co website using the generator available in https://github.com/elastic/rally-eventdata-track", "indices": [ { "name": "eventdata", "body": "index.json" } ], "corpora": [ { "name": "eventdata", "base-url": "http://benchmarks.elasticsearch.org.s3.amazonaws.com/corpora/eventdata", "documents": [ { "source-file": "eventdata.json.bz2", "document-count": 20000000, "compressed-bytes": 791796014, "uncompressed-bytes": 16437108429 } ] } ], "operations": [ {{ rally.collect(parts="operations/*.json") }} ], "challenges": [ {{ rally.collect(parts="challenges/*.json") }} ] }
chanllenges
中定義了壓測的策略答捕,operations
中定義的策略可以被chellenges
中引用,我們來看 eventdata 的默認策略eventdata/challenges/default.json
:名字為
append-no-conflicts
的 challenge 在schedule
的operation
中定義了具體壓測中包含的內容(delete-index屑那,create-index, check-cluster-health 等)拱镐,更多的可參考官方文檔: https://esrally.readthedocs.io/en/latest/track.html{ "name": "append-no-conflicts", "description": "Indexes the whole document corpus using Elasticsearch default settings. We only adjust the number of replicas as we benchmark a single node cluster and Rally will only start the benchmark if the cluster turns green. Document ids are unique so all index operations are append only.", "default": true, "schedule": [ { "operation": "delete-index" }, { "operation": { "operation-type": "create-index", "settings": {{index_settings | default({}) | tojson}} } }, { "name": "check-cluster-health", "operation": { "operation-type": "cluster-health", "index": "eventdata", "request-params": { "wait_for_status": "{{cluster_health | default('green')}}", "wait_for_no_relocating_shards": "true" } } }, { "operation": "index-append", "warmup-time-period": 120, "clients": {{bulk_indexing_clients | default(8)}} }, { "operation": "force-merge", "clients": 1 } ] }
- car: 即賽車的意思艘款,這里指被壓測的不同類型的 es 實例 (包括 jvm 的大小,版本等)沃琅,rally 能根據你指定的 es 類型哗咆,自動幫你下載并配置,如果你想對一個已存在的 es 實例進行測試阵难,可以不使用這個選項岳枷,而是在后面的 Pipeline 中指定。
- Pipeline: 指一個壓測流程呜叫,可以通過
esrally list pipeline
查看空繁,其中有一個benchmark-only
的流程,就是將 es 的管理交給用戶來操作朱庆,rally 只用來做壓測盛泡,如果你想針對已有的 es 進行壓測,則使用改模式娱颊。 - race: 即一次比賽的意思傲诵,這里是進行一次壓測,如果沒有指定 track箱硕, 則默認使用
geonames
track 進行測試拴竹。
如下實例,使用 pmc 樣本數據對一個已存在的 es 實例進行壓力測試剧罩,使用 track-params
對默認的壓測參數進行覆蓋栓拜,對這次測試以 version:5.5.0
進行 tag 標記。
esrally --track=pmc --target-hosts=10.10.102.35:9200 \
--pipeline=benchmark-only \
--track-params="number_of_shards:3,number_of_replicas=1" \
--user-tag="version:5.5.0"
被壓測 ES 硬件資源
- OS:Ubuntu 16.04
- CPU: 12 core
- MEM: 24G
- DISK: 普通硬盤
- ES Version: 5.2
壓測結果
以下所有的壓測參數均使用默認值
壓測數據類型: pmc (學術論文)
單節(jié)點惠昔,普通硬盤幕与,副本數0
Task | Min Throughput | Median Throughput | Max Throughput | P99 latency |
---|---|---|---|---|
index-append | 853.79 docs/s | 889.94 docs/s | 909.67 docs/s | 19435.3ms |
單節(jié)點,4塊普通硬盤組成 RAID0镇防,副本數0
Task | Min Throughput | Median Throughput | Max Throughput | P99 latency |
---|---|---|---|---|
index-append | 1182.27 docs/s | 1259.22 docs/s | 1285.84 docs/s | 4811.05 ms |
壓測數據類型: eventdata
單節(jié)點啦鸣,普通硬盤,副本數0
Task | Min Throughput | Median Throughput | Max Throughput | P90 latency | P99 latency |
---|---|---|---|---|---|
index-append | 29751.8 docs/s | 34498.3 docs/s | 35366.3 docs/s | 1338.77 ms | 2337.83 ms |
單節(jié)點来氧,4塊普通硬盤組成 RAID0诫给,副本數0
Task | Min Throughput | Median Throughput | Max Throughput | P90 latency | P99 latency |
---|---|---|---|---|---|
index-append | 39982.6 docs/s | 40951.4 docs/s | 41216.8 docs/s | 1177.72 ms | 1470.46 ms |
3節(jié)點,4塊普通硬盤組成 RAID0啦扬,副本數0
Task | Min Throughput | Median Throughput | Max Throughput | P90 latency | P99 latency |
---|---|---|---|---|---|
index-append | 68381.3 docs/s | 70045.9 docs/s | 70533.6 docs/s | 654.343 ms | 800.628 ms |
3節(jié)點中狂,4塊普通硬盤組成 RAID0,副本數1
Task | Min Throughput | Median Throughput | Max Throughput | P90 latency | P99 latency |
---|---|---|---|---|---|
index-append | 37794.8 docs/s | 38637 docs/s | 39569.2 docs/s | 1232.43 ms | 1426.42 ms |
壓測數據類型: geonames
單節(jié)點考传,普通硬盤,副本數0
Task | Min Throughput | Median Throughput | Max Throughput | P90 latency | P99 latency |
---|---|---|---|---|---|
index-append | 49641.4 docs/s | 50195.2 docs/s | 51236.1 docs/s | 1213.64ms | 2235.51ms |
單節(jié)點证鸥,4塊普通硬盤組成 RAID0僚楞,副本數0
Task | Min Throughput | Median Throughput | Max Throughput | P90 latency | P99 latency |
---|---|---|---|---|---|
index-append | 54829.7 docs/s | 55663.9 docs/s | 56248.9 docs/s | 941.875 ms | 1327.69 ms |
3節(jié)點勤晚,4塊普通硬盤組成 RAID0,副本數0
Task | Min Throughput | Median Throughput | Max Throughput | P90 latency | P99 latency |
---|---|---|---|---|---|
index-append | 88812.7 docs/s | 89132.5 docs/s | 89452.5 docs/s | 512.118 ms | 961.595 ms |
總結
- 在同樣的硬件情況下泉褐,我通過 mdadm 將 4 塊硬盤組成了 RAID0 來提升硬盤的 IO赐写,可以看到針對不同的樣本數據,PMC 類型 的樣本性能提升最明顯膜赃,geonames 類型的提升最少挺邀。可見跳座,單條日志越大端铛,硬盤的性能提升對 ES 的性能提升越明顯。
- 比對單節(jié)點與集群(3節(jié)點)的數據疲眷,可見禾蚕,通過新增節(jié)點的方式提升性能,性能的提升量并不等于
*
新增節(jié)點數據數量狂丝,增加一個節(jié)點性能提升 40% 左右换淆。 - 對比開啟副本數為1與不開啟副本的結果,可見几颜,副本數為1是倍试,es 的寫性能和延遲是原來的 1/2,所以生產環(huán)境中的副本數蛋哭,還是需要在性能和穩(wěn)定性上做一定的權衡县习。