https://bz.apache.org/bugzilla/show_bug.cgi?id=61810

            Bug ID: 61810
           Summary: [Proposal] Support configure the interval to keep all
                    jars open if no jar is accessed
           Product: Tomcat 7
           Version: trunk
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: Catalina
          Assignee: dev@tomcat.apache.org
          Reporter: huxing.zh...@gmail.com
  Target Milestone: ---

The Problem:

When the traffic spikes, the web application's business thread pool becomes
full.

Jstack shows one of the thread is holding a lock that block most of other
threads. The stack trace is as follows:

"HSFBizProcessor-DEFAULT-12-thread-332" Id=10156 RUNNABLE
        at java.util.zip.ZipFile.open(Native Method)
        at java.util.zip.ZipFile.<init>(ZipFile.java:219)
        at java.util.zip.ZipFile.<init>(ZipFile.java:149)
        at java.util.jar.JarFile.<init>(JarFile.java:166)
        at java.util.jar.JarFile.<init>(JarFile.java:130)
        at
org.apache.catalina.loader.WebappClassLoaderBase.openJARs(WebappClassLoaderBase.java:3120)
        at
org.apache.catalina.loader.WebappClassLoaderBase.findResourceInternal(WebappClassLoaderBase.java:3409)
        -  locked [Ljava.util.jar.JarFile;@972f6eb
        at
org.apache.catalina.loader.WebappClassLoaderBase.findClassInternal(WebappClassLoaderBase.java:3152)
        at
org.apache.catalina.loader.WebappClassLoaderBase.findClass(WebappClassLoaderBase.java:1373)
        at
org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1861)
        -  locked org.apache.catalina.loader.WebappClassLoader@726ec590


We have a web application who has ~800 jar files under WEB-INF/lib. By default
tomcat will close all the JarFile objects if there is no access to the jar file
after 90s, which is hard-coded.

However, if at some point, we need to load a class that is not loaded before,
tomcat will have to open all the jar files before trying to load the class.
What makes matter worse is that, the disk is HDD, which makes Opening ~800 jar
files quite time consuming, eventually cause this operation to block all other
threads.


Lessons learned:

Enable parallel class loading, so that one thread trying to load a class don't
block other threads. However, if multiple threads trying to load the same
class, the issue might still happen.


New Proposal:

>From my point of view, the reason why Tomcat close all the jars opened is to
release the file descriptors to save resources. If resource is not a problem,
we can keeps all the jar opened for a fairly long time, or even keeps them
always opened. 

Therefore, we propose to introduce a new attribute, called 'jarOpenInterval',
in WebappClassLoaderBase, to track the interval that can keep all the jars
opened if they are not accessed. The default value is 90000 milliseconds, which
is the same as the current implementation. The attribute can be configured in
two ways:

1. static configuration in context.xml

<Loader jarOpenInterval="90000" />

2. dynamic configuration via JMX. This value should be changed during runtime.


Any thoughts?

p.s. About the default value for jarOpenInterval, I found that Tomcat 8+ has
removed the implementation of the close jar operation, which indeed will hold
all the file descriptors during start up. Does that mean that holding all the
file descriptor is not a issue any more? Can we keep all jars open by default?

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to