Mercurial Hosting > luan
changeset 951:e542a9cc75ef
simplify SelectorManager
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Wed, 12 Oct 2016 18:12:12 -0600 |
parents | a778413aefc0 |
children | 669769bcdf5c |
files | src/org/eclipse/jetty/io/nio/SelectorManager.java |
diffstat | 1 files changed, 6 insertions(+), 121 deletions(-) [+] |
line wrap: on
line diff
diff -r a778413aefc0 -r e542a9cc75ef src/org/eclipse/jetty/io/nio/SelectorManager.java --- a/src/org/eclipse/jetty/io/nio/SelectorManager.java Wed Oct 12 14:37:56 2016 -0600 +++ b/src/org/eclipse/jetty/io/nio/SelectorManager.java Wed Oct 12 18:12:12 2016 -0600 @@ -58,11 +58,6 @@ { public static final Logger LOG=LoggerFactory.getLogger("org.eclipse.jetty.io.nio"); - private static final int __MONITOR_PERIOD=Integer.getInteger("org.eclipse.jetty.io.nio.MONITOR_PERIOD",1000).intValue(); - private static final int __MAX_SELECTS=Integer.getInteger("org.eclipse.jetty.io.nio.MAX_SELECTS",100000).intValue(); - private static final int __BUSY_PAUSE=Integer.getInteger("org.eclipse.jetty.io.nio.BUSY_PAUSE",50).intValue(); - private static final int __IDLE_TICK=Integer.getInteger("org.eclipse.jetty.io.nio.IDLE_TICK",400).intValue(); - private int _maxIdleTime; private long _lowResourcesConnections; private SelectSet[] _selectSet; @@ -74,9 +69,9 @@ * @param maxIdleTime The maximum period in milli seconds that a connection may be idle before it is closed. * @see #setLowResourcesMaxIdleTime(long) */ - public void setMaxIdleTime(long maxIdleTime) + public void setMaxIdleTime(int maxIdleTime) { - _maxIdleTime=(int)maxIdleTime; + _maxIdleTime = maxIdleTime; } /* ------------------------------------------------------------ */ @@ -212,7 +207,6 @@ super.doStop(); } - /* ------------------------------------------------------------------------------- */ public abstract AsyncConnection newConnection(SocketChannel channel, AsyncEndPoint endpoint, Object attachment); public String dump() @@ -235,22 +229,14 @@ private volatile SaneSelector _selector; private volatile Thread _selecting; - private int _busySelects; - private long _monitorNext; - private boolean _pausing; - private boolean _paused; - private volatile long _idleTick; private ConcurrentMap<SelectChannelEndPoint,Object> _endPoints = new ConcurrentHashMap<SelectChannelEndPoint, Object>(); SelectSet(int acceptorID) throws Exception { _setID=acceptorID; - _idleTick = System.currentTimeMillis(); - // create a selector; _selector = new SaneSelector(); - _monitorNext=System.currentTimeMillis()+__MONITOR_PERIOD; } private void addChange(SocketChannel channel) @@ -285,66 +271,7 @@ if (selector == null) return; - // Do and instant select to see if any connections can be handled. -// int selected = selector.selectNow(); - int selected = selector.select(); - - _now = System.currentTimeMillis(); -/* - // if no immediate things to do - if (selected==0 && selector.selectedKeys().isEmpty()) - { - - // If we are in pausing mode - if (_pausing) - { - try - { - Thread.sleep(__BUSY_PAUSE); // pause to reduce impact of busy loop - } - catch(InterruptedException e) - { - LOG.trace("",e); - } - _now = System.currentTimeMillis(); - } - - // workout how long to wait in select - long wait = __IDLE_TICK; - - // If we should wait with a select - if (wait>0) - { - long before = _now; - selector.select(wait); -// selector.select(10000L); - _now = System.currentTimeMillis(); - - // If we are monitoring for busy selector - // and this select did not wait more than 1ms - if (__MONITOR_PERIOD>0 && _now-before <=1) - { - // count this as a busy select and if there have been too many this monitor cycle - if (++_busySelects>__MAX_SELECTS) - { - // Start injecting pauses - _pausing=true; - - // if this is the first pause - if (!_paused) - { - // Log and dump some status - _paused=true; - LOG.warn("Selector {} is too busy, pausing!",this); - } - } - } - } - } -*/ - // have we been destroyed while sleeping - if (_selector==null || !selector.isOpen()) - return; + selector.select(); // Look for things to do for (SelectionKey key: selector.selectedKeys()) @@ -439,38 +366,6 @@ selector.selectedKeys().clear(); _now = System.currentTimeMillis(); -/* - // Idle tick - if (_now-_idleTick>__IDLE_TICK) - { - _idleTick = _now; - - final long idle_now=((_lowResourcesConnections>0 && selector.keys().size()>_lowResourcesConnections)) - ?(_now+_maxIdleTime) - :_now; - - execute(new Runnable() - { - public void run() - { - for (SelectChannelEndPoint endp:_endPoints.keySet()) - { - endp.checkIdleTimestamp(idle_now); - } - } - public String toString() {return "Idle-"+super.toString();} - }); - - } -*/ - // Reset busy select monitor counts - if (__MONITOR_PERIOD>0 && _now>_monitorNext) - { - _busySelects=0; - _pausing=false; - _monitorNext=_now+__MONITOR_PERIOD; - - } } catch (ClosedSelectorException e) { @@ -498,14 +393,7 @@ { return _now; } -/* - public void wakeup() - { - SaneSelector selector = _selector; - if (selector!=null) - selector.wakeup(); - } -*/ + private SelectChannelEndPoint createEndPoint(SocketChannel channel, SelectionKey sKey) throws IOException { SelectChannelEndPoint endp = new SelectChannelEndPoint(channel,this,sKey, _maxIdleTime); @@ -548,8 +436,7 @@ // close endpoints and selector synchronized (this) { - SaneSelector selector=_selector; - for (SelectionKey key:selector.keys()) + for (SelectionKey key : _selector.keys()) { if (key==null) continue; @@ -570,9 +457,7 @@ try { - selector=_selector; - if (selector != null) - selector.close(); + _selector.close(); } catch (IOException e) {