This is the following answer to the question "jsp include overhead" below:
JSP performance with jsp: include
In our application, developers have “modular” jsp fragments, using “jsp: includes” for “generic” jsp code that repeats throughout the application.
Pros
Pros are as follows:
it DRY - we define the jsp fragment once. This is a great help when you need to change some html and do not need to search / replace / search / destroy.
pretty easy to follow: you pass parameters clearly. When you edit the “included” page, you “know what you are getting,” that is, against some of the “global variables” declared on the inclusion / invocation page.
against
- overhead query performance data
Questions
So, as a continuation:
- How much performance overhead does jsp: include have? This is not obvious from tomcat code (although you can see that it is much more than an inline call). Also, in the profiling of an application that I never requested, the dispasscher.include () or invoke () methods appear as hotspots.
- - , ? (.. X Y). " " (, GC), ?
- ? (AFAIK @include jsp: - ?)
- ( ), jsp , .. " ", "jsp: include" '@include'.
. jsp.
tomcat applicationDispatcher.invoke() (tomcat 5.5. , ). .
private void invoke(ServletRequest request, ServletResponse response,
State state) throws IOException, ServletException {
ClassLoader oldCCL = Thread.currentThread().getContextClassLoader();
ClassLoader contextClassLoader = context.getLoader().getClassLoader();
if (oldCCL != contextClassLoader) {
Thread.currentThread().setContextClassLoader(contextClassLoader);
} else {
oldCCL = null;
}
HttpServletResponse hresponse = (HttpServletResponse) response;
Servlet servlet = null;
IOException ioException = null;
ServletException servletException = null;
RuntimeException runtimeException = null;
boolean unavailable = false;
if (wrapper.isUnavailable()) {
wrapper.getLogger().warn(
sm.getString("applicationDispatcher.isUnavailable",
wrapper.getName()));
long available = wrapper.getAvailable();
if ((available > 0L) && (available < Long.MAX_VALUE))
hresponse.setDateHeader("Retry-After", available);
hresponse.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE, sm
.getString("applicationDispatcher.isUnavailable", wrapper
.getName()));
unavailable = true;
}
try {
if (!unavailable) {
servlet = wrapper.allocate();
}
}
...exception handling here....
ApplicationFilterFactory factory = ApplicationFilterFactory.getInstance();
ApplicationFilterChain filterChain = factory.createFilterChain(request,
wrapper,servlet);
try {
String jspFile = wrapper.getJspFile();
if (jspFile != null)
request.setAttribute(Globals.JSP_FILE_ATTR, jspFile);
else
request.removeAttribute(Globals.JSP_FILE_ATTR);
support.fireInstanceEvent(InstanceEvent.BEFORE_DISPATCH_EVENT,
servlet, request, response);
if ((servlet != null) && (filterChain != null)) {
filterChain.doFilter(request, response);
}
request.removeAttribute(Globals.JSP_FILE_ATTR);
support.fireInstanceEvent(InstanceEvent.AFTER_DISPATCH_EVENT,
servlet, request, response);
}
...exception handling here....
try {
if (filterChain != null)
filterChain.release();
}
...exception handling here....
try {
if (servlet != null) {
wrapper.deallocate(servlet);
}
}
...exception handling here....
if (oldCCL != null)
Thread.currentThread().setContextClassLoader(oldCCL);
unwrapRequest(state);
unwrapResponse(state);
if (ioException != null)
throw ioException;
if (servletException != null)
throw servletException;
if (runtimeException != null)
throw runtimeException;
}