eclipse-ee4j / jersey

Eclipse Jersey Project - Read our Wiki:
https://github.com/eclipse-ee4j/jersey/wiki
Other
691 stars 357 forks source link

First call slow between RESOURCE_METHOD_START and real invoke() #5259

Open sc-mickael opened 1 year ago

sc-mickael commented 1 year ago

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.

jansupol commented 1 year ago

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 commented 1 year ago

This looks similar to #5281

sc-mickael commented 1 year ago

Thanks for sharing. I will try.

mkarg commented 4 months ago

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