본문 바로가기

IT/Elasticsearch

Disabling Swap!


Elasticsearch 서버에 부하가 걸릴 때 성능 향상(이라 쓰고 서버의 생존)을 꾀하기 위해서

OS에서 메모리를 효율적으로 활용하기 위해 수행하는 swapping을 봉쇄하는 것이 효과적일 수 있다.



Elasticsearch Official Documentation : Setup > Configuration > Memory setting

https://www.elastic.co/guide/en/elasticsearch/reference/2.x/setup-configuration.html#setup-configuration-memory




단락 중간 즈음에 소개된 바와 같이, RestAPI 또는 CURL로 다음 주소로 접근하면 프로세스 상태를 확인할 수 있다.

# check process through curl
curl http://localhost:9200/_nodes/process?pretty

# check process through RestAPI
/_nodes/process?pretty



공식 문서에는 3가지 방법이 제시되어 있지만, 개발중인 서버에서는 권한 문제인지 효과가 없었다.


데이터 마이그레이션 중 슬레이브 서버에 가해지는 부하로 노드가 계속 죽어나가는 상황인데

지푸라기라도 잡는 심정으로 설정파일에 옵션을 추가했는데 안됨..ㅜㅜ

뭐라도 건져야겠다 싶어 로그를 뒤져보던 확인해보니 Elasticsearch에서 친절하게 안내해주고 있었다.

[bootstrap] Unable to lock JVM Memory: error=12,reason=Cannot allocate memory [bootstrap] This can result in part of the JVM being swapped out. [bootstrap] Increase RLIMIT_MEMLOCK, soft limit: 65536, hard limit: 65536 [bootstrap] These can be adjusted by modifying /etc/security/limits.conf, for example: # allow user 'user' mlockall username soft memlock unlimited username hard memlock unlimited


공식 문서의 중간에도 swap-block 옵션이 적용되지 않는 원인에 대해 다음과 같이 권한을 언급하고 있다.

If you see that mlockall is false, then it means that the the mlockall request has failed. The most probable reason, on Linux/Unix systems, is that the user running Elasticsearch doesn’t have permission to lock memory. This can be granted by running ulimit -l unlimited as root before starting Elasticsearch.



당장 로그에서 알려준 파일로 달려가 안내해준대로 


# /etc/security/limits.conf
'user명' soft memlock unlimited
'user명' hard memlock unlimited


위의 두 줄을 추가한 후, 변수의 적용을 위해 재부팅을 한 후 다시 실행을 해보기로 한다.




굳굳!