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

Fixes #5787 - Make ManagedSelector report better JMX data. #5910

Merged
merged 1 commit into from
Feb 3, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 39 additions & 2 deletions jetty-io/src/main/java/org/eclipse/jetty/io/ManagedSelector.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,14 @@
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.log.Log;
import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.util.statistic.SampleStatistic;
import org.eclipse.jetty.util.thread.ExecutionStrategy;
import org.eclipse.jetty.util.thread.Scheduler;
import org.eclipse.jetty.util.thread.strategy.EatWhatYouKill;
Expand Down Expand Up @@ -86,6 +89,7 @@ public class ManagedSelector extends ContainerLifeCycle implements Dumpable
private Selector _selector;
private Deque<SelectorUpdate> _updates = new ArrayDeque<>();
private Deque<SelectorUpdate> _updateable = new ArrayDeque<>();
private final SampleStatistic _keyStats = new SampleStatistic();

public ManagedSelector(SelectorManager selectorManager, int id)
{
Expand Down Expand Up @@ -144,6 +148,36 @@ protected void doStop() throws Exception
super.doStop();
}

@ManagedAttribute(value = "Total number of keys", readonly = true)
public int getTotalKeys()
Copy link
Contributor

Choose a reason for hiding this comment

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

Rename this getTotalSelectableKeys maybe?

{
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()
Copy link
Contributor

Choose a reason for hiding this comment

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

Are you really sure we want to expose this?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it is good to have and easy to ignore if you don't want to use it.

{
_keyStats.reset();
}

protected int nioSelect(Selector selector, boolean now) throws IOException
{
return now ? selector.selectNow() : selector.select();
Expand Down Expand Up @@ -586,9 +620,12 @@ private boolean select()
}

_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;
}
Expand Down