jersey icon indicating copy to clipboard operation
jersey copied to clipboard

First call slow between RESOURCE_METHOD_START and real invoke()

Open sc-mickael opened this issue 2 years ago • 4 comments

Java : 8 Jersey : 2.35 Spring : 5.1.5.RELEASE com.google.appengine.tools : 0.8.2

On my production server, first call of my REST API took a while. After a lot of research, it seems that something happen in Jersey at ResourceMethodInvoker class.

The ResourceMethodInvoker class in method invoke calls context.triggerEvent(RequestEvent.Type.RESOURCE_METHOD_START); then this.dispatcher.dispatch(resource, context.request()); and finally, calls AbstractJavaResourceMethodDispatcher.invoke() which create invokeMethodAction

For some reason, the first call in production can take 2 secondes between the triggerEvent and invokeMethodAction In logs, i see RESOURCE_METHOD_START, but only 2 secondes after, i really enter in my Controller.

The second call is faster and took only some ms.

What happen ? Is it normal ?

Any idea ?

Thanks.

sc-mickael avatar Feb 14 '23 10:02 sc-mickael

Two seconds is a long time, that is odd. The first request is always slower as java warms up, but two seconds may suggest some issue.

context.triggerEvent(RequestEvent.Type.RESOURCE_METHOD_START) should not take any time, unless you have the ServerProperties.MONITORING_ENABLED set to true.

Some profiling tools would be needed to test in your environment to see what happens. For start, JFR could help (for instance java -XX:+FlightRecorder -XX:StartFlightRecording=delay=0s,duration=3s,name=myrecording,filename=myrecording.jfr,settings=profile --enable-preview).

jansupol avatar Mar 02 '23 13:03 jansupol

This looks similar to #5281

jansupol avatar Mar 25 '23 17:03 jansupol

Thanks for sharing. I will try.

sc-mickael avatar Mar 25 '23 17:03 sc-mickael

@sc-mickael Could you please share your result? :-)

mkarg avatar Jul 31 '24 21:07 mkarg