본문 바로가기
이것저것(독후감같은거)

Cping Cpong-Apache Tomcat Connector

by 혜룐 2016. 9. 2.

전에 쓴 글을 누가 물어봐서..  이제는 싸이블로그를 안함.... 이곳으로 복붙해옴~

( http://cy.cyworld.com/home/27126212/post/14512351  )



CPing/CPong

backend 연결의 상태를 확인하는 목적으로 사용한다.
CPing/CPong의 개념은 작은 사이즈의 test 패킷으로 커넥션에 문제가 없는지 확인 하고, 정상적인 경우에만 backend에 연결을 맺게 하는 것이다.
즉, 새로운 백엔드 커넥션을 연결한 후(connection mode: C mode), 그리고 요청받은 패킷을 백엔드에서 받기 전(prepost mode: P mode)에 test패킷을 통해 connection 연결에 문제가 없는지를 확인 하는 것이다. 당연히 연결 상태를 확인해 문제없을 경우에만 backend에 정상적으로 연결한다.
mod_JK 1.2.27 버전부터 제공되는 기능이고, 자사의 경우 1.2.36버전을 사용 하고 있다.(64bit)

ping-mode

mode

descrption

C: connect mode

If set, the connection will be probed once after connecting to the backend. The timeout can be set by connect_timeout. If it is not set, the value of ping_timeout will be used instead.

P: prepost mode

If set, the connection will be probed before sending each request to the backend. The timeout can be set by prepost_timeout. If it is not set, the value of ping_timeout will be used instead.

I: interval mode

If set, the connection will be probed during the regular internal maintenance cycle, but only if it is idle longer than connection_ping_interval. The timeout can be set by ping_timeout.

A: all modes

If set, all of the above probes will be used.

CPing 테스트를 사용하는 것을 권고 하지만, 지연에 민감한 어플리케이션이라고 한다면 C모드 사용하거나, C모드와 I모드의 조합을 사용하는 것이 좋다.
각각의 모드에는 time값을 설정 할 수 있는데, 설정되어 있지 않다면 ping_timeout의 값이 적용되고 이 값은 사용자가 수정할 수 있다. (기본값은 10000 milliseconds이다)

  • ping_timeout
    CPong default wait시간에 사용되는 값으로, 기본값은 10000(milliseconds) 이다.
    다만, JAVA의 GC의 타임이 길게 발생하는 경우라면, 이 기본값을 보다 작게 수정하지 말아야 한다. (C와 P모드를 사용할 경우에는 너무 짧은 값을 사용해서는 안된다.)
    GC의추이를 잘 보고 timeout값을 조정하면 되는데, 네트워크 대기와 안정성을 고려 한다면, 5000 ~ 15000 으로 하는게 좋다.
  • connect timeout
    커넥션이 연결되는 동안 Cpong default wait에 사용되는 값으로, 값이 셋팅되어 있지 않다면, ping_timeout값을 사용한다.
    Jk는 맺어진 커넥션을 영구적으로 사용하기 때문에, 새로운 백엔드커넥션을 연결하는 경우는 거의 드물기 때문에, C모드를 active해 CPing을 사용하는 것을 권고 한다.
    이 수치 또한 5000 ~ 15000 사이가 적정하다.
  • prepost_timeout
    백엔드로 요청이 전달되기 전에 사용되는 값으로, 위와 마찬가지로 prepost_time값이 셋팅되어 있지 않다면, ping_timeout값을 사용한다.
    이 모드를 사용하게 되면, _각각 요청에 대해 작은 대기시간이 발생_하기 때문에, 지연에 민감한 어플리케이션이라고 하면, 사용하지 않는 것이 좋다.
    네트워크 대기와 안정성을 고려한다면 5000 ~ 10000 사이가 적정하다.

how to

1. C,P 모드를 active 하고 각각의 timeout수치를 10000,10000 (milliseconds) 으로 설정

[2014 Wed Feb 19 15:2729][28266:3086055168] [debug] ajp_connection_tcp_send_message::jk_ajp_common.c (1145): sending to ajp13 pos=4 len=5 max=16
[2014 Wed Feb 19 15:2729][28266:3086055168] [debug] ajp_connection_tcp_send_message::jk_ajp_common.c (1145): 0000    12 34 00 01 0A 00 00 00 00 00 00 00 00 00 00 00  - .4..............
[2014 Wed Feb 19 15:2729][28266:3086055168] [debug] ajp_connection_tcp_get_message::jk_ajp_common.c (1329): received from ajp13 pos=0 len=1 max=16
[2014 Wed Feb 19 15:2729][28266:3086055168] [debug] ajp_connection_tcp_get_message::jk_ajp_common.c (1329): 0000    09 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  - ................

2. C,P 모드 각각의 timeout수치를 10,10(milliseconds) 으로 낮춰 timeout을 유발

  • worker.properties
    [root@sr-was1 apache]# cat conf/extra/workers.properties
    worker.list=worker1
     
    worker.worker1.type=ajp13
    worker.worker1.host=localhost
    worker.worker1.port=8009
    worker.worker1.socket_timeout=600
    worker.worker1.ping_mode=C,P
    worker.worker1.connect_timeout=10
    worker.worker1.prepost_timeout=10
    [2014 Wed Feb 19 15:5051][28693:3086055168] [debug] jk_is_input_event::jk_connect.c (993): timeout during poll on socket 21 [127.0.0.1:59446 -> 127.0.0.1:8009] (timeout=10)
    [2014 Wed Feb 19 15:5051][28693:3086055168] [info] ajp_handle_cping_cpong::jk_ajp_common.c (879): timeout in reply cpong
    [2014 Wed Feb 19 15:5051][28693:3086055168] [debug] jk_shutdown_socket::jk_connect.c (726): About to shutdown socket 21 [127.0.0.1:59446 -> 127.0.0.1:8009]
    [2014 Wed Feb 19 15:5051][28696:3086055168] [debug] ajp_connection_tcp_get_message::jk_ajp_common.c (1329): received from ajp13 pos=0 len=240 max=8192
    [2014 Wed Feb 19 15:5051][28693:3086055168] [debug] jk_shutdown_socket::jk_connect.c (808): Shutdown socket 21 [127.0.0.1:59446 -> 127.0.0.1:8009] and read 5 lingering bytes in 0 sec.
    [2014 Wed Feb 19 15:5051][28693:3086055168] [info] ajp_send_request::jk_ajp_common.c (1511): (worker1) failed sending request, socket -1 prepost cping/cpong failure (errno=110)
    [2014 Wed Feb 19 15:5051][28693:3086055168] [info] ajp_send_request::jk_ajp_common.c (1567): (worker1) all endpoints are disconnected, detected by connect check (0), cping (1), send (0)

3. 2번과 동일한 설정 2차 test

  • 아래 로그는 c모드에서 발생한 커넥션 error로 보여짐.
    [2014 Wed Feb 19 16:4859][29663:3086055168] [debug] jk_shutdown_socket::jk_connect.c (808): Shutdown socket 21 [127.0.0.1:46769 -> 127.0.0.1:8009] and read 5 lingering bytes in 0 sec.
    [2014 Wed Feb 19 16:4859][29663:3086055168] [error] ajp_connect_to_endpoint::jk_ajp_common.c (985): (worker1) cping/cpong after connecting to the backend server failed (errno=110)
    [2014 Wed Feb 19 16:4859][29663:3086055168] [error] ajp_send_request::jk_ajp_common.c (1578): (worker1) connecting to backend failed. Tomcat is probably not started or is listening on the wrong port (errno=110)
    [2014 Wed Feb 19 16:4859][29663:3086055168] [info] ajp_service::jk_ajp_common.c (2543): (worker1) sending request to tomcat failed (recoverable), because of error during request sending (attempt=1)
    [2014 Wed Feb 19 16:4859][29663:3086055168] [debug] ajp_service::jk_ajp_common.c (2400): retry 1, sleeping for 100 ms before retrying
    [2014 Wed Feb 19 16:4859][29666:3086055168] [debug] map_uri_to_worker_ext::jk_uri_worker_map.c (1036): Attempting to map URI '/assets/stylesheets/prettify.css' from 1 maps
    [2014 Wed Feb 19 16:4859][29666:3086055168] [debug] find_match::jk_uri_worker_map.c (850): Attempting to map context URI '/*=worker1' source 'JkMount'
  1. 참고문서
    1. https://access.redhat.com/site/documentation/en-US/JBoss_Enterprise_Application_Platform/5/html/HTTP_Connectors_Load_Balancing_Guide/Apache_HTTP_Troubleshooting.html
    2. http://tomcat.apache.org/connectors-doc/reference/workers.html
    3. http://tomcat.apache.org/connectors-doc/generic_howto/timeouts.html