파일 규칙을 많이 사용하는 Java 웹 응용 프로그램이 있습니다.
Tomcat 6을 내 서블릿 컨테이너로 사용하고 있습니다. 많은 요청이 제출되면 Tomcat은 매우 많은 메모리를 필요로하게됩니다. 나는 메모리 소비를 줄이기 위해 tomcat을 미세 조정할 수 있을지 궁금해. 서블릿 컨테이너 변경을 고려 중입니다.
무엇을 제안합니까?Tomcat 메모리 및 CPU 사용량 조정
2
A
답변
4
conf/server.xml
구성에서 허용/작동 가능한 연결 수를 제한 할 수 있습니다.
는
<Executor name="tomcatThreadPool" namePrefix="catalina-exec-"
maxThreads="16" minSpareThreads="1"/>
및
<Connector executor="tomcatThreadPool"
port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443"
/>
또는 설정 파일에
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443"
maxThreads='16'/>
을하고이 브레이크를해야한다.
편집 : 귀하의 의견을 바탕으로 당신이 당신의 CPU 수 (Runtime.getRuntime().availableProcessors()
)에 따라 크기가 전용 스레드 풀에 처리를 움직일 수 (ExecutorService 및 Executors를 참조하십시오.) 그럼 당신은 대기의 수를 스로틀하기 위해 경계 LinkedBlockingQueue을 적용 할 수 작업 (대기열이 가득 차면 차단 추가를 수행하려면 RejectedExecutionHandler을 지정하는 것을 잊지 마십시오).
편집 2 : 클래스에 대한 링크가 추가되었습니다. 거기에서 몇 가지 샘플을 찾습니다.
편집 3 : 프로젝트에서 사용한 샘플 방법.
/**
* Creates a new thread pool based on some attributes
* @param poolSize the number of worker threads in the thread pool
* @param poolName the name of the thread pool (for debugging purposes)
* @param priority the base priority of the worker threads
* @param capacity the size of the task queue used
* @return the ExecutorService object
*/
private ExecutorService newPool(int poolSize,
String poolName, final int priority, int capacity) {
int cpu = Runtime.getRuntime().availableProcessors();
ExecutorService result = null;
if (poolSize != 0) {
if (poolSize == -1) {
poolSize = cpu;
}
if (capacity <= 0) {
capacity = Integer.MAX_VALUE;
}
result = new ThreadPoolExecutor(poolSize, poolSize,
120, TimeUnit.MINUTES,
new LinkedBlockingQueue<Runnable>(capacity),
new ThreadFactory() {
@Override
public Thread newThread(Runnable runnable) {
Thread t = new Thread(runnable);
t.setPriority(priority);
return t;
}
}, new RejectedExecutionHandler() {
@Override
public void rejectedExecution(Runnable r,
ThreadPoolExecutor executor) {
if (!executor.isShutdown()) {
try {
executor.getQueue().put(r);
} catch (InterruptedException ex) {
// give up
}
}
}
});
}
return result;
}
그리고 당신은이 방법을 사용할 수 있습니다
ExecutorService exec = newPool(-1, "converter pool", Thread.NORM_PRIORITY, 500);
servletContext.setAttribute("converter pool", exec);
그리고 서블릿에서
는 "파일 규칙을 많이 작업"무엇을 의미합니까ExecutorService exec = (ExecutorService)servletContext
.getAttribute("converter pool");
exec.submit(new Runnable() {
public void run() {
// your code for transformation goes here
}
}
관련 문제
- 1. 메모리 사용량 VS. iphone의 CPU 사용량
- 2. Windows 7에서 메모리 및 CPU 사용량 변경
- 3. 성능 문제 - 메모리 및 CPU 사용량 증가
- 4. 추적 스레드 메모리 및 CPU 사용량
- 5. 파이썬 및 메모리 사용량
- 6. 리눅스에서 프로세스 메모리/CPU 사용량 제한
- 7. 안드로이드에서 응용 프로그램에 의한 메모리 (CPU) 사용량
- 8. HPUX에서 응용 프로그램의 CPU 및 메모리 사용량 프로그래밍 방식으로
- 9. 델파이에서 100 % CPU 사용량
- 10. nanosleep 높은 CPU 사용량?
- 11. 측정 할 수없는 CPU 사용량?
- 12. Eclipse 디버그 메모리 사용량
- 13. Firefox 플러그인 CPU 사용량
- 14. clr.sll! StrongNameSignatureVerification CPU 사용량
- 15. 내 프로세스의 CPU 사용량
- 16. WinCE에서 CPU 사용량 결정
- 17. SQL BOX의 CPU 사용량
- 18. 플래시에서 CPU 사용량과 CPU 메모리 사용량을 얻으시겠습니까?
- 19. Comet, responseText 및 메모리 사용량
- 20. 데이터베이스 인덱스 및 메모리 사용량
- 21. Settimeout 및 setinterval 메모리 사용량
- 22. 메모리 사용량
- 23. 이유없이 파이썬/유휴 CPU 사용량
- 24. Silverlight MultiScaleImage 컨트롤 버그 및 CPU 사용량
- 25. WMI 및 C를 사용하는 CPU 사용량
- 26. Android 에뮬레이터에서 CPU 사용량 및 FPS 표시
- 27. 주 스레드 + 스레드 풀 및 CPU 사용량
- 28. SQL 메모리 사용량
- 29. 자바 응용 프로그램의 메모리와 CPU 사용량
- 30. Android 소켓 높은 CPU 사용량
를? –