es 主要內存使用大戶

一、Segment Memory

詞典的前綴索引(Term Index),具體概念參考相關文檔。
別小看只是前綴的索引,如果索引庫多,數據量大,每個節點達到10G不稀奇,node沒節點heap內存才設置了32G啊。 :joy:

  1. 查看方法
    _cat/segments
    _cat/segments?v&h=index,shard,segment,size,size.memory
    _cat/nodes?v&h=ip,port,sm,heap.*

  2. 解決方法
    刪除不用的索引。

關閉索引 (文件仍然存在於磁盤,只是釋放掉內存)。需要的時候可以重新打開。

定期對不再更新的索引做optimize (ES2.0以後更改爲force merge api)。這Optimze的實質是對segment file強制做合併,可以節省大量的segment memory。

二、Filter Cache

查詢緩存,查詢次數多了,改緩存消耗的內存也是大數字了,可以通過query-max等參數限制。
  1. 查看方法:

_nodes/d28-84/stats/indices/query_cache

  1. 解決方法:

$ curl -XPOST ‘http://localhost:9200/clientlog-201607,clientlog-201606/_cache/clear

/kimchy,elasticsearch/_cache/clear?request_cache=true

三、Field Data cache

indices.breaker.fielddata.limit indices.fielddata.cache.size 等參數可以限制

1.解決方法:
啓用Doc Values,禁用_all

2.查看方法:

/_stats/fielddata/
# Indices Stat
curl -XGET 'http://localhost:9200/_stats/fielddata/?fields=field1,field2&pretty'

# You can use wildcards for field names
curl -XGET 'http://localhost:9200/_stats/fielddata/?fields=field*&pretty'

es 2.x後,默認都是docvalue,改問題越來越好解決了,不然lucene的field data cache也是很驚人的大,偶是很少用field data cache的。

四、Bulk Queue

批量寫入數據bulk的時候隊列中保存的數據佔用的內存。
別小看這裏的數據量,如果隊列1000個。每個bulk 4092行,每行10k這樣佔用的內存也超級驚人啊。

1、查看方法
/_cat/thread_pool?v&h=host,bulk.*
threadpool:
bulk:
type: fixed
size: 60
queue_size: 1000
2、解決方法:
設置隊列小一點,forcemerge寫入數據。
本工程的隊列值可以控制寫入數據,減少隊列數據。

五、Indexing Buffer

Indexing Buffer是用來緩存新數據,當其滿了或者refresh/flush interval到了,就會以segment file的形式寫入到磁盤。
indices.memory.index_buffer_size
Accepts either a percentage or a byte size value. It defaults to 10%, meaning that 10% of the total heap allocated to a node will be used as the indexing buffer size.
indices.memory.min_index_buffer_size
If the index_buffer_size is specified as a percentage, then this setting can be used to specify an absolute minimum. Defaults to 48mb.
indices.memory.max_index_buffer_size
If the index_buffer_size is specified as a percentage, then this setting can be used to specify an absolute maximum. Defaults to unbounded.
indices.memory.min_shard_index_buffer_size
Sets a hard lower limit for the memory allocated per shard for its own indexing buffer. Defaults to 4mb

六、超大搜索聚合結果集的fetch

1、常用或者必用查詢字段作route,數據在不同node分佈均勻;
2、對超時間查詢請求作分析,增加wrapper作屏蔽, 判斷slow log顯示的查詢;
3、預處理數據,高併發常用查詢使用預處理索引庫(最佳方式);
4、將實時ad-hoc請求適用spark+es合併執行方式處理(es-hadoop spark)。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章