Jetty 9.4.x single context optimisation (#4909)

* Optimisation for single context

It is a frequent deployment mode to have only a single context.
In that case, the ContextHandlerCollection can bypass a bit of
looping/matching/selecting and just call the single context,
which it works out itself anyway if the request applies to it.

Signed-off-by: Greg Wilkins <gregw@webtide.com>

* Optimisation for single context

updates from review

Signed-off-by: Greg Wilkins <gregw@webtide.com>
This commit is contained in:
Greg Wilkins 2020-05-27 09:53:13 +02:00 committed by GitHub
parent 2b1fa80b63
commit e82cacfdb6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 18 additions and 7 deletions

View File

@ -176,11 +176,23 @@ public class ContextHandlerCollection extends HandlerCollection
@Override
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
{
Handlers handlers = _handlers.get();
if (handlers == null)
Mapping mapping = (Mapping)_handlers.get();
// Handle no contexts
if (mapping == null)
return;
Handler[] handlers = mapping.getHandlers();
if (handlers == null || handlers.length == 0)
return;
Mapping mapping = (Mapping)handlers;
// handle only a single context.
if (handlers.length == 1)
{
handlers[0].handle(target, baseRequest, request, response);
return;
}
// handle async dispatch to specific context
HttpChannelState async = baseRequest.getHttpChannelState();
if (async.isAsync())
{
@ -197,6 +209,7 @@ public class ContextHandlerCollection extends HandlerCollection
}
}
// handle many contexts
if (target.startsWith("/"))
{
Trie<Map.Entry<String, Branch[]>> pathBranches = mapping._pathBranches;
@ -229,11 +242,9 @@ public class ContextHandlerCollection extends HandlerCollection
}
else
{
if (mapping.getHandlers() == null)
return;
for (int i = 0; i < mapping.getHandlers().length; i++)
for (Handler handler : handlers)
{
mapping.getHandlers()[i].handle(target, baseRequest, request, response);
handler.handle(target, baseRequest, request, response);
if (baseRequest.isHandled())
return;
}