ES reindex 实战

机器配置

Data nodes:i3.4xlarge.search * 3     16C 122G
master nodes:c5.2xlarge.search * 3    8C 16G

案例1-kafka

kafka consumer tps = 18k qps
bulk request batch size = 100 (程序单线程等待100个消息到达后提交,因此系统的吞吐量与batch无关)
数据量(cat命令):

green  open   admin_operate_log_v1_2021       1   0        432            0    183.9kb        183.9kb
green  open   admin_operate_log_v1_2022       1   0   38855695            0     10.9gb         10.9gb
green  open   admin_operate_log_v1_2023       1   0   15996192            0      4.5gb          4.5gb

索引配置

"settings": {
        "index": {
            "refresh_interval": "-1",
            "number_of_shards": "1",
            "number_of_replicas": "0"
        }
    }

ES负载

cpu: 写入期间<=49%,写入完成后短暂峰值:68-72%
内存:73%左右
截屏2023-05-11 22.33.15.png

性能

耗时:55-60分钟左右

案例2-reindex

数据量

healthstatusindexuuidprirepdocs.countdocs.deletedstore.sizepri.store.size
greenopenuser_operation_log_v1_202211F7qtS9A3QxCFlIiZ8vCB0Q21647144705.3gb2.6gb
greenopenuser_operation_log_v1_2022109MWtw90pTLes7ZzsDo5zxw21547969804.3gb2.1gb
greenopenadmin_operate_log_v1_2021cxmLz54CR2C2eQkWcftGdw104320183.9kb183.9kb
greenopenadmin_operate_log_v1_2022mD9B3fY3T5moY2iMoSJ6rA1038855695010.9gb10.9gb
greenopenadmin_operate_log_v1_2023Q8umgdzcR1idQncdPnUCbA101599619204.5gb4.5gb
greenopenuser_operation_log_v1_2022129Bo4HkB1T_G8oiOiJVcDow21571470704.6gb2.3gb
greenopenuser_operation_log_v1_2022088jMbqQPIQT-GI67lo72Xbg21507047105gb2.5gb
greenopenuser_operation_log_v1_202207ppYBaM3NQkaPBkZowXqbdA21525329005.1gb2.5gb
greenopenuser_operation_log_v1_202206A12fRvkhTOCcI12QPCzbxw21549914605.6gb2.8gb
greenopenuser_operation_log_v1_202305ltM-SbzaQkaEmqVmV84iEQ211659596501.1gb583mb
greenopenuser_operation_log_v1_2023040W9kvl-jTlWizYltRq4yGQ217589405444.7gb2.3gb
greenopenuser_operation_log_v1_202205KzLscm-gRSq-v7aps96M4Q21734302007.5gb3.7gb
greenopenuser_operation_log_v1_202209DDMTU6mVTn-uF1NZPJ-x4Q21469902204.3gb2.1gb
greenopenuser_operation_log_v1_202303f13sJ9wyRxagWYOCK0t07w21769829605gb2.5gb
greenopentoken_sale_v1K7FFK24FSWi1oKlXrRuBug31115722550.2kb275.1kb
greenopenuser_operation_log_v1_202204grbxxC5iQie3ADnnyE5Erw21828801908.3gb4.1gb
greenopenuser_operation_log_v1_202302oDOUznF5QKGgTmetRv2uRA21679759604.4gb2.2gb
greenopenuser_operation_log_v1_202203aJLU9fhzT3uCNf2wVdb3Gw219291234011.3gb5.6gb
greenopen.kibana_1ErpcRNskT_-GLNVpeQd-1A111010.1kb5kb
greenopenuser_operation_log_v1_202301BqpOEoDTTO2ue-uDfjUoCA2161036531529254.2gb2.1gb
greenopenuser_operation_log_v1_202202d9VaDToWSs2qbdyxJyDvdg219415513012gb6gb
greenopenuser_operation_log_v1_202201FahUyKbeTYK_zYYc_UhofQ2111594662015.4gb7.7gb

索引配置

es_host='https://my_es_host'
indices=(user_operation_log_v1_202301 user_operation_log_v1_202302)

curl --location --request POST "${es_host}/_template/user_operation_log_template_v2" \
--header 'Content-Type: application/json' \
--data-raw '{
  "order": 0,
  "index_patterns": [
    "user_operation_log_v2*"
  ],
  "mappings": {
    "dynamic": "false",
    "properties": {
      "user_id": {
        "type": "long"
      },
      "operation": {
        "type": "keyword",
        "normalizer": "caseSensitive"
      },
      "real_ip": {
        "type": "keyword"
      },
      "full_ip": {
        "type": "keyword"
      },
      "client_type": {
        "type": "keyword",
        "normalizer": "caseSensitive"
      },
      "version_code": {
        "type": "keyword",
        "index": false
      },
      "apikey": {
        "type": "keyword",
        "index": false
      },
      "user_agent": {
        "type": "keyword",
        "index": false
      },
      "request_time": {
        "type": "long"
      },
      "response_time": {
        "type": "long",
        "index": false
      },
      "request": {
        "type": "text"
      },
      "response": {
        "type": "text"
      },
      "response_status": {
        "type": "keyword",
        "normalizer": "caseSensitive"
      }
    }
  },
  "settings": {
    "index": {
      "refresh_interval" : "-1",
      "number_of_shards": "2",
      "number_of_replicas": "0"
    },
    "analysis": {
      "normalizer": {
        "caseSensitive": {
          "filter": "lowercase",
          "type": "custom"
        }
      }
    }
  },
  "aliases": {
    "user_operation_log_v2": {}
  }
}'

for((i=0;i<${#indices[*]};i++));do
  target_index=${indices[i]/v1/v2};
  message="source = ${indices[i]}, target = ${target_index}";
  echo "${message}"
  start=$(date +"%s")
  curl -HContent-Type:application/json -XPOST "${es_host}/_reindex?slices=2&requests_per_second=-1&wait_for_completion=false&pretty" -d'{
    "source": {
      "index": "'${indices[i]}'"
      ,"size": 5000
    },
    "dest": {
      "index": "'${target_index}'"
    }
  }'
  end=$(date +"%s")
  echo "${message} cost `expr $end - $start` seconds"
done

ES负载

截屏2023-05-11 14.26.56.png

性能

耗时:10分钟左右

第一次提交2个索引reindex
{
  "completed": true,
  "task": {
    "node": "b8mpzb7ARLau_iJVU4fkmg",
    "id": 246335488,
    "type": "transport",
    "action": "indices:data/write/reindex",
    "status": {
      "total": 9415513,
      "updated": 0,
      "created": 9415513,
      "deleted": 0,
      "batches": 1884,
      "version_conflicts": 0,
      "noops": 0,
      "retries": {
        "bulk": 0,
        "search": 0
      },
      "throttled_millis": 0,
      "requests_per_second": -1.0,
      "throttled_until_millis": 0,
      "slices": [
        {
          "slice_id": 0,
          "total": 4708452,
          "updated": 0,
          "created": 4708452,
          "deleted": 0,
          "batches": 942,
          "version_conflicts": 0,
          "noops": 0,
          "retries": {
            "bulk": 0,
            "search": 0
          },
          "throttled_millis": 0,
          "requests_per_second": -1.0,
          "throttled_until_millis": 0
        },
        {
          "slice_id": 1,
          "total": 4707061,
          "updated": 0,
          "created": 4707061,
          "deleted": 0,
          "batches": 942,
          "version_conflicts": 0,
          "noops": 0,
          "retries": {
            "bulk": 0,
            "search": 0
          },
          "throttled_millis": 0,
          "requests_per_second": -1.0,
          "throttled_until_millis": 0
        }
      ]
    },
    "description": "reindex from [user_operation_log_v1_202202] to [user_operation_log_v2_202202][_doc]",
    "start_time_in_millis": 1683784030867,
    "running_time_in_nanos": 447756932234,
    "cancellable": true,
    "headers": {
      
    }
  },
  "response": {
    "took": 447740,
    "timed_out": false,
    "total": 9415513,
    "updated": 0,
    "created": 9415513,
    "deleted": 0,
    "batches": 1884,
    "version_conflicts": 0,
    "noops": 0,
    "retries": {
      "bulk": 0,
      "search": 0
    },
    "throttled": "0s",
    "throttled_millis": 0,
    "requests_per_second": -1.0,
    "throttled_until": "0s",
    "throttled_until_millis": 0,
    "slices": [
      {
        "slice_id": 0,
        "total": 4708452,
        "updated": 0,
        "created": 4708452,
        "deleted": 0,
        "batches": 942,
        "version_conflicts": 0,
        "noops": 0,
        "retries": {
          "bulk": 0,
          "search": 0
        },
        "throttled": "0s",
        "throttled_millis": 0,
        "requests_per_second": -1.0,
        "throttled_until": "0s",
        "throttled_until_millis": 0
      },
      {
        "slice_id": 1,
        "total": 4707061,
        "updated": 0,
        "created": 4707061,
        "deleted": 0,
        "batches": 942,
        "version_conflicts": 0,
        "noops": 0,
        "retries": {
          "bulk": 0,
          "search": 0
        },
        "throttled": "0s",
        "throttled_millis": 0,
        "requests_per_second": -1.0,
        "throttled_until": "0s",
        "throttled_until_millis": 0
      }
    ],
    "failures": [
      
    ]
  }
}
-
{
  "completed": true,
  "task": {
    "node": "BrXZu22XQfi94P1l5ErOwA",
    "id": 168840526,
    "type": "transport",
    "action": "indices:data/write/reindex",
    "status": {
      "total": 9291234,
      "updated": 0,
      "created": 9291234,
      "deleted": 0,
      "batches": 1859,
      "version_conflicts": 0,
      "noops": 0,
      "retries": {
        "bulk": 0,
        "search": 0
      },
      "throttled_millis": 0,
      "requests_per_second": -1.0,
      "throttled_until_millis": 0,
      "slices": [
        {
          "slice_id": 0,
          "total": 4642972,
          "updated": 0,
          "created": 4642972,
          "deleted": 0,
          "batches": 929,
          "version_conflicts": 0,
          "noops": 0,
          "retries": {
            "bulk": 0,
            "search": 0
          },
          "throttled_millis": 0,
          "requests_per_second": -1.0,
          "throttled_until_millis": 0
        },
        {
          "slice_id": 1,
          "total": 4648262,
          "updated": 0,
          "created": 4648262,
          "deleted": 0,
          "batches": 930,
          "version_conflicts": 0,
          "noops": 0,
          "retries": {
            "bulk": 0,
            "search": 0
          },
          "throttled_millis": 0,
          "requests_per_second": -1.0,
          "throttled_until_millis": 0
        }
      ]
    },
    "description": "reindex from [user_operation_log_v1_202203] to [user_operation_log_v2_202203][_doc]",
    "start_time_in_millis": 1683784030916,
    "running_time_in_nanos": 437625719457,
    "cancellable": true,
    "headers": {
      
    }
  },
  "response": {
    "took": 437607,
    "timed_out": false,
    "total": 9291234,
    "updated": 0,
    "created": 9291234,
    "deleted": 0,
    "batches": 1859,
    "version_conflicts": 0,
    "noops": 0,
    "retries": {
      "bulk": 0,
      "search": 0
    },
    "throttled": "0s",
    "throttled_millis": 0,
    "requests_per_second": -1.0,
    "throttled_until": "0s",
    "throttled_until_millis": 0,
    "slices": [
      {
        "slice_id": 0,
        "total": 4642972,
        "updated": 0,
        "created": 4642972,
        "deleted": 0,
        "batches": 929,
        "version_conflicts": 0,
        "noops": 0,
        "retries": {
          "bulk": 0,
          "search": 0
        },
        "throttled": "0s",
        "throttled_millis": 0,
        "requests_per_second": -1.0,
        "throttled_until": "0s",
        "throttled_until_millis": 0
      },
      {
        "slice_id": 1,
        "total": 4648262,
        "updated": 0,
        "created": 4648262,
        "deleted": 0,
        "batches": 930,
        "version_conflicts": 0,
        "noops": 0,
        "retries": {
          "bulk": 0,
          "search": 0
        },
        "throttled": "0s",
        "throttled_millis": 0,
        "requests_per_second": -1.0,
        "throttled_until": "0s",
        "throttled_until_millis": 0
      }
    ],
    "failures": [
      
    ]
  }
}
第二次提交14个索引reindex

202204-202305
日志过多省略,与第一次提交差别不大

总结

案例1

kafka:tps=18k
文档量:54851887
文档大小:15.4GB
ES节点:单个
耗时:55-60分钟
负载:cpu=50%左右,内存=70%左右

案例2

根据第二次提交的reindex分析
文档量:113968775
文档大小:53.6GB
ES节点:3个
耗时:10分钟
负载:cpu=80%左右,内存=80%左右

正如开头描述的,系统单线程工作瓶颈明显,并发与吞吐量低,优点是限制了单个业务索引(多个物理索引按月分片)资源占用,避免拖垮系统

reindex风险

14个索引reindex的异步任务启动时间如下,可以看到几乎是同时启动的,因此批量操作是要把控并行的数量,slices参数以及size参数的配置,都要事先把控,避免将服务器跑垮

1683785201349 2023-05-11 14:06:41
1683785201371 2023-05-11 14:06:41
1683785201395
1683785201418
1683785201440
1683785201463
1683785201485
1683785201508
1683785201531
1683785201551
1683785201572
1683785201598
1683785201623
1683785201645
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值