elasticsearch4s의 tcpClient는 내부적으로 connection pool이 있지만 잘 동작이 되지 않는다.(어차피 사라질 tcp.. ㅠㅠ)


https://github.com/sksamuel/elastic4s/issues/385




오히려 새로 만든 httpClient가 잘 동작이 된다. 그러나 connection이 1개이네. 내부적으로 ES의 RestClient와 1:1 Wrapper 구조를 갖고 있다


따라서 특별히 만들어진 connection pool 클래스가 없어서 commons-pool을 구현하면 괜찮은 것 같다. 




Posted by '김용환'
,


elasticsearch client 라이브러를 실행 도중에 다음 에러가 발생했다.



ERROR StatusLogger No log4j2 configuration file found. Using default configuration: logging only errors to the console.



해결 방법은 다음 URL에 있다. 


https://www.elastic.co/guide/en/elasticsearch/client/java-api/current/_log4j_2_logger.html


다음을 pom파일에 추가하고 


<dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-core</artifactId>
    <version>2.9.1</version>
</dependency>



src/main/resource 디렉토리에 log4j2.properties을 추가한다.


appender.console.type = Console
appender.console.name = console
appender.console.layout.type = PatternLayout

rootLogger.level = info
rootLogger.appenderRef.console.ref = console


Posted by '김용환'
,

Bad neighbors/Noisy neighbors

Cloud 2017. 11. 15. 09:44



클라우드 환경에서는 

특정 물리 장비(pm)에서 동작하는 여러 vm 중 특정 vm이 자원을 많이 사용함으로서 다른 vm이 자원을 사용하지 못하는 현상을 bad neighbor 또는 noisy neighbor라고 한다.



http://searchcloudcomputing.techtarget.com/definition/noisy-neighbor-cloud-computing-performance


http://www.clubcloudcomputing.com/2012/06/bad-neighbors-in-the-cloud/




자원 독점을 qos로 막을 수 있다. 




http://events.linuxfoundation.org/sites/events/files/slides/Achieving%20QoS%20in%20Server%20Virtualization.pdf


'Cloud' 카테고리의 다른 글

NIFI 팁  (0) 2017.12.08
[nifi] tail -> cassandra 저장 예제  (0) 2017.12.01
ha_proxy 인증서 pem 파일  (0) 2017.11.10
[링크] 오픈스택 firewall  (0) 2017.11.08
우버의 스트리밍 분석 플랫폼 - AthenaX  (0) 2017.11.01
Posted by '김용환'
,

리눅스 jq 파일 예제

Tool 2017. 11. 14. 19:57



리눅스 jq 툴은 json 파싱을 잘 도와주는 툴이다.


https://stedolan.github.io/jq/





다음은 예제이다. array 구조도 잘 파싱한다.



[~/temp] cat > x.json

{

  "id": {

    "bioguide": "E000295",

    "thomas": "02283",

    "fec": [

      "S4IA00129"

    ],

    "govtrack": 412667,

    "opensecrets": "N00035483",

    "lis": "S376"

  },

  "name": {

    "first": "Joni",

    "last": "Ernst",

    "official_full": "Joni Ernst"

  },

  "bio": {

    "gender": "F",

    "birthday": "1970-07-01"

  },

  "terms": [

    {

      "type": "sen",

      "start": "2015-01-06",

      "end": "2021-01-03",

      "state": "IA",

      "class": 2,

      "state_rank": "junior",

      "party": "Republican",

      "url": "http://www.ernst.senate.gov",

      "address": "825 B&C Hart Senate Office Building Washington DC 20510",

      "office": "825 B&c Hart Senate Office Building",

      "phone": "202-224-3254"

    }

  ]

}





json 데이터 얻는 방법 


[~/temp] cat x.json | jq '.name'

{

  "first": "Joni",

  "last": "Ernst",

  "official_full": "Joni Ernst"

}

[~/temp] cat x.json | jq '.name.first'

"Joni"

[~/temp] cat x.json | jq '.terms .start'

jq: error (at <stdin>:36): Cannot index array with string "start"


[~/temp] cat x.json | jq '.terms[0] .start'

"2015-01-06"

[~/temp] cat x.json | jq '.terms[] .start'

"2015-01-06"


Posted by '김용환'
,




mysql의 innodb에서는 json과 같은 특정 컬럼으로부터 2차 인덱스를 지원한다. 


5.7.14부터이니.. 참고.





https://dev.mysql.com/doc/refman/5.7/en/create-table-secondary-indexes.html#json-column-indirect-index 예를 든다.



테스트한 버전은 mysql version은 5.7.17이다.



MySQL [mysql5]> SHOW VARIABLES LIKE "%version%";

+-------------------------+------------------------------+

| Variable_name           | Value                        |

+-------------------------+------------------------------+

| innodb_version          | 5.7.17                       |

| protocol_version        | 10                           |

| slave_type_conversions  |                              |

| tls_version             | TLSv1,TLSv1.1                |

| version                 | 5.7.17-log                   |

| version_comment         | MySQL Community Server (GPL) |

| version_compile_machine | x86_64                       |

| version_compile_os      | linux-glibc2.5               |

+-------------------------+------------------------------+

8 rows in set (0.01 sec)



테이블을 생성할 때 json컬럼의 특정 데이터를 인덱싱을 걸 수 있다. 


MySQL [mysql5]>  CREATE TABLE jemp (c JSON, g INT GENERATED ALWAYS AS (c->"$.id"), INDEX i (g));

Query OK, 0 rows affected (0.05 sec)



데이터를 추가한다 .


MySQL [mysql5]>  INSERT INTO jemp (c) VALUES

    ->  ('{"id": "1", "name": "Fred"}'), ('{"id": "2", "name": "Wilma"}'),

    ->  ('{"id": "3", "name": "Barney"}'), ('{"id": "4", "name": "Betty"}');

Query OK, 4 rows affected (0.01 sec)

Records: 4  Duplicates: 0  Warnings: 0




데이터를 검색할 수 있다.

(-->은 5.7.13부터 사용할 수 있는 키워드이다)


MySQL [mysql5]>   SELECT c->>"$.name" AS name FROM jemp WHERE g > 2;

+--------+

| name   |

+--------+

| Barney |

| Betty  |

+--------+

2 rows in set (0.01 sec)





explain으로 확인하면 인덱스가 걸려있음을 확인할 수 있다. 


MySQL [mysql5]>   EXPLAIN SELECT c->>"$.name" AS name FROM jemp WHERE g > 2;


+----+-------------+-------+------------+-------+---------------+------+---------+------+------+----------+-------------+

| id | select_type | table | partitions | type  | possible_keys | key  | key_len | ref  | rows | filtered | Extra       |

+----+-------------+-------+------------+-------+---------------+------+---------+------+------+----------+-------------+

|  1 | SIMPLE      | jemp  | NULL       | range | i             | i    | 5       | NULL |    2 |   100.00 | Using where |

+----+-------------+-------+------------+-------+---------------+------+---------+------+------+----------+-------------+

1 row in set, 1 warning (0.01 sec)




warning이 하나 있는데.. 부가 설명이 잘 되어 있다. 



MySQL [mysql5]> SHOW WARNINGS

    -> ;

+-------+------+-----------------------------------------------------------------------------------------------------------------------------------------------+

| Level | Code | Message                                                                                                                                       |

+-------+------+-----------------------------------------------------------------------------------------------------------------------------------------------+

| Note  | 1003 | /* select#1 */ select json_unquote(json_extract(`mysql5`.`jemp`.`c`,'$.name')) AS `name` from `mysql5`.`jemp` where (`mysql5`.`jemp`.`g` > 2) |

+-------+------+-----------------------------------------------------------------------------------------------------------------------------------------------+

1 row in set (0.00 sec)






Posted by '김용환'
,


Intellij에서 sbt run을 실행하다가 다음과 같은 에러를 만났다. 

잘 동작하다가 에러가 발생한 것이다.


Unexpected exception[BootException:ID: compiler-interface-bin_2.12....



indexing 또는 caching 이슈이기 때문에 삭제 후 메뉴에서 다음 메뉴를 클릭하고 재시작하면 된다.


File  |  Invalidate Caches / Restart | Just Restart



Posted by '김용환'
,

ha_proxy 인증서 pem 파일

Cloud 2017. 11. 10. 18:43



ha_proxy 인증서 파일은 하나로 합쳐서 사용한다.


인증서(crt)

체인키(chainca.crt)

개인키(key)


https://www.securesign.kr/guides/HAProxy-SSL-Certificates-Install

Posted by '김용환'
,

[git] 공커밋

etc tools 2017. 11. 10. 15:42



github 페이지가 잘 동작하다가 404 에러가 나는 경우가 있다. 

이 때는 공 커밋을 하나 날리고 push하면 된다. 


$ git commit -m 'rebuild pages' —allow-empty

$ git push




Posted by '김용환'
,


python flash 앱(oncall-bot)을 docker로 띄우려 할 때.. Dockerfile를 아래처럼 할 수 있다. 

FROM python:2.7-onbuild

EXPOSE 5000

ENTRYPOINT ["python"]
CMD ["oncall-bot.py"]



실행하는 방법은 다음과 같다. 


docker build -t oncall-bot:lastest .


docker run --rm -p 5000:5000 oncall-bot:lastest



로그도 잘 나온다. 




그러나 gunicorn을 사용할 때는 상황이 다르다. task 기반이라..



코드에 아래와 같이 handler를 추가한다. 

app = Flask(__name__)
app.logger.addHandler(logging.StreamHandler(sys.stdout))
app.logger.setLevel(logging.INFO)

함수 내에서 아래와 같이 사용한다. 

app.logger.info("-------------request.data-------------")
app.logger.info(request.data)

requirements.txt에 다음과 같이 gunicorn을 추가한다.

Flask
gunicorn
requests


Dockerfile에서는 아래와 같이 수정한다. 

FROM python:2.7-onbuild

EXPOSE 5000

CMD [ "gunicorn", "--workers", "4", "--bind", "0.0.0.0:5000", "--reload", "oncall-bot:app" ]


로그는 취합되어서 나온다. 


[~] docker logs 52a39cf13d4d

[2017-11-08 08:56:45 +0000] [1] [INFO] Starting gunicorn 19.7.1

[2017-11-08 08:56:45 +0000] [1] [INFO] Listening at: http://0.0.0.0:5000 (1)

[2017-11-08 08:56:45 +0000] [1] [INFO] Using worker: sync

[2017-11-08 08:56:45 +0000] [10] [INFO] Booting worker with pid: 10

[2017-11-08 08:56:45 +0000] [12] [INFO] Booting worker with pid: 12

[2017-11-08 08:56:45 +0000] [14] [INFO] Booting worker with pid: 14

[2017-11-08 08:56:45 +0000] [19] [INFO] Booting worker with pid: 19

-------------request.data-------------


Posted by '김용환'
,


neutron 레벨

https://wiki.openstack.org/wiki/Neutron/FWaaS


ovs 레벨

https://docs.openstack.org/newton/networking-guide/config-ovsfwdriver.html



Posted by '김용환'
,