Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jetty 12 recycle servlet channel #8909

Merged
merged 16 commits into from
Nov 24, 2022
Merged

Conversation

gregw
Copy link
Contributor

@gregw gregw commented Nov 17, 2022

Implement TODO's in ee10-servlet regarding Jetty 12 recycling of ServletChannel

@lachlan-roberts
Copy link
Contributor

@gregw Looks like there was some failure with this PR on Jenkins.

@@ -47,9 +47,10 @@ class AsyncContentProducer implements ContentProducer
private long _firstByteNanoTime = Long.MIN_VALUE;
private long _rawBytesArrived;

AsyncContentProducer(ServletChannel servletChannel)
AsyncContentProducer(ServletChannel servletChannel, AutoLock lock)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This constructor should have a comment to explain why locking is now being controlled externally.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@gregw gregw requested a review from janbartel November 22, 2022 00:32

public ServletChannel(ServletContextHandler servletContextHandler, Request request)
{
_state = new ServletRequestState(this);
_context = servletContextHandler.getContext();
_servletContextApi = _context.getServletContext();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couldn't this be recycled and go through a different ServletContextHandler which would have a different ServletContextApi?

If so then this would need to be done in associate().

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, see the test when we reuse a ServletChannel that it is for the same context, else we create a new one.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it be better to have a ServletChannel which could be re-used for any context instead of always remaking it if it goes to a different context.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah maybe, but as @lorban would say, that is optimizing the slow path. Cross context requests are rare and many deployments only have 1 context per server.
Having these big objects with lots of final fields increases the benefit of re-using them, as all those final fields don't need to be re-enabled.

So I'm happy with it as is for now. Perhaps if we see cross context slowness as a problem in future we invest in a reusable instance per context?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, at least its better than before so I'll approve.

I can't see that there would be much extra cost to making it fully re-usable though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe, but I don't really know the cost of creating new ServletContextAPI instances for each request. I'd much rather reuse them most of the time and then make a new one only if changing contexts.

@gregw
Copy link
Contributor Author

gregw commented Nov 23, 2022

@janbartel @lachlan-roberts re-review please

@gregw gregw merged commit 2460b86 into jetty-12.0.x Nov 24, 2022
@gregw gregw deleted the jetty-12-recycle-ServletChannel branch November 24, 2022 02:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants