diff --git a/jetty-io/src/main/java/org/eclipse/jetty/io/ManagedSelector.java b/jetty-io/src/main/java/org/eclipse/jetty/io/ManagedSelector.java index 2a4111b1313..9377118b6be 100644 --- a/jetty-io/src/main/java/org/eclipse/jetty/io/ManagedSelector.java +++ b/jetty-io/src/main/java/org/eclipse/jetty/io/ManagedSelector.java @@ -40,9 +40,12 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; import org.eclipse.jetty.util.IO; +import org.eclipse.jetty.util.annotation.ManagedAttribute; +import org.eclipse.jetty.util.annotation.ManagedOperation; import org.eclipse.jetty.util.component.ContainerLifeCycle; import org.eclipse.jetty.util.component.Dumpable; import org.eclipse.jetty.util.component.DumpableCollection; +import org.eclipse.jetty.util.statistic.SampleStatistic; import org.eclipse.jetty.util.thread.AutoLock; import org.eclipse.jetty.util.thread.ExecutionStrategy; import org.eclipse.jetty.util.thread.Scheduler; @@ -84,6 +87,7 @@ public class ManagedSelector extends ContainerLifeCycle implements Dumpable private Selector _selector; private Deque _updates = new ArrayDeque<>(); private Deque _updateable = new ArrayDeque<>(); + private final SampleStatistic _keyStats = new SampleStatistic(); public ManagedSelector(SelectorManager selectorManager, int id) { @@ -141,6 +145,36 @@ public class ManagedSelector extends ContainerLifeCycle implements Dumpable super.doStop(); } + @ManagedAttribute(value = "Total number of keys", readonly = true) + public int getTotalKeys() + { + return _selector.keys().size(); + } + + @ManagedAttribute(value = "Average number of selected keys", readonly = true) + public double getAverageSelectedKeys() + { + return _keyStats.getMean(); + } + + @ManagedAttribute(value = "Maximum number of selected keys", readonly = true) + public double getMaxSelectedKeys() + { + return _keyStats.getMax(); + } + + @ManagedAttribute(value = "Total number of select() calls", readonly = true) + public long getSelectCount() + { + return _keyStats.getCount(); + } + + @ManagedOperation(value = "Resets the statistics", impact = "ACTION") + public void resetStats() + { + _keyStats.reset(); + } + protected int nioSelect(Selector selector, boolean now) throws IOException { return now ? selector.selectNow() : selector.select(); @@ -584,9 +618,12 @@ public class ManagedSelector extends ContainerLifeCycle implements Dumpable } _keys = selector.selectedKeys(); - _cursor = _keys.isEmpty() ? Collections.emptyIterator() : _keys.iterator(); + int selectedKeys = _keys.size(); + if (selectedKeys > 0) + _keyStats.record(selectedKeys); + _cursor = selectedKeys > 0 ? _keys.iterator() : Collections.emptyIterator(); if (LOG.isDebugEnabled()) - LOG.debug("Selector {} processing {} keys, {} updates", selector, _keys.size(), updates); + LOG.debug("Selector {} processing {} keys, {} updates", selector, selectedKeys, updates); return true; } diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/Request.java b/jetty-server/src/main/java/org/eclipse/jetty/server/Request.java index 7423dc172d2..49b2b71f135 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/Request.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/Request.java @@ -2079,7 +2079,7 @@ public class Request implements HttpServletRequest * Set the character encoding used for the query string. This call will effect the return of getQueryString and getParamaters. It must be called before any * getParameter methods. * - * The request attribute "org.eclipse.jetty.server.server.Request.queryEncoding" may be set as an alternate method of calling setQueryEncoding. + * The request attribute "org.eclipse.jetty.server.Request.queryEncoding" may be set as an alternate method of calling setQueryEncoding. * * @param queryEncoding the URI query character encoding */