Es 常用

1、Es的客户端,通过python查

from elasticsearch import Elasticsearch

import json

es = Elasticsearch(['127.0.0.1:9202'])

 

with open('/tmp/index.txt','r') as f:

  content = [line.strip() for line in f]

#print (content)

 

for index in content:

  res = es.search(index=index,size=1)

#print (res)

#res = json.loads(res)

#print (res)

  source = res['hits']['hits'][0]['_source']['source']

  print (source)

 

2、es聚合查询过大导致实例挂

https://www.jianshu.com/p/3993d0acb187

2fielddata内存限制

indices.fielddata.cache.size:20%,超出限制,清除内存已有fielddata数据。这个是写到es.yml里的

fielddata占用的内存超出了这个比例的限制,那么就清除掉内存中已有的fielddata数据。

默认无限制,限制内存使用,但是会导致频繁evict和reload,大量IO性能损耗,以及内存碎片和gc

3、监控fielddata内存使用情况

GET /_stats/fielddata?fields=*

GET /_nodes/stats/indices/fielddata?fields=*

GET /_nodes/stats/indices/fielddata?level=indices&fields=*

4circuit breaker

如果一次query load的feilddata超过总内存,就会oom --> 内存溢出

circuit breaker会估算query要加载的fielddata大小,如果超出总内存,就短路,query直接失败

indices.breaker.fielddata.limit:fielddata的内存限制,默认60%

indices.breaker.request.limit:执行聚合的内存限制,默认40%

indices.breaker.total.limit:综合上面两个,限制在70%以内

也是配置到es.yml中的

 

Exporter 内容

https://blog.csdn.net/Q748893892/article/details/107206840

 

Es7 优化参数:

curl -H "Content-Type: application/json" -XPUT 'http://10.62.200.34:9201/_all/_settings?preserve_existing=true' -d '{

  "index.refresh_interval" : "120s",

  "index.translog.durability" : "async",

  "index.translog.flush_threshold_size" : "2096mb",

  "index.translog.sync_interval" : "120s"

}'

 

curl -XPUT 'http://localhost:9200/_all/_settings?preserve_existing=true' -d '{

  "index.merge.scheduler.max_thread_count" : "1",

  "index.refresh_interval" : "300s"

}'

 

index.merge.scheduler.max_thread_count:1 # 索引 merge 最大线程数

indices.memory.index_buffer_size:30% # 内存

index.translog.durability:async # 这个可以异步写硬盘,增大写的速度

index.translog.sync_interval:120s #translog 间隔时间

discovery.zen.ping_timeout:120s # 心跳超时时间

discovery.zen.fd.ping_interval:120s # 节点检测时间

discovery.zen.fd.ping_timeout:120s #ping 超时时间

discovery.zen.fd.ping_retries:6 # 心跳重试次数

thread_pool.bulk.size:20 # 写入线程个数 由于我们查询线程都是在代码里设定好的,我这里只调节了写入的线程数

thread_pool.bulk.queue_size:1000 # 写入线程队列大小

index.refresh_interval:300s #index 刷新间隔

posted on 2022-05-16 11:04  每天进步一点点点点点  阅读(221)  评论(0编辑  收藏  举报