Clock & Timer resolution(시간, 타이머 해상도)Clock & Timer resolution(시간, 타이머 해상도)

Posted at 2013. 1. 30. 15:28 | Posted in 개발이야기

출처: https://blogs.oracle.com/dholmes/entry/inside_the_hotspot_vm_clocks


clock에는 다음 2가지가 있다.

  • absolute clock (the time-of-day clock, with a low resolution)
  • relative clock (some kind of "high-resolution" counter from which a "free-running" time can be calculated)


현대 컴퓨터에서는 clock과 timer는 큰 차이가 있다.

The resolution of clocks and timers in modern computers is typically very different.

timed events are triggered by operating system controlled interrupts that are normally much more coarse grained (typically 10ms)

Further, systems often have a quite different resolution for the time-of-day clock (often low resolution of 10ms or worse) and the free-running relative clock (microseconds or better), because they are actually derived from quite different pieces of hardware.


absolute clock(time-of-day)는 자바에서 System.currentTimeMillis()로 구현된다.

(System.currentTimeMillis() = 'time-of-day' clock. update resolution is same as the timer interrupt(eg. 10ms).)

The absolute "time-of-day" clock is represented by the System.currentTimeMillis() method, that returns a millisecond representation of wall-clock time in milliseconds since the epoch. As such it uses the operating system's "time of day" clock. The update resolution of this clock is often the same as the timer interrupt (eg. 10ms), but on some systems is fixed, independent of the interrupt rate.


relative-time clock 은 자바에서 System.nanoTime()으로 구현된다. high-resolution이다.

The relative-time clock is represented by the System.nanoTime() method that returns a "free-running" time in nanoseconds.

The nanoTime method uses the highest resolution clock available on the platform, and while its return value is in nanoseconds, the update resolution is typically only microseconds.

However, on some systems there is no choice but to use the same clock source as for currentTimeMillis() - fortunately this is rare and mostly affects old Linux systems, and Windows 98.


자바 타이머 관련 클래스의 해상도.

  • The java.util.Timer and java.util.TimerTask - use of currentTimeMillis()
  • Java 5.0 ScheduledThreadPoolExecutor (STPE) - use of nanoTime()



//

TCP RST 보내기TCP RST 보내기

Posted at 2012. 12. 28. 10:02 | Posted in Server

tcp 소켓을 닫을때 일반적으로는 normal tcp termination(4way closing handshake) 과정을 거치게 된다.

이 때, 소켓을 먼저 close한 쪽에 TIME_WAIT 상태로 소켓이 남아 있게 된다.

만약 서버가 먼저 close한 경우 TIME_WAIT 소켓이 가득차서 더 이상의 소켓을 accept 할 수 없는 상황이 발생할 수 있다.

이럴 때의 대안으로 normal tcp termination이 아닌 abortive close로 TIME_WAIT이 발생하지 않도록 할 수 있다.

(TIME_WAIT 상태가 왜 있는지 정확히 알고, 특정 상황에서만 사용하자.)


SO_LINGER with timeout 0

로 설정하고 close()를 호출하면 TCP FIN 대신 RST 이 나간다.

peer는 그 유명한 "Connection reset by peer" 에러가 발생하게 된다.


상세는 다음 글을 참조하자.

according to "UNIX Network Programming" third edition page 202-203, setting SO_LINGER with timeout 0 prior to calling close() will cause the normal termination sequence not to be initiated.


http://stackoverflow.com/a/13088864


//

[mybatis] selectOne vs selectList[mybatis] selectOne vs selectList

Posted at 2012. 12. 21. 10:26 | Posted in 개발이야기

org.mybatis.spring.SqlSessionTemplate

- selectOne

  • 쿼리의 결과가 없으면 null을 반환한다. 또한, 쿼리의 결과로 레코드가 하나만 나와야 한다.
  • DB에 하나의 레코드만 있는 경우 사용. 그렇지 않으면 org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.TooManyResultsException 이 발생한다.

- selectList

  • 쿼리의 결과를 List<E>로 반환한다. 결과가 없으면, 빈 List를 반환한다.
  • selectList()가 null을 반환하지는 않는다.



//

curl 활용하기curl 활용하기

Posted at 2012. 12. 21. 10:02 | Posted in 개발이야기

<post 호출>

curl -d @data.txt http://localhost:8080

curl -d "12345" http://localhost:8080

curl -X POST -d "12345" http://localhost:8080

curl -H "Accept: application/json" -H "Content-Type: application/json" --fail -d @data.txt http://localhost:8080



<file download>

curl -O http://redis.googlecode.com/files/redis-2.6.9.tar.gz

curl -o taglist.zip http://www.vim.org/scripts/download_script.php?src_id=7701


wget http://redis.googlecode.com/files/redis-2.6.9.tar.gz

wget -O taglist.zip http://www.vim.org/scripts/download_script.php?src_id=7701


//

윈도우7 파일권한 설정하기윈도우7 파일권한 설정하기

Posted at 2012. 12. 9. 13:50 | Posted in OS/MS Windows

다른데서 사용하던 하드디스크를 꽂아서 사용할 때 파일 소유권이 없다거나, 권한이 없다거나 할 때

다음 도구를 사용해서 일괄 권한 편집이 가능하다.

"탐색기 메뉴 > 속성 > 보안 > 편집" 으로 들어가서 해줘도 되나, 번거롭다.


takeown: 소유권 가져오기(설정하기)


> takeown /F "파일 또는 폴더" /R /D Y

    /F: 파일

    /R: Recursive

    /D: Prompt (Y/N)

    /A: 현재 사용자가 아닌 관리자에 소유권을 준다.


icacls: 접근권한 설정하기(ACL설정)


> icacls "파일 또는 폴더" /grant deepblue:F /T

> icacls "파일 또는 폴더" /grant deepblue:(R,W) /T    특정 사용자에게 허용

> icacls "파일 또는 폴더" /grant Administrator:F /T   관리자에게 허용

> icacls "파일 또는 폴더" /grant Everyone:F /T        모든사용자에게 허용

    /T: Recursive

//

sar 간단 정리sar 간단 정리

Posted at 2012. 11. 12. 01:21 | Posted in OS/Unix/Linux

sar 에서 날짜가 깨져서 나올때, (mpstat, vmstat 등 다른 도구들도 마찬가지)

LC_TIME=C 로 설정하면 됨. (LC_TIME= 하면 원래대로 돌아감. LC_ALL 또는 LANG 의 값을 사용하게 됨.)

LANG 또는 LC_ALL=C로 해도 무방. 자세한건 locale 설정 방법 검색 ㄱㄱ


sar [-u] 가 기본

sar -s <hh:mm:ss> -e <hh:mm:ss>  로 시작/끝 시간 지정할 수 있다.

sar <interval> <count> 로 정해진 주기로 자동 호출되게 할 수 있다.

sar -f /var/log/sa/sa16  해당날짜(16일)의 통계를 본다.


sar -A  모든 정보 출력

sar -c  새롭게 만들어져 활동하고 있는 프로세스

sar -n DEV | EDEV | SOCK  네트워크 통계 (DEV: network device 통계, EDEV: network device 에러 통계, SOCK: socket 통계)

sar -q  실행 대기 중인 프로세스를 점검. 시스템의 load average를 나타낸다.


각 옵션별 상세 설명은 여기 참조: http://www.cubrid.com/zbxe/71317


//

대용량 데이터 분산, scale-out 에 대한 메모대용량 데이터 분산, scale-out 에 대한 메모

Posted at 2012. 10. 8. 14:14 | Posted in Server

gywn.net 의 텀블러와 Gizzard 분석 내용.

- http://gywn.net/2012/05/how_to_shard_big_data_in_tumblr/

http://gywn.net/2012/03/new-tweet-store/

- http://gywn.net/2012/03/gizzard-a-library-for-creating-distributed-datastores/


대용량 시스템을 위한 데이타베이스 아키텍쳐-Sharding & Query Off Loading

http://bcho.tistory.com/670


id sharding (인스타그램)

-http://charsyam.wordpress.com/2011/12/04/instagram-%EC%97%90%EC%84%9C-id-%EC%83%A4%EB%94%A9%ED%95%98%EA%B8%B0/



<TBD>...





//

HBase에서 사용하는 hash functionHBase에서 사용하는 hash function

Posted at 2012. 10. 5. 23:22 | Posted in OpenSource

http://javasourcecode.org/html/open-source/hbase/hbase-0.90.3/org/apache/hadoop/hbase/util/Hash.java.html

  /**
   * This utility method converts String representation of hash function name
   * to a symbolic constant. Currently two function types are supported,
   * "jenkins" and "murmur".
   * @param name hash function name
   * @return one of the predefined constants
   */
  public static int parseHashType(String name) {
    if ("jenkins".equalsIgnoreCase(name)) {
      return JENKINS_HASH;
    } else if ("murmur".equalsIgnoreCase(name)) {
      return MURMUR_HASH;
    } else {
      return INVALID_HASH;
    }
  }

//

3G 모바일 네트워크에 대한 이해3G 모바일 네트워크에 대한 이해

Posted at 2012. 9. 20. 14:49 | Posted in Article

3G 모바일 네트워크에 대한 이해(NHN개발자블로그)

http://helloworld.naver.com/helloworld/111111


3G 네트워크에 대한 이야기+a (deview 2012)

http://deview.kr/2012/xe/index.php?mid=track&document_srl=397&time_srl=260


살펴보고 내용 정리하기.




//

Forward Proxy & Reverse ProxyForward Proxy & Reverse Proxy

Posted at 2012. 9. 19. 17:35 | Posted in Server

Forward Proxy

클라이언트가 타겟서버의 주소를 프록시에 전달하여, 프록시가 요청된 내용을 가져오는 방식

  예) 클라이언트 Proxy 설정에 proxy.com을 설정하고, 주소창에 target.com을 입력하여 브라우징.


Reverse Proxy

프록시 서버로 요청을 보내면 프록시 서버가 '배후'서버로 요청하여 내용을 가져오는 방식. 이 때 Reverse는 "거꾸로, 역전"이 아닌 "배후, 뒷쪽"의 의미임. 클라이언트는 '배후' 서버를 알 수 없다.

  예) 클라이언트가 proxy.com에 요청하면 프록시 서버가 target.com 서버로 요청하여 결과를 반환.

  예) 많이 쓰는 nginx의 proxy_pass 설정은 reverse proxy 이다.

//