powertop 커맨드는 네트워크 카드의 상태 모니터링 뿐 아니라, c-state로 들어갈 지 여부를 설정할 수 있다. 

또한 정보를 csv로 사용할 수 있다.


c-state는 Intel에서 만든 전원 상태를 관리할 수 있는 방법이라 할 수 있다. cpu 내부에서 사용중이면 활성화하고 사용 중이 아니라면 낮은 성능을 유지시켜 전원을 낮게 쓰게 하는 효율적으로 유지한다. 


아래 링크의 공식 문서(Controlling Processor C-StateUsage in Linux)에 따르면 설명이 되어 있다. 




while it does save power, it takes time to enter and exit C-states. Generally the higher theC-state, more power is saved when the processor is idle, but it takes longer to get the CPU back upagain when it is needed. The C-states are:


C0 The CPU is actively running code


C1 The CPU uses the HLT instruction when idle-the clock is gated off to parts of the core, but it is relatively quick to wake up


C1E This is actually just C1, except when C1E is enabled, the CPU lowers the CPU’s speed & voltage when it is in C1


C2 & up The CPU will shut off various parts of the core for greater power savings, at thecost of taking longer to wake up


In most Linux distributions today, C-states are enabled by default, which is great for most users. Theoperating system will choose which C-state to use based on processor utilization and other factors.Some users, though, want very low latency, and are very sensitive to how quickly a CPU can run codewhen needed, so user control is desired.



문제는 c-state 상태를 intel cpu가 마음대로 결정하는 것이 default 설정이라서, 서비스 장비의 네트워크 카드까지 idle로 만들 수 있다는 점이다. 잠깐 쉬고 있는 것이지 아예 안쓰는 것은 아니라서..


그래서 자바 애플리케이션 서버에서 다음과 같은 에러를 발생한다.


java.net.UnknownHostException: googleplus001: unknown error
    at java.net.InetAddress.getLocalHost(InetAddress.java:1505)



c-state가 적용되지 않게 하려면 다음을 설정한다. 아래 링크의 공식 문서(Controlling Processor C-StateUsage in Linux)대로 진행한다. 


if you want control over C-states, or if your system might have CPUs that are newerthan the version of intel_idle in your kernel, you should use kernel parameter "intel_idle.max_cstate=0" to disable this driver.


커널 매개 변수로 intel_idle.max_cstate=0을 적용한다. 

grub 파일을 쓰고 있다면, /boot/grub/grub.conf 파일에 intel_idle.max_cstate=0를 설정하고 재시작한다. 

기존에 어떻게 동작하고 있었는지 보려면 grep idle /var/log/messages를 실행한다. 




그러면 항상 cpu에서는 모든 프로세스를 c0 상태로 두게 될 것이다. (acpi_idle 모듈이 사용됨을 의미한다)



부팅후에는 아래 커맨드로 확인해서 정상적으로 적용되었는지 확인한다.  (디폴트 값도 확인할 수 있다)


$ dmesg | grep -i intel_idle


acpi_idle이 동작되는지 살펴보면 다음과 같다. 


$ cat /proc/acpi/processor/CPU0/power

active state:            C0

max_cstate:              C1

maximum allowed latency: 2000000000 usec

states:






powertop 설치와 사용 방법은 다음과 같다. 


$ yum install powertop


su 사용자이거나 sudo를 사용해 실행한다.

$ sudo powertop


탭 간 이동은 tab을 이용하고 종료는 q를 누른다. idle 상태를 확인한다. 




Idle stat을 보면 C0로 되어 있는지 여부를 확인할 수 있다. 











여기서 Bad는 실제 c-state과 관련된 설정임을 의미한다. 나쁘다는 의미는 아니다. 



참고 


http://www.tecmint.com/powertop-monitors-linux-laptop-battery-usage/


https://www.scribd.com/document/132381013/Controlling-Processor-C-State-Usage-in-Linux-Nov2012


https://events.linuxfoundation.org/slides/2010/linuxcon2010_brown.pdf



Posted by '김용환'
,


Hive - get_json_object 호출시 에러 


hive에서 hive udf의 json을 사용하려 할 때(get_json_object를 사용, ROW FORMAT SERDE 'org.openx.data.jsonserde.JsonSerDe'를 사용) 다음 에러가 발생한다. 


Error while compiling statement: FAILED: RuntimeException MetaException(message:java.lang.ClassNotFoundException Class org.openx.data.jsonserde.JsonSerDe not found)
class org.apache.hive.service.cli.HiveSQLException



에러가 발생하지 않고 정상적으로 실행하려면,다음과 같이 실행하면 get_json_object가 실행된다.

$ wget http://www.congiu.net/hive-json-serde/1.3.7/cdh5/json-serde-1.3.7-jar-with-dependencies.jar
$ hive
hive> add jar /위치/json-serde-1.3.7-jar-with-dependencies.jar


세션이 실행될 때마다 동작시키려면 .hiverc를 수정한다.


$ vi ~/.hiverc

..

add jar /위치/json-serde-1.3.7-jar-with-dependencies.jar











Posted by '김용환'
,





hive 쿼리를 실행 중에 예약어를 쓰면 에러가 발생할 수 있다. 



FAILED: ParseException line 1:85 Failed to recognize predicate 'to'. Failed rule: 'identifier' in table or column identifier



이럴 때는 두 가지 방법으로 문제를 해결할 수 있다. 


1번째 방법이다. 


SET hive.support.sql11.reserved.keywords=false;

select * from src.google_plus_log where date_id='2037-02-22' and to='365600561231231123121212'


2번째 방법은 back quote를 사용한다.


select * from src.google_plus_log where date_id='2037-02-22' and `to`='365600561231231123121212'


Posted by '김용환'
,



top 커맨드의 메모리 관련 내용(VIRT, RES, SHR, %MEM)를 설명한다.


이를 설명하기 좋은 프로세스는 mongodb인 듯 해서 그 부분만 정리했다. 


실제 메모리를 보기 위해 free 커맨드를 실행하면 cached 메모리 때문에 마치 used 메모리가 상승했다.



$ free

                     total       used              free         shared    buffers     cached

Mem:      16289804   15621900     667904        188     148776    7787380

-/+ buffers/cache:     7685744      8604060

Swap:     10485756          0            10485756




top으로 보면 대략 전체 메모리는 16G이고 사용 중인 메모리는 15G이다. 

VIRT는 12.8G, RES는 6.7G, SHR은 6512로 나타난다. 


$ top

Mem:  16289804k total, 15621300k used,   668504k free,   148776k buffers

Swap: 10485756k total,        0k used, 10485756k free,  7787328k cached


PID USER      PR   NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND

17075 www    20   0 12.8g 6.7g 6512 S  0.7        43.2   4321:34 mongod




이것만 보고 정말 물리 메모리를 더 꽂아야 하냐고 묻길래. 아니라고 답변해 주었다. 



top 커맨드의 중요 메모리 설정을 살펴본다.


* VIRT는 프로세스의 가상 크기를 의미한다. 실제로 사용하고 있는 메모리의 총합을 의미한다. VIRT는 
 디스크의 파일을 읽으면서 사용했던 메모리도 포함될 수 있다. VIRT는 프로그램이 현재 얼마나 많은 메모리를 접근할 수 있는지 나타낸다. (즉 물리 메모리의 사용한 공간을 의미하지 않는다.) 


* RES는 실제 물리 메모리를 얼마나 쓰고 있는지 나타낸다. 따라서 VIRT보다는 작은 값을 보여준다.
%MEM의 내용에 연관된다.


* SHR은 VIRT 메모리 중 공유 메모리를 보여준다.



참고로 리눅스에서 물리 메모리 페이지 영역을 볼 수 있다. 
특정 PID의 세그먼트(segment)에 할당된 물리 메모리 페이지를 보여준다.

$ cat /proc/${PID}/smaps
..
7f8248fb2000-7f8249223000 rw-p 00000000 00:00 0
Size:               2500 kB
Rss:                1492 kB
Pss:                1492 kB
Shared_Clean:          0 kB
Shared_Dirty:          0 kB
Private_Clean:         0 kB
Private_Dirty:      1492 kB
Referenced:         1488 kB
Anonymous:          1492 kB
AnonHugePages:         0 kB
Swap:                  0 kB
KernelPageSize:        4 kB
MMUPageSize:           4 kB
7f8249223000-7f8249472000 ---p 00000000 00:00 0
Size:               2364 kB
Rss:                   0 kB
Pss:                   0 kB
Shared_Clean:          0 kB
Shared_Dirty:          0 kB
Private_Clean:         0 kB
Private_Dirty:         0 kB
Referenced:            0 kB
Anonymous:             0 kB
AnonHugePages:         0 kB
Swap:                  0 kB
KernelPageSize:        4 kB
MMUPageSize:           4 kB
7f8249472000-7f824948c000 r-xp 00000000 08:02 1326344                    /usr/java/jdk1.8.0_25/jre/lib/amd64/libzip.so
Size:                104 kB
Rss:                  84 kB
Pss:                  43 kB
Shared_Clean:         60 kB
Shared_Dirty:          0 kB
Private_Clean:        24 kB
Private_Dirty:         0 kB
Referenced:           84 kB
Anonymous:             0 kB
AnonHugePages:         0 kB
Swap:                  0 kB
KernelPageSize:        4 kB
MMUPageSize:           4 kB
...


이 정보의 간략화된 버전이다. 

$ cat /proc/${PID}/maps

7f8248fb2000-7f8249223000 rw-p 00000000 00:00 0
7f8249223000-7f8249472000 ---p 00000000 00:00 0
7f8249472000-7f824948c000 r-xp 00000000 08:02 1326344                    /usr/java/jdk1.8.0_25/jre/lib/amd64/libzip.so





더 깊이 보면 보면 재미있어야 할 내용들 레퍼런스 

1. https://en.wikipedia.org/wiki/Virtual_memory의 address space swapping


2. https://www.youtube.com/watch?v=twQKAoq2OPE


3. https://web.eecs.umich.edu/~pmchen/eecs482/handouts/memory.pdf






Posted by '김용환'
,



hbase 클라이언트 사용 할 때, hbase 서버와의 버전을 반드시 확인해야 프로토콜 이슈가 없다.


하지만, cassandra는 최상위 버전인 3.1.4 버전의 클라이언트 라이브러를 사용해도 일부 하위 버전까지 하위 호환성을 유지한다..





https://github.com/datastax/java-driver


The Java client driver 3.1.4 (branch 3.1) is compatible with Apache Cassandra 1.2, 2.0, 2.1, 2.2 and 3.0 (see this pagefor the most up-to-date compatibility information).




http://datastax.github.io/java-driver/manual/native_protocol



Native protocol

The native protocol defines the format of the binary messages exchanged between the driver and Cassandra over TCP. As a driver user, you don’t need to know the fine details (although the protocol spec is in the Cassandra codebase if you’re curious); the most visible aspect is that some features are only available with specific protocol versions.

Compatibility matrix

By default, the protocol version is negotiated between the driver and Cassandra when the first connection is established. Both sides are backward-compatible with older versions:


 Cassandra: 1.2.x
(DSE 3.2)
2.0.x
(DSE 4.0 to 4.6)
2.1.x
(DSE 4.7)
2.2.x3.0.x
Driver: 1.0.xv1v1v1v1Unsupported (1)
2.0.x to 2.1.1v1v2v2v2Unsupported (1)
2.1.2 to 2.1.xv1v2v3v3Unsupported (2)
3.xv1v2v3v4v4

(1) Cassandra 3.0 does not support protocol versions v1 and v2

(2) There is a matching protocol version (v3), but the driver 2.1.x can’t read the new system table format of Cassandra 3.0

For example, if you use version 2.1.5 of the driver to connect to Cassandra 2.0.9, the maximum version you can use (and the one you’ll get by default) is protocol v2 (third row, second column). If you use the same version to connect to Cassandra 2.1.4, you can use protocol v3.




netty 버전과 이슈가 있을 수 있으니.아래 내용도 참고한다. 


https://github.com/datastax/java-driver/tree/3.1.x/manual/shaded_jar







참고로 cassandra 2.1에서 3.1로 올리는 테스트해보니 바로 되지 않는 부분이 있다.


LocalDate의 getTime 메소드 같은 경우는 아예 사라져 있다.


long startDate = row.getDate("date1").getTime();




다음과 같은 에러가 발생했다.


 (188): Codec not found for requested operation: [timestamp <-> com.datastax.driver.core.LocalDate]

com.datastax.driver.core.exceptions.CodecNotFoundException: Codec not found for requested operation: [timestamp <-> com.datastax.driver.core.LocalDate]

        at com.datastax.driver.core.CodecRegistry.notFound(CodecRegistry.java:679) ~[story-app.jar:na]

        at com.datastax.driver.core.CodecRegistry.createCodec(CodecRegistry.java:526) ~[story-app.jar:na]

        at com.datastax.driver.core.CodecRegistry.findCodec(CodecRegistry.java:506) ~[story-app.jar:na]

        at com.datastax.driver.core.CodecRegistry.access$200(CodecRegistry.java:140) ~[story-app.jar:na]

        at com.datastax.driver.core.CodecRegistry$TypeCodecCacheLoader.load(CodecRegistry.java:211) ~[story-app.jar:na]

        at com.datastax.driver.core.CodecRegistry$TypeCodecCacheLoader.load(CodecRegistry.java:208) ~[story-app.jar:na]

        at com.google.common.cache.LocalCache$LoadingValueReference.loadFuture(LocalCache.java:3524) ~[story-app.jar:na]

        at com.google.common.cache.LocalCache$Segment.loadSync(LocalCache.java:2317) ~[story-app.jar:na]

        at com.google.common.cache.LocalCache$Segment.lockedGetOrLoad(LocalCache.java:2280) ~[story-app.jar:na]

        at com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2195) ~[story-app.jar:na]

        at com.google.common.cache.LocalCache.get(LocalCache.java:3934) ~[story-app.jar:na]

        at com.google.common.cache.LocalCache.getOrLoad(LocalCache.java:3938) ~[story-app.jar:na]

        at com.google.common.cache.LocalCache$LocalLoadingCache.get(LocalCache.java:4821) ~[story-app.jar:na]

        at com.datastax.driver.core.CodecRegistry.lookupCodec(CodecRegistry.java:480) ~[story-app.jar:na]

        at com.datastax.driver.core.CodecRegistry.codecFor(CodecRegistry.java:448) ~[story-app.jar:na]

        at com.datastax.driver.core.CodecRegistry.codecFor(CodecRegistry.java:430) ~[story-app.jar:na]

        at com.datastax.driver.core.AbstractGettableByIndexData.codecFor(AbstractGettableByIndexData.java:69) ~[story-app.jar:na]

        at com.datastax.driver.core.AbstractGettableByIndexData.getDate(AbstractGettableByIndexData.java:174) ~[story-app.jar:na]

        at com.datastax.driver.core.AbstractGettableData.getDate(AbstractGettableData.java:26) ~[story-app.jar:na]

        at com.datastax.driver.core.AbstractGettableData.getDate(AbstractGettableData.java:111) ~[story-app.jar:na]




다음 코드로 변경하면 잘 동작한다. 

row.getTimestamp("date1").getTime();



좋은 자료

https://groups.google.com/a/lists.datastax.com/forum/#!topic/java-driver-user/pAoLlEzmGWA

https://datastax-oss.atlassian.net/browse/JAVA-1176




maven dependency 3.1과 2.1 비교 



cassandra 3.1

[INFO] +- com.datastax.cassandra:cassandra-driver-core:jar:3.1.3:compile

[INFO] |  +- io.netty:netty-handler:jar:4.0.37.Final:compile

[INFO] |  |  +- io.netty:netty-buffer:jar:4.0.37.Final:compile

[INFO] |  |  |  \- io.netty:netty-common:jar:4.0.37.Final:compile

[INFO] |  |  +- io.netty:netty-transport:jar:4.0.37.Final:compile

[INFO] |  |  |  \- (io.netty:netty-buffer:jar:4.0.37.Final:compile)

[INFO] |  |  \- io.netty:netty-codec:jar:4.0.37.Final:compile

[INFO] |  |     \- (io.netty:netty-transport:jar:4.0.37.Final:compile)

[INFO] |  +- (com.google.guava:guava:jar:16.0.1:compile)

[INFO] |  +- io.dropwizard.metrics:metrics-core:jar:3.1.2:compile

[INFO] |  |  \- (org.slf4j:slf4j-api:jar:1.7.7:compile - omitted for conflict with 1.7.6)

[INFO] |  +- com.github.jnr:jnr-ffi:jar:2.0.7:compile

[INFO] |  |  +- com.github.jnr:jffi:jar:1.2.10:compile

[INFO] |  |  +- com.github.jnr:jffi:jar:native:1.2.10:runtime

[INFO] |  |  +- (org.ow2.asm:asm:jar:5.0.3:compile - omitted for conflict with 4.1)

[INFO] |  |  +- (org.ow2.asm:asm-commons:jar:5.0.3:compile - omitted for conflict with 4.1)

[INFO] |  |  +- org.ow2.asm:asm-analysis:jar:5.0.3:compile

[INFO] |  |  |  \- (org.ow2.asm:asm-tree:jar:5.0.3:compile)

[INFO] |  |  +- org.ow2.asm:asm-tree:jar:5.0.3:compile

[INFO] |  |  |  \- (org.ow2.asm:asm:jar:5.0.3:compile - omitted for conflict with 4.1)

[INFO] |  |  +- org.ow2.asm:asm-util:jar:5.0.3:compile

[INFO] |  |  |  \- (org.ow2.asm:asm-tree:jar:5.0.3:compile)

[INFO] |  |  \- com.github.jnr:jnr-x86asm:jar:1.0.2:compile

[INFO] |  \- com.github.jnr:jnr-posix:jar:3.0.27:compile

[INFO] |     +- (com.github.jnr:jnr-ffi:jar:2.0.7:compile)

[INFO] |     \- com.github.jnr:jnr-constants:jar:0.9.0:compile



cassandra 2.1



[INFO] +- com.datastax.cassandra:cassandra-driver-core:jar:2.1.9:compile

[INFO] |  +- io.netty:netty-handler:jar:4.0.27.Final:compile

[INFO] |  |  +- io.netty:netty-buffer:jar:4.0.27.Final:compile

[INFO] |  |  |  \- io.netty:netty-common:jar:4.0.27.Final:compile

[INFO] |  |  +- io.netty:netty-transport:jar:4.0.27.Final:compile

[INFO] |  |  |  \- (io.netty:netty-buffer:jar:4.0.27.Final:compile)

[INFO] |  |  \- io.netty:netty-codec:jar:4.0.27.Final:compile

[INFO] |  |     \- (io.netty:netty-transport:jar:4.0.27.Final:compile)

[INFO] |  +- (com.google.guava:guava:jar:14.0.1:compile - omitted for conflict with 16.0.1)

[INFO] |  \- com.codahale.metrics:metrics-core:jar:3.0.2:compile

[INFO] |     \- (org.slf4j:slf4j-api:jar:1.7.5:compile - omitted for conflict with 1.7.6)


Posted by '김용환'
,



"마침표(.)" 커맨드는 쉘이 지정 파일을 읽고 실행할 수 있게 한다. file은 실행 가능한 필요는 없고, 읽을 수 있으면 된다. 또한 쉘은 PATH 변수를 사용하여 file을 찾는다. 서브쉘에 전달되지 않는다.



$ cat varx
AAA=a
BBB=b

$ . varx

$ echo $AAA
a

$ echo $BBB
b






Posted by '김용환'
,

널 커맨드 - :

unix and linux 2017. 2. 23. 08:46




: 커맨드는 본질적으로 널(null) 커맨드이다. 커맨드가 있어야 하는 요구 사항을 충족시키는 데 자주 사용된다.



 if [ $(id -u) != "0" ]; then : ; else echo "superuser"; fi



Posted by '김용환'
,

[spark] spark summit 자료

scala 2017. 2. 22. 23:38


spark summit 자료는 잘 공개되어 있다. 세션 뿐 아니라 튜터리얼 까지도. ㄷ ㄷ 




https://spark-summit.org/2016/schedule/



https://spark-summit.org/east-2017/schedule/




'scala' 카테고리의 다른 글

[펌] spark 2.0 소개(성능)  (0) 2017.03.02
[spark] spark의 OutOfMemoryError 발생시  (0) 2017.02.24
[scala] Array.transpose 예시  (0) 2017.02.17
[spark1.6] rdd를 dataframe으로 만드는 방법  (0) 2017.02.14
[spark] foreachPartition 예시  (0) 2017.02.14
Posted by '김용환'
,



바로 이전 디렉토리로 이동하려면 cd - 를 사용한다.


그러나 바로 이전 디렉토리가 어디있지 출력하고 싶을 때는..  다음 커맨드를 사용한다.


echo ~-


현재 디렉토리는 다음 커맨드를 사용한다.


echo ~+



$ echo ~+

/temp

$ echo ~-

/usr/local/redis/src


'unix and linux' 카테고리의 다른 글

닷 커맨드(마침표 커맨드) : .  (0) 2017.02.23
널 커맨드 - :  (0) 2017.02.23
[bash] stty tostop  (0) 2017.02.20
typeset 커맨드  (0) 2017.02.17
[bash] history를 관리하는 툴 fc  (0) 2017.02.17
Posted by '김용환'
,

[bash] stty tostop

unix and linux 2017. 2. 20. 18:54


백그라운드로 실행한 작업이 있는데,

계속 로그 출력이 계속되면 좀 거슬릴 수 있다. 


백그라운드 작업을 한번에 중지하려면 stty tostop을 사용한다. 




$ ./sleep.sh


echo 1

sleep 1

echo 1

sleep 1

echo 1

sleep 1

...


$./sleep.sh  &




$ stty tostop


[1]+  Stopped                 ./sleep.sh




'unix and linux' 카테고리의 다른 글

널 커맨드 - :  (0) 2017.02.23
[bash] 바로 이전 디렉토리 확인하기  (0) 2017.02.20
typeset 커맨드  (0) 2017.02.17
[bash] history를 관리하는 툴 fc  (0) 2017.02.17
라인 편집기 모드를 vi로 적용하기 (set -o vi)  (0) 2017.02.15
Posted by '김용환'
,