Link Search Menu Expand Document Documentation Menu

OpenSearch Benchmark 快速入门

本教程概述了如何快速安装 OpenSearch Benchmark 并运行您的第一个 OpenSearch Benchmark 工作负载。

先决条件

要执行快速入门步骤,您需要满足以下先决条件

  • 一个当前活跃的 OpenSearch 集群。有关如何创建 OpenSearch 集群的说明,请参阅创建集群
  • Git 2.3 或更高版本。
  • Python 3.8 或更高版本

设置 OpenSearch 集群

如果您还没有活跃的 OpenSearch 集群,可以启动一个新的 OpenSearch 集群以与 OpenSearch Benchmark 配合使用。

OpenSearch Benchmark 尚未在 Windows 版本的 OpenSearch 上进行测试。

安装完成后,您可以通过访问 localhost:9200 来验证 OpenSearch 是否正在运行。如果您的集群启用了安全插件,OpenSearch 将需要使用用户名“admin”和密码“admin”进行 SSL 连接。但是,由于 localhost 地址不是唯一的公共地址,任何证书颁发机构都不会为其颁发 SSL 证书,因此需要使用 -k 选项禁用证书检查。

使用以下命令验证 OpenSearch 是否在禁用 SSL 证书检查的情况下运行

curl -k -u admin:<custom-admin-password> https://:9200			# the "-k" option skips SSL certificate checks

{
  "name" : "147ddae31bf8.opensearch.org",
  "cluster_name" : "opensearch",
  "cluster_uuid" : "n10q2RirTIuhEJCiKMkpzw",
  "version" : {
    "distribution" : "opensearch",
    "number" : "2.10.0",
    "build_type" : "tar",
    "build_hash" : "eee49cb340edc6c4d489bcd9324dda571fc8dc03",
    "build_date" : "2023-09-20T23:54:29.889267151Z",
    "build_snapshot" : false,
    "lucene_version" : "9.7.0",
    "minimum_wire_compatibility_version" : "7.10.0",
    "minimum_index_compatibility_version" : "7.0.0"
  },
  "tagline" : "The OpenSearch Project: https://opensearch.org.cn/"
}

集群运行后,您现在可以安装 OpenSearch Benchmark。

安装 OpenSearch Benchmark

要使用 Docker 安装 OpenSearch Benchmark,请参阅安装 OpenSearch Benchmark > 使用 Docker 安装

要从 PyPi 安装 OpenSearch Benchmark,请输入以下 pip 命令

pip3 install opensearch-benchmark

安装完成后,通过输入以下命令验证 OpenSearch Benchmark 是否正在运行

opensearch-benchmark --help

如果成功,OpenSearch 将返回以下响应

$ opensearch-benchmark --help
usage: opensearch-benchmark [-h] [--version] {execute-test,list,info,create-workload,generate,compare,download,install,start,stop} ...

   ____                  _____                      __       ____                  __                         __
  / __ \____  ___  ____ / ___/___  ____ ___________/ /_     / __ )___  ____  _____/ /_  ____ ___  ____ ______/ /__
 / / / / __ \/ _ \/ __ \\__ \/ _ \/ __ `/ ___/ ___/ __ \   / __  / _ \/ __ \/ ___/ __ \/ __ `__ \/ __ `/ ___/ //_/
/ /_/ / /_/ /  __/ / / /__/ /  __/ /_/ / /  / /__/ / / /  / /_/ /  __/ / / / /__/ / / / / / / / / /_/ / /  / ,<
\____/ .___/\___/_/ /_/____/\___/\__,_/_/   \___/_/ /_/  /_____/\___/_/ /_/\___/_/ /_/_/ /_/ /_/\__,_/_/  /_/|_|
    /_/

 A benchmarking tool for OpenSearch

optional arguments:
  -h, --help            show this help message and exit
  --version             show program's version number and exit

subcommands:
  {execute-test,list,info,create-workload,generate,compare,download,install,start,stop}
    execute-test        Run a benchmark
    list                List configuration options
    info                Show info about a workload
    create-workload     Create a Benchmark workload from existing data
    generate            Generate artifacts
    compare             Compare two test_executions
    download            Downloads an artifact
    install             Installs an OpenSearch node locally
    start               Starts an OpenSearch node locally
    stop                Stops an OpenSearch node locally

Find out more about Benchmark at https://opensearch.org.cn/docs

运行您的第一个基准测试

您现在可以运行您的第一个基准测试。以下基准测试使用 percolator 工作负载。

理解工作负载命令标志

基准测试使用 execute-test 命令和以下命令标志运行

有关其他 execute-test 命令标志,请参阅 execute-test 参考。一些常用选项是 --workload-params--exclude-tasks--include-tasks

  • --pipeline=benchmark-only : 通知 OSB 用户希望提供自己的 OpenSearch 集群。
  • workload=percolator:OpenSearch Benchmark 使用的工作负载名称。
  • --target-host="<OpenSearch Cluster Endpoint>":指示将进行基准测试的目标集群或主机。在此处输入您的 OpenSearch 集群的端点。
  • --client-options="basic_auth_user:'<Basic Auth Username>',basic_auth_password:'<Basic Auth Password>'":您的 OpenSearch 集群的用户名和密码。
  • --test-mode:允许用户运行工作负载,而无需运行完整持续时间。当存在此标志时,Benchmark 将运行工作负载中每个任务的前一千个操作。这仅用于健全性检查——生成的指标没有意义。

--distribution-version,指示 Benchmark 在配置时将使用的 OpenSearch 版本。运行时,execute-test 命令将在连接到 OpenSearch 集群时解析正确的发行版本。

运行工作负载

要使用 OpenSearch Benchmark 运行 percolator 工作负载,请使用以下 execute-test 命令

opensearch-benchmark execute-test --pipeline=benchmark-only --workload=percolator --target-host=https://:9200 --client-options=basic_auth_user:admin,basic_auth_password:admin,verify_certs:false --test-mode

execute-test 命令运行时,percolator 工作负载中的所有任务和操作都将顺序运行。

验证测试

OpenSearch Benchmark 测试运行后,请执行以下步骤验证其是否正常运行

  • 记下您计划进行基准测试的 OpenSearch 或 OpenSearch Dashboards 索引中的文档数量。
  • 在 OpenSearch Benchmark 返回的结果中,比较您的特定工作负载的 workload.json 文件,并验证文档数量是否与文档数量匹配。例如,根据 percolator workload.json 文件,您应该会在集群中看到 2000000 个文档。

理解结果

基准测试完成后,OpenSearch Benchmark 返回以下响应

------------------------------------------------------
    _______             __   _____
   / ____(_)___  ____ _/ /  / ___/_________  ________
  / /_  / / __ \/ __ `/ /   \__ \/ ___/ __ \/ ___/ _ \
 / __/ / / / / / /_/ / /   ___/ / /__/ /_/ / /  /  __/
/_/   /_/_/ /_/\__,_/_/   /____/\___/\____/_/   \___/
------------------------------------------------------

|                                                         Metric |                                       Task |       Value |   Unit |
|---------------------------------------------------------------:|-------------------------------------------:|------------:|-------:|
|                     Cumulative indexing time of primary shards |                                            |     0.02655 |    min |
|             Min cumulative indexing time across primary shards |                                            |           0 |    min |
|          Median cumulative indexing time across primary shards |                                            |  0.00176667 |    min |
|             Max cumulative indexing time across primary shards |                                            |   0.0140333 |    min |
|            Cumulative indexing throttle time of primary shards |                                            |           0 |    min |
|    Min cumulative indexing throttle time across primary shards |                                            |           0 |    min |
| Median cumulative indexing throttle time across primary shards |                                            |           0 |    min |
|    Max cumulative indexing throttle time across primary shards |                                            |           0 |    min |
|                        Cumulative merge time of primary shards |                                            |   0.0102333 |    min |
|                       Cumulative merge count of primary shards |                                            |           3 |        |
|                Min cumulative merge time across primary shards |                                            |           0 |    min |
|             Median cumulative merge time across primary shards |                                            |           0 |    min |
|                Max cumulative merge time across primary shards |                                            |   0.0102333 |    min |
|               Cumulative merge throttle time of primary shards |                                            |           0 |    min |
|       Min cumulative merge throttle time across primary shards |                                            |           0 |    min |
|    Median cumulative merge throttle time across primary shards |                                            |           0 |    min |
|       Max cumulative merge throttle time across primary shards |                                            |           0 |    min |
|                      Cumulative refresh time of primary shards |                                            |   0.0709333 |    min |
|                     Cumulative refresh count of primary shards |                                            |         118 |        |
|              Min cumulative refresh time across primary shards |                                            |           0 |    min |
|           Median cumulative refresh time across primary shards |                                            |  0.00186667 |    min |
|              Max cumulative refresh time across primary shards |                                            |   0.0511667 |    min |
|                        Cumulative flush time of primary shards |                                            |  0.00963333 |    min |
|                       Cumulative flush count of primary shards |                                            |           4 |        |
|                Min cumulative flush time across primary shards |                                            |           0 |    min |
|             Median cumulative flush time across primary shards |                                            |           0 |    min |
|                Max cumulative flush time across primary shards |                                            |  0.00398333 |    min |
|                                        Total Young Gen GC time |                                            |           0 |      s |
|                                       Total Young Gen GC count |                                            |           0 |        |
|                                          Total Old Gen GC time |                                            |           0 |      s |
|                                         Total Old Gen GC count |                                            |           0 |        |
|                                                     Store size |                                            | 0.000485923 |     GB |
|                                                  Translog size |                                            | 2.01873e-05 |     GB |
|                                         Heap used for segments |                                            |           0 |     MB |
|                                       Heap used for doc values |                                            |           0 |     MB |
|                                            Heap used for terms |                                            |           0 |     MB |
|                                            Heap used for norms |                                            |           0 |     MB |
|                                           Heap used for points |                                            |           0 |     MB |
|                                    Heap used for stored fields |                                            |           0 |     MB |
|                                                  Segment count |                                            |          32 |        |
|                                                 Min Throughput |                                      index |     3008.97 | docs/s |
|                                                Mean Throughput |                                      index |     3008.97 | docs/s |
|                                              Median Throughput |                                      index |     3008.97 | docs/s |
|                                                 Max Throughput |                                      index |     3008.97 | docs/s |
|                                        50th percentile latency |                                      index |     351.059 |     ms |
|                                       100th percentile latency |                                      index |     365.058 |     ms |
|                                   50th percentile service time |                                      index |     351.059 |     ms |
|                                  100th percentile service time |                                      index |     365.058 |     ms |
|                                                     error rate |                                      index |           0 |      % |
|                                                 Min Throughput |                   wait-until-merges-finish |       28.41 |  ops/s |
|                                                Mean Throughput |                   wait-until-merges-finish |       28.41 |  ops/s |
|                                              Median Throughput |                   wait-until-merges-finish |       28.41 |  ops/s |
|                                                 Max Throughput |                   wait-until-merges-finish |       28.41 |  ops/s |
|                                       100th percentile latency |                   wait-until-merges-finish |     34.7088 |     ms |
|                                  100th percentile service time |                   wait-until-merges-finish |     34.7088 |     ms |
|                                                     error rate |                   wait-until-merges-finish |           0 |      % |
|                                                 Min Throughput |     percolator_with_content_president_bush |       36.09 |  ops/s |
|                                                Mean Throughput |     percolator_with_content_president_bush |       36.09 |  ops/s |
|                                              Median Throughput |     percolator_with_content_president_bush |       36.09 |  ops/s |
|                                                 Max Throughput |     percolator_with_content_president_bush |       36.09 |  ops/s |
|                                       100th percentile latency |     percolator_with_content_president_bush |     35.9822 |     ms |
|                                  100th percentile service time |     percolator_with_content_president_bush |     7.93048 |     ms |
|                                                     error rate |     percolator_with_content_president_bush |           0 |      % |

[...]

|                                                 Min Throughput |          percolator_with_content_ignore_me |        16.1 |  ops/s |
|                                                Mean Throughput |          percolator_with_content_ignore_me |        16.1 |  ops/s |
|                                              Median Throughput |          percolator_with_content_ignore_me |        16.1 |  ops/s |
|                                                 Max Throughput |          percolator_with_content_ignore_me |        16.1 |  ops/s |
|                                       100th percentile latency |          percolator_with_content_ignore_me |     131.798 |     ms |
|                                  100th percentile service time |          percolator_with_content_ignore_me |     69.5237 |     ms |
|                                                     error rate |          percolator_with_content_ignore_me |           0 |      % |
|                                                 Min Throughput | percolator_no_score_with_content_ignore_me |       29.37 |  ops/s |
|                                                Mean Throughput | percolator_no_score_with_content_ignore_me |       29.37 |  ops/s |
|                                              Median Throughput | percolator_no_score_with_content_ignore_me |       29.37 |  ops/s |
|                                                 Max Throughput | percolator_no_score_with_content_ignore_me |       29.37 |  ops/s |
|                                       100th percentile latency | percolator_no_score_with_content_ignore_me |     45.5703 |     ms |
|                                  100th percentile service time | percolator_no_score_with_content_ignore_me |      11.316 |     ms |
|                                                     error rate | percolator_no_score_with_content_ignore_me |           0 |      % |



--------------------------------
[INFO] SUCCESS (took 18 seconds)
--------------------------------

percolator 工作负载运行的每个任务都代表在测试运行时执行的特定 OpenSearch API 操作(例如 Bulk 或 Search)。输出摘要中的每个任务都包含以下信息

  • 吞吐量: 每秒成功的 OpenSearch 操作数。
  • 延迟: Benchmark 发送和接收请求和响应所花费的时间,包括等待时间。
  • 服务时间: Benchmark 发送和接收请求和响应所花费的时间,不包括等待时间。
  • 错误率: 任务期间运行的操作中不成功或返回 200 错误代码的百分比。

有关如何生成摘要报告的更多详细信息,请参阅摘要报告

在您自己的集群上运行 OpenSearch Benchmark

现在您已经熟悉了在集群上运行 OpenSearch Benchmark,您可以在您自己的集群上运行 OpenSearch Benchmark,使用相同的 execute-test 命令,替换以下设置。

  • https://:9200 替换为您的目标集群端点。这可以是一个 URI,例如 https://search.mydomain.comHOST:PORT 规范。
  • 如果集群配置了基本身份验证,请将命令行中的用户名和密码替换为相应的凭据。
  • 如果您未将 localhost 指定为目标集群,请删除 verify_certs:false 指令。此指令仅适用于未设置 SSL 证书的集群。
  • 如果您使用 HOST:PORT 规范并计划使用 SSL/TLS,请指定 https://,或将 use_ssl:true 指令添加到 --client-options 字符串选项中。
  • 删除 --test-mode 标志以运行完整工作负载,而不是缩短的测试。

您可以复制以下命令模板以在您自己的终端中使用

opensearch-benchmark execute-test --pipeline=benchmark-only --workload=percolator --target-host=<OpenSearch Cluster Endpoint> --client-options=basic_auth_user:admin,basic_auth_password:admin

后续步骤

请参阅以下资源以了解有关 OpenSearch Benchmark 的更多信息

  • 用户指南:深入了解 OpenSearch Benchmark 如何帮助您跟踪集群的性能。
  • 教程:使用分步指南了解更高级的基准测试配置和功能。