users@jersey.java.net

[Jersey] Jersey server inefficiency?

From: Mikael Ståldal <mikael.staldal_at_appearnetworks.com>
Date: Fri, 29 Aug 2014 12:04:33 +0200

I am using Jersey server 2.12 to implement a web service.

It seems to me that Jersey server requires all request handling threads to
pass through a sychronized lock in
org.jvnet.hk2.internal.Utilities(Utilities.java:148), below is a stack
trace I was able to capture during a load test with a lot of concurrent
requests (Java 7, Jetty 9.2.2). Several threads were waiting for the same
lock.

It's not a deadlock, but it could be something which significantly reduces
scalability of Jersey when you have many concurrent requests and several
CPU cores available.


"qtp330351192-119" prio=10 tid=0x00007f3710017800 nid=0x321f waiting for
monitor entry [0x00007f36b98d5000]
   java.lang.Thread.State: BLOCKED (on object monitor)
        at
org.jvnet.hk2.internal.Utilities.computeElementAnnotationInfo(Utilities.java:1576)
        - waiting to lock <0x00000000c06a27b8> (a java.lang.Object)
        at
org.jvnet.hk2.internal.Utilities.getInjectAnnotation(Utilities.java:1609)
        at
org.jvnet.hk2.internal.Utilities.getInjectionResolver(Utilities.java:1854)
        at
org.jvnet.hk2.internal.Utilities.getInjectionResolver(Utilities.java:1886)
        at org.jvnet.hk2.internal.Utilities.justInject(Utilities.java:938)
        at
org.jvnet.hk2.internal.ServiceLocatorImpl.inject(ServiceLocatorImpl.java:902)
        at
org.jvnet.hk2.internal.ServiceLocatorImpl.inject(ServiceLocatorImpl.java:892)
        at
org.glassfish.jersey.server.internal.inject.AbstractValueFactoryProvider.getValueFactory(AbstractValueFactoryProvider.java:136)
        at
org.glassfish.jersey.server.spi.internal.ParameterValueHelper.getValueFactory(ParameterValueHelper.java:145)
        at
org.glassfish.jersey.server.spi.internal.ParameterValueHelper.createValueProviders(ParameterValueHelper.java:124)
        at
org.glassfish.jersey.server.model.Invocable.getValueProviders(Invocable.java:322)
        at
org.glassfish.jersey.server.model.ResourceMethodValidator.checkValueProviders(ResourceMethodValidator.java:164)
        at
org.glassfish.jersey.server.model.ResourceMethodValidator.checkMethod(ResourceMethodValidator.java:106)
        at
org.glassfish.jersey.server.model.ResourceMethodValidator.visitJaxrsResourceMethod(ResourceMethodValidator.java:102)
        at
org.glassfish.jersey.server.model.ResourceMethodValidator.visitResourceMethod(ResourceMethodValidator.java:92)
        at
org.glassfish.jersey.server.model.ResourceMethod.accept(ResourceMethod.java:854)
        at
org.glassfish.jersey.server.model.ComponentModelValidator.validateWithErrors(ComponentModelValidator.java:161)
        at
org.glassfish.jersey.server.model.ComponentModelValidator.validateWithErrors(ComponentModelValidator.java:167)
        at
org.glassfish.jersey.server.model.ComponentModelValidator.validateWithErrors(ComponentModelValidator.java:167)
        at
org.glassfish.jersey.server.model.ComponentModelValidator.validateWithErrors(ComponentModelValidator.java:167)
        at
org.glassfish.jersey.server.model.ComponentModelValidator.access$000(ComponentModelValidator.java:90)
        at
org.glassfish.jersey.server.model.ComponentModelValidator$1.run(ComponentModelValidator.java:151)
        at org.glassfish.jersey.internal.Errors$1.call(Errors.java:271)
        at org.glassfish.jersey.internal.Errors$1.call(Errors.java:267)
        at org.glassfish.jersey.internal.Errors.process(Errors.java:315)
        at org.glassfish.jersey.internal.Errors.process(Errors.java:297)
        at org.glassfish.jersey.internal.Errors.process(Errors.java:267)
        at
org.glassfish.jersey.server.model.ComponentModelValidator.validate(ComponentModelValidator.java:146)
        at
org.glassfish.jersey.server.internal.routing.SubResourceLocatorRouter$1.run(SubResourceLocatorRouter.java:205)
        at org.glassfish.jersey.internal.Errors$1.call(Errors.java:271)
        at org.glassfish.jersey.internal.Errors$1.call(Errors.java:267)
        at org.glassfish.jersey.internal.Errors.process(Errors.java:315)
        at org.glassfish.jersey.internal.Errors.process(Errors.java:297)
        at org.glassfish.jersey.internal.Errors.process(Errors.java:267)
        at
org.glassfish.jersey.server.internal.routing.SubResourceLocatorRouter.validate(SubResourceLocatorRouter.java:201)
        at
org.glassfish.jersey.server.internal.routing.SubResourceLocatorRouter.apply(SubResourceLocatorRouter.java:160)
        at
org.glassfish.jersey.server.internal.routing.RoutingStage._apply(RoutingStage.java:112)
        at
org.glassfish.jersey.server.internal.routing.RoutingStage._apply(RoutingStage.java:115)
        at
org.glassfish.jersey.server.internal.routing.RoutingStage._apply(RoutingStage.java:115)
        at
org.glassfish.jersey.server.internal.routing.RoutingStage._apply(RoutingStage.java:115)
        at
org.glassfish.jersey.server.internal.routing.RoutingStage._apply(RoutingStage.java:115)
        at
org.glassfish.jersey.server.internal.routing.RoutingStage._apply(RoutingStage.java:115)
        at
org.glassfish.jersey.server.internal.routing.RoutingStage._apply(RoutingStage.java:115)
        at
org.glassfish.jersey.server.internal.routing.RoutingStage._apply(RoutingStage.java:115)
        at
org.glassfish.jersey.server.internal.routing.RoutingStage._apply(RoutingStage.java:115)
        at
org.glassfish.jersey.server.internal.routing.RoutingStage._apply(RoutingStage.java:115)
        at
org.glassfish.jersey.server.internal.routing.RoutingStage._apply(RoutingStage.java:115)
        at
org.glassfish.jersey.server.internal.routing.RoutingStage._apply(RoutingStage.java:115)
        at
org.glassfish.jersey.server.internal.routing.RoutingStage._apply(RoutingStage.java:115)
        at
org.glassfish.jersey.server.internal.routing.RoutingStage._apply(RoutingStage.java:115)
        at
org.glassfish.jersey.server.internal.routing.RoutingStage._apply(RoutingStage.java:115)
        at
org.glassfish.jersey.server.internal.routing.RoutingStage._apply(RoutingStage.java:115)
        at
org.glassfish.jersey.server.internal.routing.RoutingStage._apply(RoutingStage.java:115)
        at
org.glassfish.jersey.server.internal.routing.RoutingStage.apply(RoutingStage.java:94)
        at
org.glassfish.jersey.server.internal.routing.RoutingStage.apply(RoutingStage.java:63)
        at
org.glassfish.jersey.process.internal.Stages.process(Stages.java:197)
        at
org.glassfish.jersey.server.ServerRuntime$1.run(ServerRuntime.java:263)
        at org.glassfish.jersey.internal.Errors$1.call(Errors.java:271)
        at org.glassfish.jersey.internal.Errors$1.call(Errors.java:267)
        at org.glassfish.jersey.internal.Errors.process(Errors.java:315)
        at org.glassfish.jersey.internal.Errors.process(Errors.java:297)
        at org.glassfish.jersey.internal.Errors.process(Errors.java:267)
        at
org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:297)
        at
org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:254)
        at
org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:1030)
        at
org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:373)
        at
org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:381)
        at
org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:344)
        at
org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:221)
        at
org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:769)

-- 
Mikael Ståldal
Chief Software Architect
*Appear*
Phone: +46 8 545 91 572
Email: mikael.staldal_at_appearnetworks.com