LoginSignup
4
4

More than 5 years have passed since last update.

ElasticeSearchのindexが遅くなったら対処したこと

Last updated at Posted at 2016-07-05

こちらを参考にした
http://stackoverflow.com/questions/33952089/slow-index-speed-of-elasticsearch

https://www.elastic.co/guide/en/elasticsearch/guide/current/heap-sizing.html
ここを参考にHEAPサイズ調整とswap無効にする

1.メモリ不足して、swapが大量に発生していないかの調査

$ free
total       used       free     shared    buffers     cached
Mem:       2052380    1967252      85128          4      40220     250592
-/+ buffers/cache:    1676440     375940
Swap:      1048572     175832     872740

結構発生してる。

2.HEAPサイズを調整

ES_HEAP_SIZEを物理メモリの半分にする

3.swapを無効

http://kakakazuma.hatenablog.com/entry/2015/03/12/015504
こちらを参考に設定

vim /etc/sysconfig/elasticsearch
ES_HEAP_SIZE=1024m #物理メモリの半分 
MAX_LOCKED_MEMORY=unlimited

4.elasticesearchを再起動

公式ページのおすすめ手順でやる

# rebalance無効化、これでshardsの自動調整が止める
$ curl -XPUT 'http://localhost:9200/_cluster/settings' -d '{
    "transient" : {
        "cluster.routing.allocation.enable" : "none"
    }
}'

# elasticsearch再起動
$ sudo service elasticsearch restart

# rebalance有効化
$ curl -XPUT 'http://localhost:9200/_cluster/settings' -d '{
    "transient" : {
        "cluster.routing.allocation.enable" : "all"
    }
}'

# head pluginでshardsの調整できたことを確認

5.swapが無効になってることを確認(mlockallがtrueになってること)

http://localhost::9200/_nodes/process?pretty

"process": {
  "refresh_interval_in_millis": 1000,
  "id": 1232,
  "max_file_descriptors": 65535,
  "mlockall": true
}

作業中困ったこと

なぜかelasticsearch起動に失敗した
  1. /var/log/elasticsearch/したのログを調査したが、特になし
  2. システムからのエラーと疑って、/var/log/messagesを調査
Out of memory: Kill process 11560 (java) score 948 or sacrifice child
Killed process 11560 (java) total-vm:2949556kB, anon-rss:1929660kB, file-rss:13048kB

調べたら、elasticsearchが利用してるメモリが多くので、OOM Killerに殺させた。

物理メモリが2Gのマシンに、HEAPサイズを1.5Gに設定されたため、OOM Killerに殺させた
HEAPサイズを勧めの物理メモリの半分1Gにして、これで起動できた

4
4
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
4