'elasticsearch'에 해당되는 글 420건

  1. 2014.10.17 [ElasticSearch] bitset...
  2. 2014.10.02 [ElasticSearch] GC 튜닝 참고.
  3. 2014.09.02 [ElasticSearch] master node election...
  4. 2014.08.27 [ElasticSearch] Hash Partition 테스트
  5. 2014.08.26 [ElasticSearch] 자꾸 까먹어..ㅡ.ㅡ;; (preference)
  6. 2014.08.22 [ElasticSearch] start flow..
  7. 2014.08.11 [ElasticSearch] High CPU usage when idle #1940
  8. 2014.08.07 [ElasticSearch] float & double
  9. 2014.08.04 [ElasticSearch] 대용량 데이터 색인 시 optimize 튜닝 관점
  10. 2014.08.04 [ElasticSearch] Refresh/Flush/Optimize - by elasticsearch.org

[ElasticSearch] bitset...

Elastic/Elasticsearch 2014. 10. 17. 18:25

내 블로그에 안남기고 페북에만 남겼내..ㅋㅋ


그냥 지나가다가...

질의 성능 최적화에서 queries vs filters 에 대해 이해하고 사용하고 계실줄로 압니다만, ^^;

요기에 추가로 bitset 에 대해서도 내용이 나오기 때문에 그냥 참고하시라고 링크 던져 봅니다. ^^

filter 가 빠르다라고 이야기 하는 부분에서 bitset에 대한 이해가 없으면 안될것 같아서요.

https://lucene.apache.org/core/4_10_1/core/org/apache/lucene/util/OpenBitSet.html

쉽게는 term filter 했을 떄 match 된 term 에 대해서 bitset 을 1로 marking 해 두어 다음에 이 bitset 만 보고 문서를 리턴하게 된다 뭐 그런 이야기 입니다.


:

[ElasticSearch] GC 튜닝 참고.

Elastic/Elasticsearch 2014. 10. 2. 11:32

gc 관련 문의주신 분이 계셔서 공유해 드리기로 약속했습니다.

그래서 공유 합니다.


우선, gc 옵션 값은 정답이 정해져 있는게 아닙니다.

지속적으로 관리를 해주셔야 합니다.


elasticsearch 에서 gc 관련 영향을 미치는 것들은 주로 아래 내용들에 대해서 살펴 보셔야 합니다.

- segment merge policy

- 검색 질의에 대한 유형 및 데이터 크기

- field, filter 관련 cache 관리

- facet, aggregation에 대한 유형 및 데이터 크기

- jdk 7 이상 사용

- 등등등..


제가 주로 사용하는 gc 옵션 값은 아래와 같습니다.

(그러고 보니 이것도 예전에 공유드렸던 것 같습니다.)

-server

-XX:+AggressiveOpts

-XX:UseCompressedOops

-XX:MaxDirectMemorySize

-XX:+UseParNewGC

-XX:+UseConcMarkSweepG

-XX:+CMSParallelRemarkEnabled

-XX:CMSInitiatingOccupancyFraction=75

-XX:+UseCMSInitiatingOccupancyOnly

-XX:+UseG1GC


JDK 7 부터는 default G1 gc를 사용하는 것으로 알고 있습니다.

※ http://www.oracle.com/technetwork/java/javase/tech/g1-intro-jsp-135488.html


아시겠지만, 1.2.0 이상 부터는 무조건 JDK 7 버전을 사용해야 합니다.


gc 튜닝은 단순 JVM 설정만으로 다 해결 되는 문제는 아닙니다.

client application에서도 문제가 발생 되지 않도록 구현을 해야 하는 것도 중요합니다.

단순 예를 들면, elasticsearch node 에 설정한 memory 보다 큰 사이즈의 데이터를 요청해서 분석하는 경우 이건 그냥  OOM 갑니다.

더 심각하게는 node 가 죽을 수도 있구요.


아래 링크들은 gc 관련 링크 입니다. (예전에 찾아 봤던 링크들 입니다.)

https://gist.github.com/mrflip/5366376

http://jprante.github.io/2012/11/28/Elasticsearch-Java-Virtual-Machine-settings-explained.html

https://www.found.no/foundation/elasticsearch-in-production/

http://helloworld.naver.com/helloworld/1329

http://eediom.com/logpresso-cli-araqne-core/

http://dimdim.tistory.com/entry/Java-GC-%ED%83%80%EC%9E%85-%EB%B0%8F-%EC%84%A4%EC%A0%95-%EC%A0%95%EB%B3%B4-%EC%A0%95%EB%A6%AC

http://wiki.ex-em.com/index.php/JVM_Options

:

[ElasticSearch] master node election...

Elastic/Elasticsearch 2014. 9. 2. 11:00

그냥 또 까먹을까봐.. 대충 적어 봅니다.


기본적으로 zen discovery 를 통해서 cluster 구성 및 node 간 통신을 위해서 사용이 됩니다.

그럼 master node  가 죽었을 때 어떻게 선출이 될까요?


es 가 실행 되면서 zen discovery module 도 등록이 됩니다.

ZenDiscovery 가 binding 되면서 MasterFaultDetection 과 ElectMasterService 도 등록이 되지요.

MasterFaultDetection 에서 master node 를 감시하다가 에러가 나면 ElectMasterService 에서 master node 를 선출하게 되는 구조가 되는 것입니다.


참 쉽죠 ^^;


ZenDiscovery 에서 하는 역할은 더 있지만 여기서는 그냥 단순 master election 에 대해서만 살펴 봤습니다.


ZenDiscovery

        

MasterFaultDetection

        

ElectMasterService



:

[ElasticSearch] Hash Partition 테스트

Elastic/Elasticsearch 2014. 8. 27. 14:15

간혹 특정 shard 로 색인 문서가 몰리는 경우가 있습니다.

이럴경우 _id 값에 대한 key 조합을 확인해야 할 필요가 있는데요.

es 내부에서 사용하는 hash 함수를 이용해서 간단하게 테스트 해볼수 있습니다.


[테스트 코드]

public class EsHashPartitionTest {

    private static final Logger log = LoggerFactory.getLogger(EsHashPartitionTest.class);

    private HashFunction hashFunction = new DjbHashFunction();

    


    @Test

    public void testHashPartition() {

        int shardSize = 120;

        List<Long> shards = new ArrayList<Long>();

        long[] partSize = new long[shardSize];

        

        for ( int i=0; i<shardSize; i++ ) {

            shards.add((long) 0);

            partSize[i] = 0;

        }

        

        for ( int i=0; i<1000000; i++ ) {

            int shardId = MathUtils.mod(hash(String.valueOf(i)), shardSize);

            shards.add(shardId, (long) ++partSize[shardId]);

        }

        

        for ( int i=0; i<shardSize; i++ ) {

            log.debug("["+i+"] {}", partSize[i]);

        }

    }

    

    public int hash(String routing) {

        return hashFunction.hash(routing);

    }

}


[Hash 함수 원본 코드]

/**

 * This class implements the efficient hash function

 * developed by <i>Daniel J. Bernstein</i>.

 */

public class DjbHashFunction implements HashFunction {


    public static int DJB_HASH(String value) {

        long hash = 5381;


        for (int i = 0; i < value.length(); i++) {

            hash = ((hash << 5) + hash) + value.charAt(i);

        }


        return (int) hash;

    }


    public static int DJB_HASH(byte[] value, int offset, int length) {

        long hash = 5381;


        final int end = offset + length;

        for (int i = offset; i < end; i++) {

            hash = ((hash << 5) + hash) + value[i];

        }


        return (int) hash;

    }


    @Override

    public int hash(String routing) {

        return DJB_HASH(routing);

    }


    @Override

    public int hash(String type, String id) {

        long hash = 5381;


        for (int i = 0; i < type.length(); i++) {

            hash = ((hash << 5) + hash) + type.charAt(i);

        }


        for (int i = 0; i < id.length(); i++) {

            hash = ((hash << 5) + hash) + id.charAt(i);

        }


        return (int) hash;

    }

}

- https://github.com/elasticsearch/elasticsearch/tree/master/src/main/java/org/elasticsearch/cluster/routing/operation/hash


이와 관련된 자세한 내용은 아래 링크 참고하세요.

http://www.elasticsearch.org/guide/en/elasticsearch/guide/current/routing-value.html

:

[ElasticSearch] 자꾸 까먹어..ㅡ.ㅡ;; (preference)

Elastic/Elasticsearch 2014. 8. 26. 14:26


http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-request-preference.html


preference

Controls a preference of which shard replicas to execute the search request on. By default, the operation is randomized between the shard replicas.

The preference is a query string parameter which can be set to:

_primary

The operation will go and be executed only on the primary
 shards.

_primary_first

The operation will go and be executed on the primary shard,
and if not available (failover), will execute on other shards.

_local

The operation will prefer to be executed on a local allocated
shard if possible.

_only_node:xyz

Restricts the search to execute only on a node with the
provided node id (xyz in this case).

_prefer_node:xyz

Prefers execution on the node with the provided node id
(xyz in this case) if applicable.

_shards:2,3

Restricts the operation to the specified shards. (2 and 3 
in this case). This preference can be combined
with other preferences but it has to appear first: _shards:2,3;_primary

Custom (string) value

A custom value will be used to guarantee that
the same shards will be used for the same custom value.
This can help with "jumping values" when hitting different
shards in different refresh states. A sample value can be
something like the web session id, or the user name.


:

[ElasticSearch] start flow..

Elastic/Elasticsearch 2014. 8. 22. 12:34

ElasticSearch 를 실행 하게 되면 아래와 같은 flow 로 실행이 됩니다.


Elasticsearch

      |

      V

Bootstrap

      |

      V

NodeBuilder

      |

      V

InternalNode


실제 node 의 실행은 InternalNode 의 start() 에서 이루어 집니다.

여기서 필요한 service 와 module 등록하고 실행 되는 것입니다.

:

[ElasticSearch] High CPU usage when idle #1940

Elastic/Elasticsearch 2014. 8. 11. 10:26

https://github.com/elasticsearch/elasticsearch/issues/1940

:

[ElasticSearch] float & double

Elastic/Elasticsearch 2014. 8. 7. 10:38

별건 아니구요..

1.0 은 실수 입니다.
그렇죠!

그럼 이게 float 일까요? double 일까요?
이런 멍청한 짓을 어제 했었습니다. ㅡ.ㅡ;;

ES 에 float 으로 정의해 놓고 데이터를 1.0 으로 넣었습니다.
그냥 ES 에서는 제대로 리턴해 주는데 이걸 JDBC ResultSet 에서 type 검사를 해서 넘겨주려고 하다보니 이게 double 로 나와서 type mismatch 로 인한 로직 오류를 범했내요.

바닥 공사가 부실해서 큰일 입니다.
이러다 싱크홀 생기면 큰일인데....

그래서 저는 그냥 double 을 사용하기로 결심했습니다. :)

:

[ElasticSearch] 대용량 데이터 색인 시 optimize 튜닝 관점

Elastic/Elasticsearch 2014. 8. 4. 18:04

elasticsearch.org 에 the definitive guide 에 좋은 내용이 있어 공유 합니다.

최근에 제가 대용량 데이터를 색인 하면서 사용한 방법 이기도 합니다.


아래 링크가 원문 입니다.

http://www.elasticsearch.org/guide/en/elasticsearch/guide/current/inside-a-shard.html


제일 중요한 부분은 장비스펙과 데이터 크기에 따른 shard sizing 입니다.

이건 추후 공유 드리기로 하구요. ^^;


원문 대비 제가 활용한 방법에 대해서 간단하게 정리 하도록 하겠습니다.


[한 줄 정리]

- optimize 대신  refresh 와  flush 를 이용한다.


※ optimize 실행은 가급적 대용량 데이터 색인 및 실시간 색인에서는 사용을 피하는 것이 좋습니다.

- 글에도 있지만 대용량 데이터 색인 시 I/O 자원과 CPU 자원을 많이 사용합니다.

The merging of big segments can use a lot of I/O and CPU, which can hurt search performance if left unchecked. By default, Elasticsearch throttles the merge process so that search still has enough resources available to perform well.



Be aware that merges triggered by the optimize API are not throttled at all. They can consume all of the I/O on your nodes, leaving nothing for search and potentially making your cluster unresponsive. If you plan on optimizing an index, you should use shard allocation (see Appendix A, TODO) to first move the index to a node where it is safe to run.


이런 이유로 저는 대용량 데이터 색인 및 검색을 위해서 optimize 를 수행하지 않고 refresh 와 flush 를 조합해서 bulk request 를 수행 하도록 했습니다.
(거의 색인 시간 만큼 optimize 수행을 하다 보니 시스템 리소스를 효율적으로 사용하는데 제한이 있었습니다.)

[Bulk Request Flow]
Step 1. update settings
refresh_interval disable (-1)
replica disable (0)
Step 2. bulk request
Step 3. flush & refresh
Step 4. update settings
refresh_interval rollback
replica rollback
- 여기서 step 4 에서 replica rollback 부분은 서비스중에 돌리기 어려울 경우 별도 scheduling 을 통해서 rollback 해줘도 됩니다.
- 다만, 장애 발생 시 서비스에 심각한 문제가 되는 경우라면 바로 설정을 적용해 주어야 합니다.


[Bulk Request Size]

원문) http://www.elasticsearch.org/guide/en/elasticsearch/guide/current/bulk.html

how big is too big?edit

The entire bulk request needs to be loaded into memory by the node which receives our request, so the bigger the request, the less memory available for other requests. There is an optimal size of bulk request. Above that size, performance no longer improves and may even drop off.

The optimal size, however, is not a fixed number. It depends entirely on your hardware, your document size and complexity, and your indexing and search load. Fortunately, it is easy to find this sweetspot:

Try indexing typical documents in batches of increasing size. When performance starts to drop off, your batch size is too big. A good place to start is with batches of between 1,000 and 5,000 documents or, if your documents are very large, with even smaller batches.

It is often useful to keep an eye on the physical size of your bulk requests. One thousand 1kB documents is very different than one thousand 1MB documents. A good bulk size to start playing with is around 5-15MB in size.


:

[ElasticSearch] Refresh/Flush/Optimize - by elasticsearch.org

Elastic/Elasticsearch 2014. 8. 4. 17:48

원본) http://www.elasticsearch.org/guide/en/elasticsearch/guide/current/inside-a-shard.html


1. near real-time search

refresh apiedit

In Elasticsearch, this lightweight process of writing and opening a new segment is called a refresh. By default, every shard is refreshed automatically once every second. This is why we say that Elasticsearch has near real-time search: document changes are not visible to search immediately, but will become visible within one second.


2. making changes persistent

flush apiedit

The action of performing a commit and truncating the translog is known in Elasticsearch as a flush. Shards are flushed automatically every 30 minutes, or when the translog becomes too big. See thetranslog documentation for settings that can be used to control these thresholds.


3. segment merging 

optimize apiedit

The optimize API is best described as the forced merge API. It forces a shard to be merged down to the number of segments specified in the max_num_segments parameter. The intention is to reduce the number of segments (usually to 1) in order to speed up search performance.



: