'tomcat'에 해당되는 글 16건

  1. 2021.12.07 [Elasticsearch] LLRC + Springboot 성능 튜닝 팁
  2. 2020.06.25 [Spring] Spring boot tomcat relaxedQueryChars
  3. 2020.06.01 [Spring] Spring boot jar build and run.
  4. 2018.05.02 [Spring Framework] SpringMVC + Gradle 템플릿 + Tomcat 연동
  5. 2016.09.19 [Tomcat] Spring framework 사용 시 중복 실행 이슈
  6. 2016.03.24 [Intellij] Intellij + SpringMVC + Tomcat
  7. 2014.02.12 [eclipse] tomcat 실행 시 java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener 에러 1
  8. 2013.09.11 [Tomcat] Tomcat 전용 WAS 서버설정.(server.xml]
  9. 2012.11.14 solr + tomcat 연동 시 admin 에서 한글 검색 이슈
  10. 2012.10.24 Tomcat 에서 IP Restriction 하기.

[Elasticsearch] LLRC + Springboot 성능 튜닝 팁

Elastic/Elasticsearch 2021. 12. 7. 09:14

대부분의 성능 이슈는 서버 엔진 보다는 클라이언트 단에서 사용을 잘 못 하는 경우가 많이 있습니다.

 

Low Level Rest Client 와 Springboot 조합으로 API 개발 시 튜닝 요소를 조금 정리 합니다.

나중에 또 기억 못할 것 같으니...

 

RestClientBuilder 에 보면 아래와 같이 기본 설정이 되어 있습니다.

public static final int DEFAULT_MAX_CONN_PER_ROUTE = 10;
public static final int DEFAULT_MAX_CONN_TOTAL = 30;

이 기본 값으로 그냥 사용하게 되면 너무 리소스를 제한적으로 사용하기 때문에 성능이 제대로 나오지 않게 됩니다.

해당 값을 적절하게 튜닝을 하셔야 하는데 모든 케이스에 다 적용 가능한 부분은 아니지만 그래도 가늠 할 수 있는 기준 정도로는 사용이 가능 할 것 같아 공유 합니다.

분석 결과는 Core 1 개당 setMaxConnPerRoute 설정 시 25 개씩이 최적 값으로 보입니다.
4 core 짜리면 4 x 25 = setMaxConnPerRoute(100)

 

아래는 실제 코드 내부에 작성 되어 있는 코멘트를 보여 드리기 위해 캡쳐 했습니다.

HttpAsyncClientBuilder httpClientBuilder = HttpAsyncClientBuilder.create().setDefaultRequestConfig(requestConfigBuilder.build())
  //default settings for connection pooling may be too constraining
  .setMaxConnPerRoute(DEFAULT_MAX_CONN_PER_ROUTE).setMaxConnTotal(DEFAULT_MAX_CONN_TOTAL)

 

코드에서도 동일하게 기본 설정은 너무 제한적일 수 있다고 되어 있습니다.

 

Embedded Tomcat 에서의 기본 Max Connection 은 8192 개 입니다.

Tomcat 과 HttpClient 그리고 Elasitcsearch 에 대한 각각의 Connection, Thread Count 를 잘 조정 하셔야 성능을 최적화 할 수 있습니다.

 

추가적으로 Connection 과 Route 의 비율은 10:1 정도가 적절해 보입니다.

 

아래는 Tomcat 기본 설정 내용입니다.

- Embedded Tocmat 의 설정 중
    acceptCount 는 기본 100 개 이며 이 설정은 maxConnection 에 다다랐을 때 OS 레벨에서 큐잉 하게 되는 값 입니다.
    maxConnections 는 기본 8192 개 이며 NIO/NIO2 를 사용 하며, -1 로 설정 시 카운팅 하지 않습니다. (unlimited)
    maxThreads 는 기본 200 개 이며 connection 당 생성 가능한 최대 thread 수 입니다.
    BIO 일 경우 maxConnections 와 maxThreads 값은 같아야 합니다.


정답은 없으나 시스템 리소스 상황에 맞춰서 최적 값을 찾아 내는게 제일 중요 합니다.
위에 설정 방식이나 값이 최적 값이 아니며 상황에 맞춘 최적 값이고 다른 환경에서는 튜닝 포인트가 된다고 보는게 좋을 것 같습니다.

시스템의 ulimit 설정을 꼭 확인 하고 사용하는 stack 의 default 값도 꼭 확인 하고 사용 합시다.

성능 최적화를 위해 함께 살펴 봐야 하는 소스 코드는 

Java NIO, Executor
Tomcat Connector
Http Client (Components)
Elasticsearch RestClient

 

:

[Spring] Spring boot tomcat relaxedQueryChars

ITWeb/개발일반 2020. 6. 25. 11:35

https://docs.spring.io/spring-boot/docs/current/reference/html/appendix-application-properties.html#server-properties

 

Common Application properties

Various properties can be specified inside your application.properties file, inside your application.yml file, or as command line switches. This appendix provides a list of common Spring Boot properties and references to the underlying classes that consume

docs.spring.io

https://tomcat.apache.org/tomcat-9.0-doc/config/http.html

 

Apache Tomcat 9 Configuration Reference (9.0.36) - The HTTP Connector

This Connector supports all of the required features of the HTTP/1.1 protocol, as described in RFCs 7230-7235, including persistent connections, pipelining, expectations and chunked encoding. If the client supports only HTTP/1.0 or HTTP/0.9, the Connector

tomcat.apache.org

 

server.tomcat.relaxed-path-chars

Comma-separated list of additional unencoded characters that should be allowed in URI paths. Only "< > [ \ ] ^ ` { | }" are allowed.

server.tomcat.relaxed-query-chars

Comma-separated list of additional unencoded characters that should be allowed in URI query strings. Only "< > [ \ ] ^ ` { | }" are allowed.

relaxedPathChars

The HTTP/1.1 specification requires that certain characters are %nn encoded when used in URI paths. Unfortunately, many user agents including all the major browsers are not compliant with this specification and use these characters in unencoded form. To prevent Tomcat rejecting such requests, this attribute may be used to specify the additional characters to allow. If not specified, no additional characters will be allowed. The value may be any combination of the following characters: " < > [ \ ] ^ ` { | } . Any other characters present in the value will be ignored.

relaxedQueryChars

The HTTP/1.1 specification requires that certain characters are %nn encoded when used in URI query strings. Unfortunately, many user agents including all the major browsers are not compliant with this specification and use these characters in unencoded form. To prevent Tomcat rejecting such requests, this attribute may be used to specify the additional characters to allow. If not specified, no additional characters will be allowed. The value may be any combination of the following characters: " < > [ \ ] ^ ` { | } . Any other characters present in the value will be ignored.

의도치 않게 tomcat 에서 에러 처리를 해버려서 이를 방지 하기 위해 설정 후 application 에서 처리 하시면 됩니다.

:

[Spring] Spring boot jar build and run.

ITWeb/개발일반 2020. 6. 1. 18:05

build.gradle)
plugins {
  id 'org.springframework.boot' version '2.3.0.RELEASE'
...중략...
  id 'java'
  id 'war'
}

...중략...

task projectVersion {
  doLast {
    println "${project.version}"
  }
}

task jarName {
  doLast {
    println "${archivesBaseName}-${version}.jar"
  }
}

bootJar {
  archivesBaseName = "springboot-was"
}

war {
  enabled = true
  archivesBaseName = "springboot-was"
}

 

build)
$ ./gradlew clean build bootJar

 

run)
$ sudo java -Djava.security.egd=file:/dev/./urandom -jar springboot-was.jar

 

springboot 프로젝트로 빌드 후 embedded tomcat 으로 실행 하는 예제 입니다.

:

[Spring Framework] SpringMVC + Gradle 템플릿 + Tomcat 연동

ITWeb/개발일반 2018. 5. 2. 18:33

매니저 역할을 오래 하다 보면 개발 감각이 떨어 지는건 어쩔수 없는 일인 것 같습니다.

SpringMVC 를 이용한 기본 웹 개발도 이제는 거북이 수준이 되어 가고 있는 것 같아 잊지 않기 위해 기록해 봅니다.


요즘 워낙 좋은 Tool, IDE 들이 많이 나와 있고. Git 검색만 해봐도 찾던 소스가 너무나도 많이 나옵니다.

아래는 Intellij community 버전을 이용해서 웹프로젝트 템플릿을 생성하는 예제 입니다.


각 단계별 코드별 설명은 작성 하지 않았습니다.

이유는 여긴 제가 그냥 혼자 기록하고 공부하는 공간이고, 누구를 가르치기에 너무 많은 무림고수 들이 계셔서 어쭙잖은 설명은 그냥 아래 레퍼런스로 대신 합니다.


References)

https://github.com/HowookJeong/springmvc-gradle-template

https://tomcat.apache.org/tomcat-9.0-doc/config/context.html

https://docs.spring.io/spring/docs/4.3.16.RELEASE/spring-framework-reference/htmlsingle/#spring-web


Step 1)

Intellij 를 실행 하고 매뉴에서 아래와 같이 선택을 합니다.


File -> New -> Project -> Gradle -> Java -> Next


GroupId -> org.project.web

ArtifactId -> springmvc-gradle-template

Next


Step 2)

SpringMVC Framework 틀을 만들기 위해 필요한 폴더와 파일들을 아래와 같이 생성을 합니다.


2-1) Community 버전으로는 gradle webapp 추가가 안되기 때문에 별도로 생성 합니다.

Make webapp directory

src/main/webapp


2-2) Make WEB-INF directory

src/main/webapps/WEB-INF

web.xml

dispatcher-servlet.xml


2-3) jsp template 사용을 위해서 WEB-INF 아래 jsp 폴더를 생성 합니다.

Make jsp directory

src/main/webapps/WEB-INF/jsp


2-4) Resource 구성을 합니다.

Make resources directory

src/main/resources/beans

bo-bean.xml

dao-bean.xml

src/main/resources/context

applicationContext.xml

applicationContext-mybatis.xml

src/main/resources/mybatis

config.xml

jdbc.properties

src/main/resources/sql

example.xml

log4j.xml


2-5) Package 구성을 합니다.

Make packages

org.project.web.bo

org.project.web.controllor

org.project.web.dao

org.project.web.model


여기까지 하셨으면 기본 empty project 생성은 끝났습니다.

이제 필요한 코드와 설정을 해보도록 하겠습니다.


Step 3)

이제 필요한 코드들을 생성해 보도록 하겠습니다.


3-1) web.xml 설정하기



3-2) dispatcher-servlet.xml 설정하기



3-3) log4j.xml 설정하기



3-4) mybatis/config.xml 설정하기



3-5) mybatis/jdbc.properties 설정하기



3-6) build.gradle 설정하기



이제 application 구현을 위한 코드 생성을 해보겠습니다.


3-7) controller/ExampleController


3-8) bo/ExampleBO


3-9) bo/ExampleBOImpl


3-10) dao/ExampleDAO


3-11dao/ExampleDAOImpl


3-12) model/ExampleModel



코드 구현을 했으니 이제 resources 설정을 하도록 하겠습니다.


3-13) beans/bo-bean.xml


3-14) beans/dao-bean.xml


3-15) context/applicationContext.xml


3-16) context/applicationContext-mybatis.xml


3-17) sql/example.xml


화면 구성을 위한 데코레이션으로 jsp 코드를 작성해 보겠습니다.


3-18) WEB-INF/jsp/exampleView.jsp


:

[Tomcat] Spring framework 사용 시 중복 실행 이슈

ITWeb/개발일반 2016. 9. 19. 11:08

tomcat + spring 을 사용하면서 startup.sh 를 이용해서 실행 후 로그를 확인해 보면 두 번 실행(로딩) 되는 모습을 확인 할 때가 있습니다.


이렇게 두 번 실행이 될 경우 예상하지 못했던 문제를 가끔 경험 하게 되는데요.

아래와 같이 tomcat 의 server.xml 수정을 통해서 한 번만 실행 되도록 처리 할 수 있습니다.


기존 두 번 실행 되던 server.xml)

    <Engine name="Catalina" defaultHost="localhost">

      <Host name="localhost"  appBase="webapps"

            unpackWARs="false" autoDeploy="false">

        <Context docBase="web-service" path="/" reloadable="false" />

      </Host>

    </Engine>



수정된 server.xml)

    <Engine name="Catalina" defaultHost="localhost">

      <Host name="localhost"  appBase="webapps/web-service"

            unpackWARs="false" autoDeploy="false">

        <Context docBase="" path="/" reloadable="false" />

      </Host>

    </Engine>


그냥 별건 아니지만 scheduler 같은 컴포넌트를 사용하시는 경우 중복 실행이 될 수 있기 때문에 공유해 봅니다.

:

[Intellij] Intellij + SpringMVC + Tomcat

ITWeb/개발일반 2016. 3. 24. 17:29

요즘 한참 web 개발을 안하다 보니 까먹고 산다고나 할까요.

그래서 기억을 돕기 위해 기록 합니다.


프로젝트 생성)

Intellij -> File -> New -> Project -> Maven -> maven-archetype-webapp


Spring MVC 추가)

Current Project -> Mouse Right Click -> Add Framework Support -> Spring MVC


Tomcat 연동)

연동 전에 다운로드를 먼저 받아 놓아야 합니다.

Run -> Edit Configures -> + -> Tomcat Server -> local -> Name 등록


실행은 그냥 Run 으로 등록한 Name 실행 하면 됩니다.


여기서 재밌는 사실 하나!

controller 만들고 jsp 만들어서 "Hello World" 변수 넘겨줘서 찍어 보면 동작 하지 않는 문제가 있습니다.

이것은 바로 servlet-api 의 version 문제 인데요.


위와 같이 spring mvc 프로젝트 생성 하시면 web.xml 에 아래와 같이 선언 됩니다.

<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >

<web-app>


보이시죠 servlet-api 가 2.3 입니다.

근데 제가 선언한건 2.5 ㅡ.ㅡ;

이럴 경우 화면에 변수 출력이 정상적으로 되지 않고 그냥 ${message} 와 같이 출력이 됩니다.

그래서 아래와 같이 수정했습니다.


<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

참 별거 아니지만 모르면 별거가 되는 것이고 알면 별거 아닌게 되고 그렇죠. ^^


:

[eclipse] tomcat 실행 시 java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener 에러

ITWeb/개발일반 2014. 2. 12. 11:14

eclipse 에서 spring mvc 프로젝트 생성하고 tomcat 등록 후 바로 실행 하면 아래와 같은 에러가 발생 할 때가 있습니다.

뭐 다들 아시는 내용이겠지만 기억력을 돕기 위해 기록을 남겨 보도록 하겠습니다.


1. 생성한 프로젝트의 properties  창을엽니다. ( alt + f + enter )

2. Deployment Assembly 를 선택 합니다.

3. 오른쪽 위 Add 버튼을 클릭 합니다.

4. Java Build Path Entries  선택 후 Next 버튼 클릭 합니다.

5. Maven Dependencies  선택 후 Finish 버튼 클릭 합니다.

6. Properties 창 오른쪽 하단의 Apply 버튼 클릭 합니다.

7. Properties 창 오른쪽 하단의 OK 버튼 클릭 후 tomcat 재실행을 해봅니다.



이렇게 하시면 정상적으로 동작 하게 됩니다.

뭐 원인은 빤하죠.

tomcat 에 해당 spring mvc 실행을 위한 class 가 포함이 안되서 그런 것이니 이와 같이 설정만 해주면 끝....


:

[Tomcat] Tomcat 전용 WAS 서버설정.(server.xml]

ITWeb/개발일반 2013. 9. 11. 16:03

일반적인 default 설정 입니다.

tomcat 만 가지고 web application 을 서비스 할때 사용하면 됩니다.

기타 설정 값들은 서비스 특징에 맞춰서 수정 하시면 되겠습니다. (리스너도 필요 없으면 빼도 되겠죠..)


<?xml version='1.0' encoding='utf-8'?>

<Server port="8005" shutdown="SHUTDOWN">

  <Listener SSLEngine="on" className="org.apache.catalina.core.AprLifecycleListener"/>

  <Listener className="org.apache.catalina.core.JasperListener"/>

  <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener"/>

  <Listener className="org.apache.catalina.mbeans.ServerLifecycleListener"/>

  <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener"/>


    <Service name="Catalina">

        <Connector port="8080"

                enableLookups="false"

                protocol="HTTP/1.1"

                URIEncoding="UTF-8"

                compression="on"

                connectionTimeout="5000"

                disableUploadTimeout="false"

                maxHttpHeaderSize="8192"

                maxSpareThreads="75"

                maxThreads="1024"

                minSpareThreads="25" />


    <Engine name="Catalina" defaultHost="localhost">

        <Host name="localhost"  appBase="webapps"

            unpackWARs="true" autoDeploy="true"

            xmlValidation="false" xmlNamespaceAware="false">

        <Context docBase="proxy" path="/" reloadable="true" />

      </Host>

    </Engine>

  </Service>

</Server>


간혹 tomcat 실행 시 manager, host-manager 어쩌구가 없다고 에러 던지면

- tomcat/conf/Catalina 디렉토리를 날려 주세요.


:

solr + tomcat 연동 시 admin 에서 한글 검색 이슈

Elastic/Elasticsearch 2012. 11. 14. 15:50

solr + tomcat 연동은 이미 이전 글에 있습니다.
solr 로 검색해 보시면 되구요.

tomcat 기본설치 후 solr admin 에서 한글이 깨지지 않게 하려면 server.xml 에 아래 내용을 추가해 주셔야 합니다.

뭐 기본이니 다들 아시겠지만.. ^^;

<Connector port="8080" protocol="HTTP/1.1"

               connectionTimeout="20000"

            URIEncoding="UTF-8"

               redirectPort="8443" />

설정 후 재시작 하셔야 합니다. ㅎㅎ

:

Tomcat 에서 IP Restriction 하기.

ITWeb/서버관리 2012. 10. 24. 18:12

뭐 그다지 어렵지 않게 적용이 가능 하내요.


<Engine name="Catalina" defaultHost="localhost">
      <Host name="localhost" appBase="webapps"
       unpackWARs="true" autoDeploy="false"
       xmlValidation="false" xmlNamespaceAware="false">

       <!-- IP Restriction -->
       <Valve className="org.apache.catalina.valves.RemoteAddrValve" allow="10\.101\.254\.\d+, 10\.67\.21\..*"/>

bold 체 처럼 넣으시면 됩니다.

: