elasticsearch8.3容器单机版搭建

基于docker-compose快速启动

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
services:
es01:
image: docker.elastic.co/elasticsearch/elasticsearch:8.13.0
container_name: es01
restart: always
ports:
- "19200:9200"
- "19300:9300"
environment:
- http.host=0.0.0.0
- discovery.type=single-node
- ELASTIC_PASSWORD=xxx
- ES_JAVA_OPTS=-Xms1g -Xmx1g
volumes:
- ./data:/usr/share/elasticsearch/data:z
- ./plugins:/usr/share/elasticsearch/plugins:z
- ./logs:/usr/share/elasticsearch/logs:z

curl查看es-node thread_pool

curl -s -q --location --request GET 'http://47.96.130.181:19200/_nodes/stats/thread_pool' \
--header 'Authorization: Basic xxxx' |python3 -m json.tool |grep search -A 5

/_nodes/stats/thread_pool.search 如何自定义

thread_pool.search.queue_size, 
thread_pool.get.queue_size, 
thread_pool.search_worker.queue_size,
thread_pool.analyze.queue_size, 
thread_pool.write.queue_size, 
thread_pool.search.size,
thread_pool.system_read.queue_size]?"

thread_pool

Elasticsearch 8.3_nodes/stats/thread_pool.search 里的一些线程池参数是否可以修改,以及如何自定义。我们来仔细分析。

1.线程池参数概念

Elasticsearch 的线程池(thread pool)管理不同类型的任务,例如:

线程池类型 用途
search 搜索请求执行
get GET 请求执行
write 索引/写入请求
bulk 批量操作
analyze 分词分析
system_read 系统内部读操作

每个线程池通常有几个关键参数:

  • size:线程池中固定线程数或动态计算的核心线程数。
  • queue_size:队列长度,即当线程全部被占用时,允许等待的请求数量。
  • keep_alive:非核心线程空闲多久会被回收(仅部分线程池可配置)。

2.Elasticsearch 配置方式

注意:ES8.x 对线程池参数可配置性有限

  • 线程池 类型为 fixed 的(固定线程数)

    • sizequeue_size 可以在 elasticsearch.yml 中修改,或者通过 动态 cluster setting 修改(大部分为静态,需要重启)。
  • 线程池 类型为 scaling(可扩展)

    • size 代表初始线程数,Elasticsearch 会根据负载自动扩展到最大值,队列长度通常可配置。
  • 有些线程池参数 不能在运行时修改,尤其是系统线程池或内部线程池。

3.验证参数是否生效

1
GET /_nodes/stats/thread_pool/search

输出类似:

1
2
3
4
5
6
7
8
9
10
{
"search": {
"threads": 40,
"queue": 0,
"active": 0,
"rejected": 0,
"largest": 40,
"completed": 123456
}
}
  • threads → 当前线程池大小
  • queue → 当前排队请求数
  • largest → 历史最大线程数
  • rejected → 被拒绝请求数量