'2019/10'에 해당되는 글 6건

  1. 2019.10.23 [Elasticsearch] Cache 에 대해 알아 봅시다.
  2. 2019.10.17 [Elasticsearch] 앱 내 사용자 행동로그 수집 파이프라인 구성
  3. 2019.10.17 [Elasticsearch] minimum_master_nodes is not working.
  4. 2019.10.10 [Reference] How to do in java
  5. 2019.10.08 [Spring] Disable Spring Data Auto Configuration
  6. 2019.10.02 [Elasticsearch] Elasticsearch Cluster Auto Scaling 구성 하기.

[Elasticsearch] Cache 에 대해 알아 봅시다.

Elastic/Elasticsearch 2019. 10. 23. 09:58

저는 기본적으로 API 단에서 Elasticsearch 로 질의한 결과를 Cache 하도록 구현해서 사용하고 있습니다.

하지만 Elasticsearch 에서도 기본적으로 두 가지의 Cache 기능을 제공 하고 있으니 잘 활용 하시면 좋을 것 같아 기록해 봅니다.

 

한 줄로 정리 하면)

검색 결과 리스팅은 Query Cache에, 검색 결과에 대한 집계 는 Request Cache 에 저장 된다고 이해 하시면 됩니다.

 

1. Node Query Cache

공식문서)

https://www.elastic.co/guide/en/elasticsearch/reference/current/query-cache.html

- 이 기능은 Query 에 따른 결과를 Cache하게 되며, LRU 정책으로 동작 합니다.

- 이 기능은 Node 레벨로 동작 합니다.

- 이 기능은 Filter Context 를 사용 했을 경우에만 동작 합니다.

 

- 아래 설정은 Cluster 내 모든 Data Node 에 설정을 반드시 해야 합니다.

indices.queries.cache.size

 

- 아래 설정은 Index 별로 설정을 해야 합니다.
index.queries.cache.enabled

 

2. Shard Request Cache

공식문서)

https://www.elastic.co/guide/en/elasticsearch/reference/current/shard-request-cache.html

- 이 기능은 개별 Local Shard 의 결과를 Cache 합니다.

- 이 기능은 size=0 인 Request 의 결과만 Cache 합니다.

- 즉, Aggregations 와 Suggestions 결과를 Cache 하게 되며, hits 결과는 Cache 하지 않지만 hits.total 은 Cache 합니다.

- Date Range 또는 Histogram 질의 시 now 를 사용하게 되면 Cache 하지 않습니다.

 

- 이 기능은 Index 레벨로 설정을 합니다.

PUT /my_index
{
  "settings": {
    "index.requests.cache.enable": true
  }
}

 

- 아래 설정은 Node 레벨로 설정을 하는 것입니다.

indices.requests.cache.size

 

- 아래 설정은 Cache TTL 설정을 하는 것입니다. 

indices.requests.cache.expire

 

Code Sniff)

// IndicesRequestCache.java
    /**
     * A setting to enable or disable request caching on an index level. Its dynamic by default
     * since we are checking on the cluster state IndexMetaData always.
     */
    public static final Setting<Boolean> INDEX_CACHE_REQUEST_ENABLED_SETTING =
        Setting.boolSetting("index.requests.cache.enable", true, Property.Dynamic, Property.IndexScope);
    public static final Setting<ByteSizeValue> INDICES_CACHE_QUERY_SIZE =
        Setting.memorySizeSetting("indices.requests.cache.size", "1%", Property.NodeScope);
    public static final Setting<TimeValue> INDICES_CACHE_QUERY_EXPIRE =
        Setting.positiveTimeSetting("indices.requests.cache.expire", new TimeValue(0), Property.NodeScope);
        
// TimeValue.java        
   public static TimeValue parseTimeValue(String sValue, TimeValue defaultValue, String settingName) {
        settingName = Objects.requireNonNull(settingName);
        if (sValue == null) {
            return defaultValue;
        }
        final String normalized = sValue.toLowerCase(Locale.ROOT).trim();
        if (normalized.endsWith("nanos")) {
            return new TimeValue(parse(sValue, normalized, "nanos"), TimeUnit.NANOSECONDS);
        } else if (normalized.endsWith("micros")) {
            return new TimeValue(parse(sValue, normalized, "micros"), TimeUnit.MICROSECONDS);
        } else if (normalized.endsWith("ms")) {
            return new TimeValue(parse(sValue, normalized, "ms"), TimeUnit.MILLISECONDS);
        } else if (normalized.endsWith("s")) {
            return new TimeValue(parse(sValue, normalized, "s"), TimeUnit.SECONDS);
        } else if (sValue.endsWith("m")) {
            // parsing minutes should be case-sensitive as 'M' means "months", not "minutes"; this is the only special case.
            return new TimeValue(parse(sValue, normalized, "m"), TimeUnit.MINUTES);
        } else if (normalized.endsWith("h")) {
            return new TimeValue(parse(sValue, normalized, "h"), TimeUnit.HOURS);
        } else if (normalized.endsWith("d")) {
            return new TimeValue(parse(sValue, normalized, "d"), TimeUnit.DAYS);
        } else if (normalized.matches("-0*1")) {
            return TimeValue.MINUS_ONE;
        } else if (normalized.matches("0+")) {
            return TimeValue.ZERO;
        } else {
            // Missing units:
            throw new IllegalArgumentException("failed to parse setting [" + settingName + "] with value [" + sValue +
                    "] as a time value: unit is missing or unrecognized");
        }
    }        

 

각 설정 값들에 대한 최적화는

- 장비 스펙

- 질의 특성

- 문서 크기

등에 맞춰서 구성을 하셔야 합니다.

잘 모를 경우는 그냥 Elasticsearch 의 default 값을 사용하시면서 최적값을 찾으셔야 합니다.

 

Monitoring Cache Usage)

공식문서)

https://www.elastic.co/guide/en/elasticsearch/reference/current/cluster-stats.html

https://www.elastic.co/guide/en/elasticsearch/reference/current/cluster-nodes-stats.html

https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-stats.html

GET /_stats/request_cache?human
GET /_nodes/stats/indices/request_cache?human

 

함께 알아 두면 좋은것)

https://www.elastic.co/guide/en/elasticsearch/reference/current/fielddata.html

https://www.elastic.co/guide/en/elasticsearch/reference/current/doc-values.html

https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-store.html

 

:

[Elasticsearch] 앱 내 사용자 행동로그 수집 파이프라인 구성

Elastic/Elasticsearch 2019. 10. 17. 15:13

사용하고자 하는 Software Stack 은 다양하게 많이 있습니다.

일반적으로 아래 파이프라인으로 많이들 구성 합니다.

 

1. App -> Stream service -> Consumer -> Elasticsearch
2. App -> Stream service -> Producer -> Queue -> Consumer -> Elasticsearch
3. App -> Logging service (daemon, http, file ...) -> Consumer -> Elasticsearch
4. App -> Logging service (daemon, http, file ...) -> Producer -> Queue -> Consumer -> Elasticsearch

 

이걸 다시 Elastic Stack 으로 변환 하면

 

Producer 는)

- Filebeat

- Logstash

 

Queue 는)

- Logstash persistent queue

 

Consumer 는)

- Logstash

 

이 외에도 sqs, dynamodb, redis, kafka, fluentd, storm 등 활용 가능한 오픈소스들이 많이 준비되어 있습니다.

 

가장 쉽고 일반적인 구성이라고 보시면 될 것 같습니다.

:

[Elasticsearch] minimum_master_nodes is not working.

Elastic/Elasticsearch 2019. 10. 17. 14:56

7.x breaking changes 에 올라가 있는 내용입니다.

기억력을 돕는 차원에서 기록합니다.

 

The discovery.zen.minimum_master_nodes setting is permitted, but ignored, on 7.x nodes.

 

해당 설정은 더 이상 사용하지 맙시다.

그리고 이제 master node 는 2개로 구성해서는 더 이상 위험해서 못쓰겠내요.

 

참고문서)

https://www.elastic.co/guide/en/elasticsearch/reference/current/breaking-changes-7.0.html#breaking_70_discovery_changes

 

Breaking changes in 7.0 | Elasticsearch Reference [7.4] | Elastic

Reindex indices from Elasticsearch 5.x or before Indices created in Elasticsearch 5.x or before will need to be reindexed with Elasticsearch 6.x in order to be readable by Elasticsearch 7.x.

www.elastic.co

 

:

[Reference] How to do in java

ITWeb/스크랩 2019. 10. 10. 13:04

우연히 Spring Batch 관련 자료를 찾다가 얻어 걸린 사이트 입니다.

그냥 한번 따라만 해봤는데, 정리도 잘 되어 있고 코드도 잘 동작 해서 링크 걸어 봤습니다.

 

https://howtodoinjava.com/

 

Java Tutorials - Java Learning Resources - HowToDoInJava

Simple and easy to follow free Java tutorials on spring framework, spring boot, angular, maven, hibernate, jpa, concurrency, collections and much more.

howtodoinjava.com

그럼에도 불구 하고 모든 예제들은 기본적으로 Spring 에 대한 또는 Java 에 대한 이해를 하고 있어야 문제 없이 따라 할 수 있습니다.

 

만약 실행이 안된다면 그건 당신의 실력이 부족해서 입니다.

:

[Spring] Disable Spring Data Auto Configuration

ITWeb/개발일반 2019. 10. 8. 09:53

단순 Spring Batch Job, Step, Reader, Processor, Writer 테스트만 하려고 하다 아래와 같은 에러가 발생을 해서 그냥 disable 하고 테스트 했습니다.

 

[Error Message]

***************************
APPLICATION FAILED TO START
***************************

Description:

Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.

Reason: Failed to determine a suitable driver class


Action:

Consider the following:
If you want an embedded database (H2, HSQL or Derby), please put it on the classpath.
If you have database settings to be loaded from a particular profile you may need to activate it (no profiles are currently active).

 

[application.properties]

spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration, \

org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration, \

org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration

:

[Elasticsearch] Elasticsearch Cluster Auto Scaling 구성 하기.

Elastic/Elasticsearch 2019. 10. 2. 16:04

기억하기 위해 작성해 봅니다.

 

ES Cluster 를 아래와 같이 구성 한다고 가정 하고 들어 가겠습니다.

 

1. Master Node 2개

2. Coordinating Node 2개

3. Data Node 2개

 

ES Cluster 를 구성 하다 보면 CPU, MEM, DISK, NETWORK 등 모든 자원을 다 효율적으로 사용하도록 구성 하기는 매우 어렵습니다.

그렇다 보니 CPU 는 부족한데 MEM 은 남는 다던가 MEM 은 부족한데 CPU 는 남는 다던가 또는 가끔 말도 안되게 NETWORK Bandwidth 가 부족 할 때도 나오더군요.

 

암튼 그래서 모든 자원을 다 쥐어 짜듯이 구성 할 수 없으니 적당히 포기 하시길 권장 드립니다.

 

여기서 Auto Scaling 하는 구성은 Coordinating Node 와 Data node 이 두 가지 입니다.

 

우선 ES 는 너무 쉽게 Node 를 추가 하고 삭제 할 수 있습니다.

elasticsearch.yml 파일 내 Master Node 정보만 등록 해 두시면 됩니다.

 

- discovery.zen.ping.unicast.hosts: MASTER_NODE_LIST

 

설정 공식 문서는 아래 링크 참고 하세요.

https://www.elastic.co/guide/en/elasticsearch/reference/6.2/modules-discovery-zen.html

 

Zen Discovery | Elasticsearch Reference [6.2] | Elastic

The zen discovery is the built in discovery module for Elasticsearch and the default. It provides unicast discovery, but can be extended to support cloud environments and other forms of discovery. The zen discovery is integrated with other modules, for exa

www.elastic.co

 

Coordinating Node Auto Scaling  구성 하기)

0. 가장 먼저 하셔야 하는 작업은 elasticsearch.yml 파일 내 Master Node 정보 등록 입니다.

1. 우선 Coordinating Node 들을 LoadBalancer 로 묶습니다. (AWS 를 사용 하시면 ALB/ELB 로 구성 하시면 됩니다.)

    - Coordinating Node 의 경우 "Too many requests" 오류가 발생 할 경우 이를 예방 하기 위해 Auto Scaling 구성을 하면 좋습니다.

    - 보통 트래픽이 몰릴 경우 search thread 가 부족 할 수 있기 때문 입니다.

    - LB 로 묶는 또 다른 이유는 API 단에서 단일 Endpoint 를 바라 보게 해서 운영을 편하게 하기 위함 입니다.

2. Auto Scaling 설정 구성을 합니다.

    - 이 부분은 사용하시는 환경에 맞춰서 구성 하시면 됩니다.

    - 공식 문서를 참고 하시면 됩니다.

    - https://docs.aws.amazon.com/ko_kr/autoscaling/ec2/userguide/scaling_plan.html#scaling_typesof

 

Auto Scaling 그룹의 크기 조정 - Amazon EC2 Auto Scaling

Auto Scaling 그룹의 크기 조정 조정은 애플리케이션의 컴퓨팅 용량을 늘리거나 줄이는 기능입니다. 조정은 이벤트와 함께 시작되거나 Auto Scaling 그룹에 Amazon EC2 인스턴스를 시작 또는 종료하도록 지시하는 조정 작업과 함께 시작됩니다. Amazon EC2 Auto Scaling에서는 여러 가지 방법으로 애플리케이션의 요구 사항에 가장 적합하게 조정 기능을 조절할 수 있습니다. 그러므로 애플리케이션을 충분히 이해하는 것이 중요합니다.

docs.aws.amazon.com

3. 테스트 해보시고 서비스에 적용 하시면 됩니다.

 

 

Data Node Auto Scaling 구성 하기) 

0. 가장 먼저 하셔야 하는 작업은 elasticsearch.yml 파일 내 Master Node 정보 등록 입니다.

0. 더불어 Replica Shard 설정은 (Data Node - 1) 만큼 구성이 되어야 합니다.

0. 더불어 초기 Data Node 수와 Primary Shard 크기를 잘 정의 하셔야 합니다.

0. 이유는 Primary Shard 는 한번 생성 하게 되면 ReIndexing 을 하지 않고서는 변경이 불가능 합니다.

1. Auto Scaling 설정 구성을 합니다.

    - 이 설정 시 Shard reallocation 에 대한 이슈는 없는지 꼭 확인을 하셔야 합니다.

    - CPU, DISk I/O, NETWORK 등에 대한 성능 저하가 발생 할 수 있습니다.

 

1. Auto Scaling 설정 후 수동으로 Shard Allocation 이 가능 합니다.

    - 보통 이런 문제는 트래픽이 몰리거나 운영 시점에 발생을 하기 때문에 미리 스크립트 구성해 놓으시고 re-location  진행 하시면 됩니다.

    - 그래서 Shard Allocation 설정을 꺼 두셔야 합니다.

    - 공식 문서를 참고 하시면 됩니다.

    - https://www.elastic.co/guide/en/elasticsearch/reference/current/shards-allocation.html

 

Cluster level shard allocation | Elasticsearch Reference [7.4] | Elastic

Regardless of the result of the balancing algorithm, rebalancing might not be allowed due to forced awareness or allocation filtering.

www.elastic.co

2. Data Node 의 경우 Auto Scaling 종료 정책에 따라 Primary Shard 가 유실 되지 않도록 구성 하는 것이 좋습니다.

    - 물론 Full Replicaiton 구성이라 다른 Replica 가 Primary Shard 로 선출 되겠지만 그래도 주의 하는게 좋겠죠.

 

마무리를 하면)

Coordinating Node 까지는 쉽게 적용이 가능 합니다.

하지만, Data Node 적용은 실제 운영 경험이 있고 문제 발생 시 신속하게 대응이 가능 하지 않다면 시도 하지 마시라고 말씀 드리고 싶습니다.

: