Elasticsearch 壓力測試

為什么要壓測

俗話說 "知己知彼,百戰(zhàn)不殆",當(dāng)我們上線一個新的系統(tǒng)或應(yīng)用的時(shí)候,至少要知道這個系統(tǒng)或應(yīng)用的上線在哪里,做直接的數(shù)據(jù)可能就是【吞吐量】是多少,【延時(shí)】是多少,【瓶頸】是什么。更多關(guān)于壓測的指導(dǎo)可參考CoolShell 的性能測試應(yīng)該怎么做?

壓測工具

rally es 官方提供的一款壓測工具。同時(shí)官方也將 es 的實(shí)時(shí)壓測結(jié)果放在了 https://elasticsearch-benchmarks.elastic.co/ , 你可以將你自己的結(jié)果與它進(jìn)行對比,官方是使用 2 臺服務(wù)器進(jìn)行壓測,一臺運(yùn)行 rally, 一臺運(yùn)行 es, 服務(wù)器的配置如下:

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,默認(rèn)在 ~/.rally 目錄中
esrally configure

rally 相關(guān)術(shù)語

rally 是汽車?yán)惖囊馑?,所以關(guān)于它里面術(shù)語也是跟汽車的拉力賽有關(guān)。

  • track: 即賽道的意思,這里指壓測用到的樣本數(shù)據(jù)和壓測策略,使用 esrally list tracks 列出。rally 自帶的 track 可在 https://github.com/elastic/rally-tracks 中查看,每個 track 的文件名中都存在 README.md 對壓測的數(shù)據(jù)類型和參數(shù)做了詳細(xì)的說明。每個 track 都包含一個 track.json 文件,track.json 中定義了樣本數(shù)據(jù)的獲取 url,具體的策略,我們來看一個具體的 eventdata/track.json:

    corpora定義了 eventdata 數(shù)據(jù)從 AWS S3 中獲取,這里獲取樣本數(shù)據(jù)比較坑爹,下載的速度很慢,國內(nèi)基本就是無法下載,我是通過 AWS 新加坡上的一個 ECS 下載下來在通過公網(wǎng)拉取到國內(nèi)的服務(wù)器上,新加坡到國內(nèi)用公網(wǎng)的速度還不錯,國內(nèi)也有人將樣本數(shù)據(jù)都放在百度云了: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 的默認(rèn)策略 eventdata/challenges/default.json:

    名字為 append-no-conflicts 的 challenge 在 scheduleoperation 中定義了具體壓測中包含的內(nèi)容(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 實(shí)例 (包括 jvm 的大小,版本等),rally 能根據(jù)你指定的 es 類型,自動幫你下載并配置,如果你想對一個已存在的 es 實(shí)例進(jìn)行測試,可以不使用這個選項(xiàng),而是在后面的 Pipeline 中指定。
  • Pipeline: 指一個壓測流程,可以通過 esrally list pipeline 查看,其中有一個 benchmark-only 的流程,就是將 es 的管理交給用戶來操作,rally 只用來做壓測,如果你想針對已有的 es 進(jìn)行壓測,則使用改模式。
  • race: 即一次比賽的意思,這里是進(jìn)行一次壓測,如果沒有指定 track, 則默認(rèn)使用 geonames track 進(jìn)行測試。

如下實(shí)例,使用 pmc 樣本數(shù)據(jù)對一個已存在的 es 實(shí)例進(jìn)行壓力測試,使用 track-params 對默認(rèn)的壓測參數(shù)進(jìn)行覆蓋,對這次測試以 version:5.5.0 進(jìn)行 tag 標(biāo)記。

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

壓測結(jié)果

以下所有的壓測參數(shù)均使用默認(rèn)值

壓測數(shù)據(jù)類型: pmc (學(xué)術(shù)論文)

單節(jié)點(diǎn),普通硬盤,副本數(shù)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é)點(diǎn),4塊普通硬盤組成 RAID0,副本數(shù)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

壓測數(shù)據(jù)類型: eventdata

單節(jié)點(diǎn),普通硬盤,副本數(shù)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é)點(diǎn),4塊普通硬盤組成 RAID0,副本數(shù)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é)點(diǎn),4塊普通硬盤組成 RAID0,副本數(shù)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é)點(diǎn),4塊普通硬盤組成 RAID0,副本數(shù)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

壓測數(shù)據(jù)類型: geonames

單節(jié)點(diǎn),普通硬盤,副本數(shù)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é)點(diǎn),4塊普通硬盤組成 RAID0,副本數(shù)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é)點(diǎn),4塊普通硬盤組成 RAID0,副本數(shù)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

總結(jié)

  • 在同樣的硬件情況下,我通過 mdadm 將 4 塊硬盤組成了 RAID0 來提升硬盤的 IO,可以看到針對不同的樣本數(shù)據(jù),PMC 類型 的樣本性能提升最明顯,geonames 類型的提升最少??梢?,單條日志越大,硬盤的性能提升對 ES 的性能提升越明顯。
  • 比對單節(jié)點(diǎn)與集群(3節(jié)點(diǎn))的數(shù)據(jù),可見,通過新增節(jié)點(diǎn)的方式提升性能,性能的提升量并不等于*新增節(jié)點(diǎn)數(shù)據(jù)數(shù)量,增加一個節(jié)點(diǎn)性能提升 40% 左右。
  • 對比開啟副本數(shù)為1與不開啟副本的結(jié)果,可見,副本數(shù)為1是,es 的寫性能和延遲是原來的 1/2,所以生產(chǎn)環(huán)境中的副本數(shù),還是需要在性能和穩(wěn)定性上做一定的權(quán)衡

參考

https://segmentfault.com/a/1190000011174694#articleHeader0

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容