jersey
  1. jersey
  2. JERSEY-1317

Tomcat 7 slow startup time with Jersey (1.13) deployed

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Invalid
    • Affects Version/s: 1.13
    • Fix Version/s: 1.17
    • Component/s: containers
    • Labels:
      None
    • Environment:

      Windows 7, jdk1.6.0_30, apache-tomcat-7.0.29, jersey-archive-1.13, eclipselink-2.3.1

      Description

      Time for launch Tomcat without Jersey is 1 second.
      When I add the jars of Jersey to tomcat/lib directory, the time for launch goes for 30 seconds.
      It doesn't matter which application I deploy - even if no application is deployed (no servlets) it takes that time. However the server already contains jars of Selenium and EclipseLink.

      The jar that cause the problem is jersey-servlet-1.13. When I remove it from lib directory, launch time goes normal again. I suspect that the services defined in that jar (\META-INF\services*) cause the trouble but couldn't find the exact cause...

      I'm not sure if it's a bug but it's definitively a problem.
      My motivation for choosing Tomcat was performance, and if Jersey hurts that performance it's a problem.

      Steps to reproduce:
      1. download and extract apache-tomcat-7.0.29
      2. copy to tomcat/lib directory the following jars from eclipselink-2.3.1 (JPA):
      a) eclipselink.jar
      b) javax.persistence_2.0.3.v201010191057.jar
      3. copy to tomcat/lib directory the following jars from selenium-2.24.1:
      a) selenium-java-2.24.1.jar
      b) all jars from lib directory (36 jars)
      4. run tomcat/bin/startup.bat and make sure (using logs) the startup time is few seconds at most.
      On my machine it takes less than 1 second.
      5. run shutdown.bat
      6. copy to tomcat/lib directory the following jars from jersey-archive-1.12.zip:
      a) asm-3.1.jar
      b) jersey-core-1.12.jar
      c) jersey-server-1.12.jar
      d) jersey-servlet-1.12.jar
      (As far as I know this is the minimum required to use Jersey)
      7. run startup.bat again.
      On my machine it takes now more than 30 seconds.

        Activity

        Hide
        gamliela added a comment - - edited

        The same problem occurs on both versions of Jersey - 1.12 & 1.13.
        Also please fix the download link for 1.13 (it still points to 1.12).

        Show
        gamliela added a comment - - edited The same problem occurs on both versions of Jersey - 1.12 & 1.13. Also please fix the download link for 1.13 (it still points to 1.12).
        Hide
        Marek Potociar added a comment -

        Michal, can you please evaluate?

        Show
        Marek Potociar added a comment - Michal, can you please evaluate?
        Hide
        Michal Gajdos added a comment - - edited

        This is not a Jersey bug although the jersey-servlet.jar makes Tomcat to perform some additional classpath scanning. The jersey-servlet.jar adds a capability for Servlet3 initialization which Tomcat7 supports. Since you put Jersey jars into tomcat/lib directory then the Jersey implementation of ServletContainerInitializer is invoked for every webapp (present in tomcat\webapps) during it's deployment. Before the invocation of the JerseyServletContainerInitializer the Tomcat does classpath scanning to provide requested classes to this initializer (which slows down the startup).

        There are two ways to solve this issue:

        • if you do not need/use Servlet3 capabilities, you can remove the META-INF/services/javax.servlet.ServletContainerInitializer file from jersey-servlet.jar so that the JerseyServletContainerInitializer is not recognized by Tomcat and hence no classpath scanning is performed for this initializer.
        • if you want to use Servlet3 then pack the Jersey jars with the webapp to ensure the JerseyServletContainerInitializer is invoked only for this webapp (Tomcat will do the classpath scanning only for webapps containing the jersey-servlet.jar)

        Edit: Thanks for noticing the incorrect download link.

        Show
        Michal Gajdos added a comment - - edited This is not a Jersey bug although the jersey-servlet.jar makes Tomcat to perform some additional classpath scanning. The jersey-servlet.jar adds a capability for Servlet3 initialization which Tomcat7 supports. Since you put Jersey jars into tomcat/lib directory then the Jersey implementation of ServletContainerInitializer is invoked for every webapp (present in tomcat\webapps ) during it's deployment. Before the invocation of the JerseyServletContainerInitializer the Tomcat does classpath scanning to provide requested classes to this initializer (which slows down the startup). There are two ways to solve this issue: if you do not need/use Servlet3 capabilities, you can remove the META-INF/services/javax.servlet.ServletContainerInitializer file from jersey-servlet.jar so that the JerseyServletContainerInitializer is not recognized by Tomcat and hence no classpath scanning is performed for this initializer. if you want to use Servlet3 then pack the Jersey jars with the webapp to ensure the JerseyServletContainerInitializer is invoked only for this webapp (Tomcat will do the classpath scanning only for webapps containing the jersey-servlet.jar ) Edit: Thanks for noticing the incorrect download link.

          People

          • Assignee:
            Michal Gajdos
            Reporter:
            gamliela
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Time Tracking

              Estimated:
              Original Estimate - Not Specified
              Not Specified
              Remaining:
              Remaining Estimate - 0 minutes
              0m
              Logged:
              Time Spent - 5 hours
              5h