소스 트리에서 다음과 같은 에러가 계속 난다.. 


remote: Invalid username or password. fatal: Authentication failed


아마도 예전에 저장한 패스워드에 문제가 있었나 보다.



아래 설정을 진행하니 문제가 없다.



Sourcetree > Preferences > Git > Use System Git




Posted by '김용환'
,


스파크 MLlib은 K-평균, 이분법 K-평균, 가우스 혼합 외에 PIC, LDA, 스트리밍 K-평균과 같은 세 개의 클러스터링 알고리즘의 구현을 제공한다. 


한 가지 분명한 것은 클러스터링 분석을 미세하게 튜닝하려면 종종 비정상 데이터(outlier 또는  anomaly)이라고 불리는 원치 않는 데이터 오브젝트를 제거해야 한다.


스파크 MLlib으로 비정상 데이터를 찾는데 공부하기 위한 좋은 자료


https://github.com/keiraqz/anomaly-detection


https://mapr.com/ebooks/spark/08-unsupervised-anomaly-detection-apache-spark.html




Posted by '김용환'
,


간단한 스파크 잡 실행하기 예제는 다음과 같다. 



# 8코어에서 독립 실행 형 모드로 애플리케이션을 실행한다

SPARK_HOME/bin/spark-submit \  

--class org.apache.spark.examples.Demo \  

--master local[8] \  

Demo-0.1-SNAPSHOT-jar-with-dependencies.jar


# YARN 클러스터에서 실행한다

export HADOOP_CONF_DIR=XXX

SPARK_HOME/bin/spark-submit \  

--class org.apache.spark.examples.Demo \  

--master yarn \  

--deploy-mode cluster \  # 클러스터 모드로 클라이언트가 될 수 있다

--executor-memory 20G \  

--num-executors 50 \  

Demo-0.1-SNAPSHOT-jar-with-dependencies.jar


# supervise 플래그를 포함해 클러스터 배포 모드의 메소스(Mesos) 클러스터에서 실행한다

SPARK_HOME/bin/spark-submit \

--class org.apache.spark.examples.Demo \

--master mesos://207.184.161.138:7077 \ # IP 주소를 사용한다

--deploy-mode cluster \  

--supervise \  

--executor-memory 20G \  

--total-executor-cores 100 \  

Demo-0.1-SNAPSHOT-jar-with-dependencies.jar



supervise는 스탠드 얼론 모드에서 0이외의 값을 리턴, 비정상적인 종료일 때는 다시 실행하라는 의미를 가진다.






예제

https://spark.apache.org/docs/2.1.1/submitting-applications.html


# Run application locally on 8 cores
./bin/spark-submit \
  --class org.apache.spark.examples.SparkPi \
  --master local[8] \
  /path/to/examples.jar \
  100

# Run on a Spark standalone cluster in client deploy mode
./bin/spark-submit \
  --class org.apache.spark.examples.SparkPi \
  --master spark://207.184.161.138:7077 \
  --executor-memory 20G \
  --total-executor-cores 100 \
  /path/to/examples.jar \
  1000

# Run on a Spark standalone cluster in cluster deploy mode with supervise
./bin/spark-submit \
  --class org.apache.spark.examples.SparkPi \
  --master spark://207.184.161.138:7077 \
  --deploy-mode cluster \
  --supervise \
  --executor-memory 20G \
  --total-executor-cores 100 \
  /path/to/examples.jar \
  1000

# Run on a YARN cluster
export HADOOP_CONF_DIR=XXX
./bin/spark-submit \
  --class org.apache.spark.examples.SparkPi \
  --master yarn \
  --deploy-mode cluster \  # can be client for client mode
  --executor-memory 20G \
  --num-executors 50 \
  /path/to/examples.jar \
  1000

# Run a Python application on a Spark standalone cluster
./bin/spark-submit \
  --master spark://207.184.161.138:7077 \
  examples/src/main/python/pi.py \
  1000

# Run on a Mesos cluster in cluster deploy mode with supervise
./bin/spark-submit \
  --class org.apache.spark.examples.SparkPi \
  --master mesos://207.184.161.138:7077 \
  --deploy-mode cluster \
  --supervise \
  --executor-memory 20G \
  --total-executor-cores 100 \
  http://path/to/examples.jar \
  1000


Posted by '김용환'
,



opentsdb의 hbase 스키마는 다음 url에서 확인할 수 있다.

특이한 점은 데이터는 역순(증분)으로 되어 있고 마지막 uid 정보를 0x00에 저장한다는 점이다. 

따라서 scanning할 때 무척 편하게 할 수 있다. 


http://opentsdb.net/docs/build/html/user_guide/backends/hbase.html


UID Table Schema

A separate, smaller table called tsdb-uid stores UID mappings, both forward and reverse. Two columns exist, one named name that maps a UID to a string and another id mapping strings to UIDs. Each row in the column family will have at least one of three columns with mapping values. The standard column qualifiers are:

  • metrics for mapping metric names to UIDs
  • tagk for mapping tag names to UIDs
  • tagv for mapping tag values to UIDs.

The name family may also contain additional meta-data columns if configured.

id Column Family

Row Key - This will be the string assigned to the UID. E.g. for a metric we may have a value of sys.cpu.user or for a tag value it may be 42.

Column Qualifiers - One of the standard column types above.

Column Value - An unsigned integer encoded on 3 bytes by default reflecting the UID assigned to the string for the column type. If the UID length has been changed in the source code, the width may vary.

name Column Family

Row Key - The unsigned integer UID encoded on 3 bytes by default. If the UID length has been changed in the source code, the width may be different.

Column Qualifiers - One of the standard column types above OR one of metrics_metatagk_meta or tagv_meta.

Column Value - For the standard qualifiers above, the string assigned to the UID. For a *_meta column, the value will be a UTF-8 encoded, JSON formatted UIDMeta Object as a string. Do not modify the column value outside of OpenTSDB. The order of the fields is important, affecting CAS calls.

UID Assignment Row

Within the id column family is a row with a single byte key of \x00. This is the UID row that is incremented for the proper column type (metrics, tagk or tagv) when a new UID is assigned. The column values are 8 byte signed integers and reflect the maximum UID assigned for each type. On assignment, OpenTSDB calls HBase's atomic increment command on the proper column to fetch a new UID.


Posted by '김용환'
,



Kafka에 zookeeper를 사용할 때. zookeeper 기본 설정 사용하다가 주키퍼에서 메모리 부족하고 난리도 아니다.


메모리 설정과 jmx 설정을 해주는 것이 좋다.




conf/java.env파일을 추가해 메모리 설정도 gc 로그 파일을 생성한다. 아래는 대략 기본 설정으로 보는게 좋다.


export JVMFLAGS="-Xmx3g -Xms3g -XX:+UseG1GC -XX:MaxGCPauseMillis=200 -XX:CompileThreshold=200 -verbosegc -XX:+PrintGCDetails -XX:+PrintGCDateStamps -Xloggc:/var/lib/zookeeper/gc.log -XX:+UseGCLogFileRotation -XX:GCLogFileSize=10m -XX:NumberOfGCLogFiles=10"



zkServer.sh에 다음을 추가해 jmx 모니터링을 진행한다.


-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.port=8989 -Djava.rmi.server.hostname=my.remoteconsole.org





Posted by '김용환'
,


Jetbrains에서 query editor를 사용하려면.


File -> New -> Console을 이용한다.


아니면.


Database -> + -> console을 이용한다.





Posted by '김용환'
,



https://www.slideshare.net/dgomezg/parallel-streams-en-java-8


Parallel streams in java 8 from David Gómez García
Posted by '김용환'
,


flask의 테스트 코드를 실행할 때 사용되는 툴은 다음과 같다.


$ tox -e flake8,py27



tox는 표준 툴이다.

https://tox.readthedocs.io/en/latest/




pyenv를 사용하고 있다면 다음과 같이 설치후 사용할 수 있다.


pip install -r requirements.txt -i http://proxy.google.com/pypi/simple/ --trusted-host proxy.google.com

~/.pyenv/shims/tox -e flake8,py27


Posted by '김용환'
,


아래와 같이 select의 컬럼과 from의 테이블이 서로 다르다.(사실 이게 되기도 한다)


SELECT distinct kibanaauth_esidx.esidx

FROM kibanaauth_role role



이전 쿼리는 kibanaauth_role와 kibanaauth_esidx가 다르기 때문에 조인을 할 수 없다.


sql_alchemy의 query()를 join()과 함께 쓸 때는 

내부적으로 SQL의 select와 from 뒤에 query() 매개 변수에 포함되는 모델의 테이블을 무조건 적용하게 된다.







그래서 아래와 같이 select와 from을 동일한 테이블이 나오도록 쿼리를 수정한 후,, 


SELECT DISTINCT kibanaauth_esidx.esidx AS kibanaauth_esidx_esidx

FROM kibanaauth_esidx 



아래와 같이 sql_alchemy 문을 만들어서 테스트해보니. 조인이 된다.


aaa = session.query(LogAuthServiceTag.esidx).distinct() \

                    .join(LogAuthRoleServiceTag, LogAuthServiceTag.id == LogAuthRoleServiceTag.esidx_id) \

                    .join(LogAuthRole, LogAuthRole.id == LogAuthRoleServiceTag.role_id) \

                    .join(LogAuthRoleUser, LogAuthRoleUser.role_id == LogAuthRole.id) \

                    .join(LogAuthUser, LogAuthUser.id == LogAuthRoleUser.user_id) \

                    .filter(LogAuthUser.userid == userid)



query() 문에 여러 모델을 넣어도 sql_alchemy가 내부적으로 조합하기 때문에 

상황에 따라서는 from이 이상하게 나올 수 있다. 


복잡하게 sql_alchemy 를 사용할 때는 SQL 문장을 디버깅하면서 확인해야 한다.





다시 얘기하면. 



session.query(Post) \

       .join(User, Post.author_id == User.id)



이 문장은 다음과 같이 변환될 것이다.  query()의 매개 변수는 select, from으로 넘어갔다(항상 그런 것은 아니지만, 대개 그렇다.)


select post

from post 

inner join user 

   on post.author_id == user.id




Posted by '김용환'
,



python의 sql_alchemy에서 3개의 테이블을 조인하고 특정 사람의 권한을 보고 싶은 쿼리가 있다.



select role.role

from 

(user join roleuser on user.id = roleuser.user_id)

left join role role on roleuser.role_id = role.id

where user.userid = 'sma'



python의 sql_alchemy는 다음과 같이 코딩한다.



                instance = session.query(Role.role)\

                    .join(RoleUser, User.id == RoleUser.user_id) \

                    .outerjoin(Role, RoleUser.role_id == Role.id) \

                    .filter(User.userid == userid)



조인된 다른 테이블을 보려면 다음과 같다.


                instance = session.query(Role.role)\

                    .join(RoleUser, User.id == RoleUser.user_id) \

                    .outerjoin(Role, RoleUser.role_id == Role.id) \

                    .filter(User.userid == userid) \

                   .add_entity(RoleUser) \

                   .add_entity(User) \

Posted by '김용환'
,