2011-09-17 1 views
0

glassfish 서버에서 실행되는 웹 페이지가 있습니다. 우리의 jsp 파일에는 아래와 같은 내용물이 많이 있습니다.jsp 파일에 많은 jspf 파일을 포함하면 메모리 사용량이 높습니다.

<jsp:directive.include file="johndoe/foobar.jspf"/> 

이러한 파일은 사용자 선택에 따라 포함됩니다. 우리의 JSP 파일은 다음과 같이 기본적으로 :

<jsp:root version="2.1" xmlns:c="http://java.sun.com/jstl/core_rt" 
xmlns:f="http://java.sun.com/jsf/core" 
xmlns:h="http://java.sun.com/jsf/html" 
xmlns:jsp="http://java.sun.com/JSP/Page" 
xmlns:webuijsf="http://www.sun.com/webui/webuijsf"> 
//some unimportant codes here 
<c:if test="${sessionScope.loadAvgTest}"> 
    //some unimportant codes here 
    <f:subview id="reports15"> 
    <jsp:directive.include file="siforms/sysinfoform.jspf"/> 
    </f:subview> 
    //some unimportant codes here           
    <f:subview id="reports16"> 
    <jsp:directive.include file="siforms/sysinfoformscheduled.jspf"/> 
    </f:subview> 
    //some unimportant codes here 
</c:if> 
//some unimportant codes here 
<c:if test="${sessionScope.bandwidthTest}"> 
    //some unimportant codes here 
    <f:subview id="reports17"> 
    <jsp:directive.include file="mailforms/mailfilter.jspf"/> 
    </f:subview> 
    //some unimportant codes here 
    <f:subview id="reports18"> 
    <jsp:directive.include file="mailforms/mailfilterscheduled.jspf"/> 
    </f:subview> 
//some unimportant codes here 
</c:if> 
.... 

약이있다 (80)의 경우이 같은 문장이 inculdes를 포함하는 각 하나. 이러한 if 절을 많이 삭제하고 몇 가지만 삭제 한 경우 몇 가지를 포함하면 메모리 사용량이 좋았습니다. 하지만 if 절을 많이 사용하면 더 많은 메모리가 포함됩니다. 어떤 아이디어를 어떻게 코드를 최적화 할 수 있습니까? 또는 서블릿 구성을 어떻게 변경하여 메모리 사용량을 줄일 수 있습니까?

답변

1

대신 jsp:directive.includejsp:include이 문제를 해결 사용. 필자가 연구 한 내용에서 알 수 있듯이 jsp:directive.include (지시어 포함)은 컴파일시 JSP 페이지에 파일을 포함하지만 jsp:include에는 런타임에 출력이 포함됩니다.

I have found that, include action (runtime include) runs a bit slower 
yet it is preferred generally because it save a lot of memory of the system. 

(source)

0

JSF를 사용하고 있습니다. 뷰 작성시 if 문이 true로 평가되면 페이지의 JSF 컨트롤이 컴포넌트 트리에 추가됩니다. 서버 측 상태 저장의 경우 이러한 UIComponent 인스턴스와 their state은 (기본적으로) 사용자의 세션에서 지속됩니다. 추가하는 컨트롤이 많을수록 더 많은 메모리를 소비하게됩니다. 기본적으로 이전 뷰의 수가 세션에서 유지됩니다.

당신은 시도 할 수 :

  • 세션에서 뷰의 수를 감소 대형 개체 그래프
  • 를 구축 아니 JSF 버전을 사용
  • (구현을위한 com.sun.faces.numberOfViewsInSessioncom.sun.faces.numberOfLogicalViews 또는 이에 상응하는 초기화 매개 변수를 참조) partial state saving (아직 글래스 피쉬 업그레이드가 필요할 수 있음)
  • 상태를 RAM 외부에 저장하려면 StateManager을 구현하십시오 (예 : 데이터베이스, 그러나 이것은 자신의 문제로 연결) 또는 기본 구현에 저장 클라이언트 측 상태로 전환 (javax.faces.STATE_SAVING_METHOD 참조 -이 보안 문제와 함께 제공 및 응용 프로그램 동작을 변경할 수 있습니다)