Middleware/Setting

[Tomcat] Tomcat 8버전 Clustering

cocologue 2021. 2. 27. 23:35
SMALL

[테스트환경]

  - HostOS : Windows10

  - GuestOS : CentOS 7.4

  - JDK : OpenJDK 1.8.0_242

  - WEB : Apache/2.4.34 (httpd-2.4.34)

  - WAS : Apache-Tomcat-8.5.40

 

[내용]

​  - 설정파일 : conf/server.xml

 

  1) 기본 server.xml에 있는 설정 주석제거 (<!-- -->제거)

<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>

  2) 1번 설정만 하면 Default 설정으로 클러스터링이 되지만, 포트 지정을 하지 않고 기본설정에 맡기면.. 포트 중복이 나며 기동이 멈춘다.

    - 이 때 Thread Dump를 떠보면 이렇게 Lock이 많이 잡힌 것으로 보이고,

[tomcat@testap02 tomcat81]$ grep "wait for" thread1.log
        - parking to wait for  <0x00000000e99fe270> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
        - parking to wait for  <0x00000000e99fe270> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
        - parking to wait for  <0x00000000e99fe270> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
        - parking to wait for  <0x00000000e99fe270> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
        - parking to wait for  <0x00000000e99fe270> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
        - parking to wait for  <0x00000000e99fe270> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
        - parking to wait for  <0x00000000e99fe270> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
        - parking to wait for  <0x00000000e99fe270> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
        - parking to wait for  <0x00000000e99fe270> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
        - parking to wait for  <0x00000000e99fe270> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
        - parking to wait for  <0x00000000e99ffb78> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
        - parking to wait for  <0x00000000e99ffb78> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
        - parking to wait for  <0x00000000e99ffb78> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
        - parking to wait for  <0x00000000e99ffb78> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
        - parking to wait for  <0x00000000e99ffb78> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
        - parking to wait for  <0x00000000e99ffb78> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
        - parking to wait for  <0x00000000e99ffb78> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
        - parking to wait for  <0x00000000e99ffb78> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
        - parking to wait for  <0x00000000e99ffb78> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
        - parking to wait for  <0x00000000e99ffb78> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)

    - 기동로그는 Started in이 찍히지 않은 상태(정상기동이 안된 상태)로 멈춰버린다.

 

(비정상로그)

24-Apr-2020 17:34:35.291 정보 [main] org.apache.catalina.tribes.membership.McastServiceImpl.waitForMembers Done sleeping, membership established, start level:[4]
24-Apr-2020 17:34:35.301 정보 [main] org.apache.catalina.tribes.membership.McastServiceImpl.waitForMembers Sleeping for [1000] milliseconds to establish cluster membership, start level:[8]
24-Apr-2020 17:34:35.359 정보 [Tribes-Task-Receiver[Catalina-Channel]-1] org.apache.catalina.tribes.io.BufferPool.getBufferPool Created a buffer pool with max size:[104857600] bytes of type: [org.apache.catalina.tribes.io.BufferPool15Impl]
24-Apr-2020 17:34:36.302 정보 [main] org.apache.catalina.tribes.membership.McastServiceImpl.waitForMembers Done sleeping, membership established, start level:[8]
24-Apr-2020 17:34:36.361 정보 [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [/tomcat/applications/tomcat82/tomcat8] -> 여기서 멈춤 (멈추는 곳은 환경 별로 다를 수있어요)

 

(정상로그)

24-Apr-2020 17:32:25.885 정보 [main] org.apache.catalina.tribes.membership.McastServiceImpl.waitForMembers Sleeping for [1000] milliseconds to establish cluster membership, start level:[4]
24-Apr-2020 17:32:26.886 정보 [main] org.apache.catalina.tribes.membership.McastServiceImpl.waitForMembers Done sleeping, membership established, start level:[4]
24-Apr-2020 17:32:26.895 정보 [main] org.apache.catalina.tribes.membership.McastServiceImpl.waitForMembers Sleeping for [1000] milliseconds to establish cluster membership, start level:[8]
24-Apr-2020 17:32:27.896 정보 [main] org.apache.catalina.tribes.membership.McastServiceImpl.waitForMembers Done sleeping, membership established, start level:[8]
24-Apr-2020 17:32:28.008 정보 [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [/tomcat/applications/tomcat81/tomcat8]
24-Apr-2020 17:32:29.202 정보 [localhost-startStop-1] org.apache.catalina.ha.session.DeltaManager.startInternal Register manager [localhost#/tomcat8] to cluster element [Engine] with name [Catalina]
24-Apr-2020 17:32:29.202 정보 [localhost-startStop-1] org.apache.catalina.ha.session.DeltaManager.startInternal Starting clustering manager at [localhost#/tomcat8]
24-Apr-2020 17:32:29.203 정보 [localhost-startStop-1] org.apache.catalina.ha.session.DeltaManager.getAllClusterSessions Manager [localhost#/tomcat8]: skipping state transfer. No members active in cluster group.
24-Apr-2020 17:32:29.255 정보 [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [/tomcat/applications/tomcat81/tomcat8] has finished in [1,246] ms
24-Apr-2020 17:32:29.257 정보 [main] org.apache.catalina.ha.session.JvmRouteBinderValve.startInternal JvmRouteBinderValve started
24-Apr-2020 17:32:29.274 정보 [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-nio-192.168.56.20-8680"]
24-Apr-2020 17:32:29.343 정보 [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["ajp-nio-192.168.56.20-8609"]
24-Apr-2020 17:32:29.449 정보 [main] org.apache.catalina.startup.Catalina.start Server startup in 3886 ms

 

 3) Tomcat의 Default 설정은 이렇게 된다. (참고 : http://tomcat.apache.org/tomcat-8.5-doc/cluster-howto.html)

    - 해당 설정을 환경에 맞게 수정 해 준다.

      ① Muticast를 하기위한 IP

      ② auto 의 경우, 해당 서버의 IP정보를 자동으로 가져온다. 제대로 안될 땐 서버의 IP를 적어준다.

      ③ 2) 에서 문제가 되었던 포트 클러스터링를 위한 포트이며, 인스턴스별 포트를 중복되지 않게 작성한다.

<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster" hannelSendOptions="8"> <-- 1) 에서 주석 해제 한 부분
  <Manager className="org.apache.catalina.ha.session.DeltaManager"
             expireSessionsOnShutdown="false" notifyListenersOnReplication="true"/>
  <Channel className="org.apache.catalina.tribes.group.GroupChannel">
    <Membership className="org.apache.catalina.tribes.membership.McastService"
                address="①228.0.0.4"
                port="45564"
                frequency="500"
                dropTime="3000"/>
    <Receiver className="org.apache.catalina.tribes.transport.nio.NioReceiver"
              address="②auto"
              port="③4000"
              autoBind="100"
              selectorTimeout="5000"
              maxThreads="6"/>
    <Sender className="org.apache.catalina.tribes.transport.ReplicationTransmitter">
      <Transport className="org.apache.catalina.tribes.transport.nio.PooledParallelSender"/>
    </Sender>
    <Interceptor className="org.apache.catalina.tribes.group.interceptors.TcpFailureDetector"/>
    <Interceptor className="org.apache.catalina.tribes.group.interceptors.MessageDispatchInterceptor"/>
  </Channel>

  <Valve className="org.apache.catalina.ha.tcp.ReplicationValve" filter=""/>
  <Valve className="org.apache.catalina.ha.session.JvmRouteBinderValve"/>

  <Deployer className="org.apache.catalina.ha.deploy.FarmWarDeployer"
            tempDir="/tmp/war-temp/"
            deployDir="/tmp/war-deploy/"
            watchDir="/tmp/war-listen/"
            watchEnabled="false"/>
  <ClusterListener className="org.apache.catalina.ha.session.ClusterSessionListener"/>
</Cluster>

 

3) 설정까지 해주면 클러스터링은 정상적으로 된다! 대신 기동시간이 많이 늘어난다.
1,2번 인스턴스를 각자 내려보면서 세션 공유가 잘 되는지 확인 해봤는데, 세션이 1개 뿐인데도.. 기동 시간이 3초는 더 늘어난다.
그래도 7버전 보다는 8버전에서 클러스터링이 좀 더 좋아진 것 같긴한데... 7버전도 다시 테스트 해 봐야 할 것 같다.
결론은 JDK7에 Tomcat7 쓰는 것 보다 JDK8에 Tomcat8을 쓰는게 낫다! 

 

동일 조건에서 Tomcat7과 Tomcat8 클러스터링을 비교해봤는데, 확실히 Tomcat8이 기동되는데 시간이 빠르다.
설정 넣고 기동했을때도 4초정도, 세션이 어느정도 많아졌을 때도 4초.
같은 환경에서 세션이 많아지면 4초->7초로 늘어났던 Tomcat7에 비하면 확실히 빨라진 것 같다.

 

2020. 4. 24. 18:08 Naver Blog Backup
반응형
LIST