doFilter() performance issues
843842Jun 2 2008 — edited Jun 2 2008I have been trying to optimize a doFilter() method to run more quickly than it was previously. In narrowing this down, it seems the my in my doFilter() method body, the action of simply allowing the request to continue with FilterChain.doFilter() is causing major major delays at runtime. I have the following code snippet from a Filter class I have created to show this:
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) {
long before = System.currentTimeMillis();
try {
// Send the request on
chain.doFilter(request,response);
}
catch (IOException io) {
System.out.println ("IOException raised in SimpleFilter");
}
catch (ServletException se) {
System.out.println ("ServletException raised in SimpleFilter");
}
long after = System.currentTimeMillis();
System.out.println("doFilter() execeuted in " + (after - before) + "ms");
}
The output of this usually shows between 5000 and 20000 milliseconds of execution time for simply the chain.doFilter() line.
It doesn't seem others have this same problem, as other examples I have found through google show 10-20 ms execution times.
Here just an example from the output of the code:
doFilter() execeuted in 3312ms
doFilter() execeuted in 0ms
doFilter() execeuted in 0ms
doFilter() execeuted in 140ms
doFilter() execeuted in 1718ms
doFilter() execeuted in 203ms
doFilter() execeuted in 968ms
doFilter() execeuted in 1954ms
doFilter() execeuted in 1984ms
doFilter() execeuted in 2266ms
doFilter() execeuted in 3688ms
doFilter() execeuted in 12625ms
doFilter() execeuted in 15079ms
doFilter() execeuted in 20828ms
doFilter() execeuted in 22204ms
doFilter() execeuted in 22594ms
doFilter() execeuted in 22594ms
Is there something specific that might cause this? I am new to Java and Java Servlets