From 5db0c7b5522fcee34a0d14eac2a12a9a67687da1 Mon Sep 17 00:00:00 2001 From: Steven Schlansker Date: Fri, 14 Jul 2023 14:03:11 -0700 Subject: [PATCH] HttpChannel, AdaptiveExecutionStrategy: improve profiler-friendliness In an application with multiple Jetty instances in one JVM (e.g. integration test) when examining stack frames using the debugger or profiler, most samples that involve user code will have these two frames in their stack. Unfortunately, with a lambda, the different Jetty instances actually have different class names for different lambdas, which causes stack analysis to falsely think the frames are different. It's a little uglier, but by replacing these two specific lambdas with anonymous classes with a stable name, the profiler is able to see that the frames are in fact the same and collapse them, improving observability. --- .../org/eclipse/jetty/server/HttpChannel.java | 16 ++++++++++------ .../strategy/AdaptiveExecutionStrategy.java | 9 ++++++++- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/HttpChannel.java b/jetty-server/src/main/java/org/eclipse/jetty/server/HttpChannel.java index 25841db287c..768bf108fd2 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/HttpChannel.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/HttpChannel.java @@ -494,15 +494,19 @@ public abstract class HttpChannel implements Runnable, HttpOutput.Interceptor if (!_request.hasMetaData()) throw new IllegalStateException("state=" + _state); - dispatch(DispatcherType.REQUEST, () -> + dispatch(DispatcherType.REQUEST, new Dispatchable() { - for (HttpConfiguration.Customizer customizer : _configuration.getCustomizers()) + @Override + public void dispatch() throws IOException, ServletException { - customizer.customize(getConnector(), _configuration, _request); - if (_request.isHandled()) - return; + for (HttpConfiguration.Customizer customizer : _configuration.getCustomizers()) + { + customizer.customize(getConnector(), _configuration, _request); + if (_request.isHandled()) + return; + } + getServer().handle(HttpChannel.this); } - getServer().handle(HttpChannel.this); }); break; diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/thread/strategy/AdaptiveExecutionStrategy.java b/jetty-util/src/main/java/org/eclipse/jetty/util/thread/strategy/AdaptiveExecutionStrategy.java index cae0e352d07..6c163c2617d 100644 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/thread/strategy/AdaptiveExecutionStrategy.java +++ b/jetty-util/src/main/java/org/eclipse/jetty/util/thread/strategy/AdaptiveExecutionStrategy.java @@ -137,7 +137,14 @@ public class AdaptiveExecutionStrategy extends ContainerLifeCycle implements Exe private final Executor _executor; private final TryExecutor _tryExecutor; private final Executor _virtualExecutor; - private final Runnable _runPendingProducer = () -> tryProduce(true); + private final Runnable _runPendingProducer = new Runnable() + { + @Override + public void run() + { + tryProduce(true); + } + }; private State _state = State.IDLE; private boolean _pending;