Author: markt Date: Tue May 5 15:29:49 2015 New Revision: 1677839 URL: http://svn.apache.org/r1677839 Log: Remove the oomParachute as discissed on the dev list
Modified: tomcat/trunk/java/org/apache/coyote/http11/Http11Nio2Protocol.java tomcat/trunk/java/org/apache/coyote/http11/Http11NioProtocol.java tomcat/trunk/java/org/apache/tomcat/util/net/Nio2Endpoint.java tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java tomcat/trunk/webapps/docs/config/http.xml Modified: tomcat/trunk/java/org/apache/coyote/http11/Http11Nio2Protocol.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/http11/Http11Nio2Protocol.java?rev=1677839&r1=1677838&r2=1677839&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/coyote/http11/Http11Nio2Protocol.java (original) +++ tomcat/trunk/java/org/apache/coyote/http11/Http11Nio2Protocol.java Tue May 5 15:29:49 2015 @@ -57,13 +57,6 @@ public class Http11Nio2Protocol extends } - // -------------------- Tcp setup -------------------- - - public void setOomParachute(int oomParachute) { - ((Nio2Endpoint)getEndpoint()).setOomParachute(oomParachute); - } - - // ----------------------------------------------------- JMX related methods @Override Modified: tomcat/trunk/java/org/apache/coyote/http11/Http11NioProtocol.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/http11/Http11NioProtocol.java?rev=1677839&r1=1677838&r2=1677839&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/coyote/http11/Http11NioProtocol.java (original) +++ tomcat/trunk/java/org/apache/coyote/http11/Http11NioProtocol.java Tue May 5 15:29:49 2015 @@ -88,11 +88,6 @@ public class Http11NioProtocol extends A } - // -------------------- Tcp setup -------------------- - public void setOomParachute(int oomParachute) { - ((NioEndpoint)getEndpoint()).setOomParachute(oomParachute); - } - // ----------------------------------------------------- JMX related methods @Override Modified: tomcat/trunk/java/org/apache/tomcat/util/net/Nio2Endpoint.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/net/Nio2Endpoint.java?rev=1677839&r1=1677838&r2=1677839&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/util/net/Nio2Endpoint.java (original) +++ tomcat/trunk/java/org/apache/tomcat/util/net/Nio2Endpoint.java Tue May 5 15:29:49 2015 @@ -74,11 +74,6 @@ public class Nio2Endpoint extends Abstra private AsynchronousServerSocketChannel serverSock = null; /** - * The size of the OOM parachute. - */ - private int oomParachute = 1024*1024; - - /** * Allows detecting if a completion handler completes inline. */ private static ThreadLocal<Boolean> inlineCompletion = new ThreadLocal<>(); @@ -91,24 +86,6 @@ public class Nio2Endpoint extends Abstra private volatile boolean allClosed; /** - * The oom parachute, when an OOM error happens, - * will release the data, giving the JVM instantly - * a chunk of data to be able to recover with. - */ - private byte[] oomParachuteData = null; - - /** - * Make sure this string has already been allocated - */ - private static final String oomParachuteMsg = - "SEVERE:Memory usage is low, parachute is non existent, your system may start failing."; - - /** - * Keep track of OOM warning messages. - */ - private long lastParachuteCheck = System.currentTimeMillis(); - - /** * Cache for SocketProcessor objects */ private SynchronizedStack<SocketProcessor> processorCache; @@ -151,14 +128,6 @@ public class Nio2Endpoint extends Abstra return false; } - public void setOomParachute(int oomParachute) { - this.oomParachute = oomParachute; - } - - public void setOomParachuteData(byte[] oomParachuteData) { - this.oomParachuteData = oomParachuteData; - } - /** * Port in use. @@ -183,35 +152,12 @@ public class Nio2Endpoint extends Abstra } - // --------------------------------------------------------- OOM Parachute Methods - - protected void checkParachute() { - boolean para = reclaimParachute(false); - if (!para && (System.currentTimeMillis()-lastParachuteCheck)>10000) { - try { - log.fatal(oomParachuteMsg); - }catch (Throwable t) { - ExceptionUtils.handleThrowable(t); - System.err.println(oomParachuteMsg); - } - lastParachuteCheck = System.currentTimeMillis(); - } - } - - protected boolean reclaimParachute(boolean force) { - if ( oomParachuteData != null ) return true; - if ( oomParachute > 0 && ( force || (Runtime.getRuntime().freeMemory() > (oomParachute*2))) ) - oomParachuteData = new byte[oomParachute]; - return oomParachuteData != null; - } - protected void releaseCaches() { if (useCaches) { this.nioChannels.clear(); this.processorCache.clear(); } if ( handler != null ) handler.recycle(); - } // --------------------------------------------------------- Public Methods @@ -261,8 +207,6 @@ public class Nio2Endpoint extends Abstra // Initialize SSL if needed initialiseSsl(); - - if (oomParachute>0) reclaimParachute(true); } @@ -398,15 +342,6 @@ public class Nio2Endpoint extends Abstra return socketProperties.getRxBufSize(); } - public int getOomParachute() { - return oomParachute; - } - - public byte[] getOomParachuteData() { - return oomParachuteData; - } - - @Override protected AbstractEndpoint.Acceptor createAcceptor() { return new Acceptor(); @@ -1742,20 +1677,6 @@ public class Nio2Endpoint extends Abstra nioChannels.push(socket.getSocket()); } } - } catch (OutOfMemoryError oom) { - try { - oomParachuteData = null; - log.error("", oom); - closeSocket(socket); - releaseCaches(); - } catch (Throwable oomt) { - try { - System.err.println(oomParachuteMsg); - oomt.printStackTrace(); - } catch (Throwable letsHopeWeDontGetHere){ - ExceptionUtils.handleThrowable(letsHopeWeDontGetHere); - } - } } catch (VirtualMachineError vme) { ExceptionUtils.handleThrowable(vme); } catch (Throwable t) { Modified: tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java?rev=1677839&r1=1677838&r2=1677839&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java (original) +++ tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java Tue May 5 15:29:49 2015 @@ -88,28 +88,6 @@ public class NioEndpoint extends Abstrac private ServerSocketChannel serverSock = null; /** - * The size of the OOM parachute. - */ - private int oomParachute = 1024*1024; - /** - * The oom parachute, when an OOM error happens, - * will release the data, giving the JVM instantly - * a chunk of data to be able to recover with. - */ - private byte[] oomParachuteData = null; - - /** - * Make sure this string has already been allocated - */ - private static final String oomParachuteMsg = - "SEVERE:Memory usage is low, parachute is non existent, your system may start failing."; - - /** - * Keep track of OOM warning messages. - */ - private long lastParachuteCheck = System.currentTimeMillis(); - - /** * */ private volatile CountDownLatch stopLatch = null; @@ -211,14 +189,6 @@ public class NioEndpoint extends Abstrac return false; } - public void setOomParachute(int oomParachute) { - this.oomParachute = oomParachute; - } - - public void setOomParachuteData(byte[] oomParachuteData) { - this.oomParachuteData = oomParachuteData; - } - /** * Port in use. @@ -239,28 +209,6 @@ public class NioEndpoint extends Abstrac } - // --------------------------------------------------------- OOM Parachute Methods - - protected void checkParachute() { - boolean para = reclaimParachute(false); - if (!para && (System.currentTimeMillis()-lastParachuteCheck)>10000) { - try { - log.fatal(oomParachuteMsg); - }catch (Throwable t) { - ExceptionUtils.handleThrowable(t); - System.err.println(oomParachuteMsg); - } - lastParachuteCheck = System.currentTimeMillis(); - } - } - - protected boolean reclaimParachute(boolean force) { - if ( oomParachuteData != null ) return true; - if ( oomParachute > 0 && ( force || (Runtime.getRuntime().freeMemory() > (oomParachute*2))) ) - oomParachuteData = new byte[oomParachute]; - return oomParachuteData != null; - } - protected void releaseCaches() { this.nioChannels.clear(); this.processorCache.clear(); @@ -268,6 +216,7 @@ public class NioEndpoint extends Abstrac } + // --------------------------------------------------------- Public Methods /** * Number of keep-alive sockets. @@ -290,7 +239,6 @@ public class NioEndpoint extends Abstrac // ----------------------------------------------- Public Lifecycle Methods - /** * Initialize the endpoint. */ @@ -318,7 +266,6 @@ public class NioEndpoint extends Abstrac // Initialize SSL if needed initialiseSsl(); - if (oomParachute>0) reclaimParachute(true); selectorPool.open(); } @@ -430,14 +377,6 @@ public class NioEndpoint extends Abstrac return selectorPool; } - public int getOomParachute() { - return oomParachute; - } - - public byte[] getOomParachuteData() { - return oomParachuteData; - } - @Override protected AbstractEndpoint.Acceptor createAcceptor() { @@ -601,23 +540,6 @@ public class NioEndpoint extends Abstrac if (running) { log.error(sm.getString("endpoint.accept.fail"), x); } - } catch (OutOfMemoryError oom) { - try { - oomParachuteData = null; - releaseCaches(); - log.error("", oom); - }catch ( Throwable oomt ) { - try { - try { - System.err.println(oomParachuteMsg); - oomt.printStackTrace(); - }catch (Throwable letsHopeWeDontGetHere){ - ExceptionUtils.handleThrowable(letsHopeWeDontGetHere); - } - }catch (Throwable letsHopeWeDontGetHere){ - ExceptionUtils.handleThrowable(letsHopeWeDontGetHere); - } - } } catch (Throwable t) { ExceptionUtils.handleThrowable(t); log.error(sm.getString("endpoint.accept.fail"), t); @@ -874,19 +796,42 @@ public class NioEndpoint extends Abstrac public void run() { // Loop until destroy() is called while (true) { - try { - // Loop if endpoint is paused - while (paused && (!close) ) { - try { - Thread.sleep(100); - } catch (InterruptedException e) { - // Ignore - } + // Loop if endpoint is paused + while (paused && (!close) ) { + try { + Thread.sleep(100); + } catch (InterruptedException e) { + // Ignore } + } - boolean hasEvents = false; + boolean hasEvents = false; - // Time to terminate? + // Time to terminate? + if (close) { + events(); + timeout(0, false); + try { + selector.close(); + } catch (IOException ioe) { + log.error(sm.getString( + "endpoint.nio.selectorCloseFail"), ioe); + } + break; + } else { + hasEvents = events(); + } + try { + if ( !close ) { + if (wakeupCounter.getAndSet(-1) > 0) { + //if we are here, means we have other stuff to do + //do a non blocking select + keyCount = selector.selectNow(); + } else { + keyCount = selector.select(selectorTimeout); + } + wakeupCounter.set(0); + } if (close) { events(); timeout(0, false); @@ -897,73 +842,34 @@ public class NioEndpoint extends Abstrac "endpoint.nio.selectorCloseFail"), ioe); } break; - } else { - hasEvents = events(); } - try { - if ( !close ) { - if (wakeupCounter.getAndSet(-1) > 0) { - //if we are here, means we have other stuff to do - //do a non blocking select - keyCount = selector.selectNow(); - } else { - keyCount = selector.select(selectorTimeout); - } - wakeupCounter.set(0); - } - if (close) { - events(); - timeout(0, false); - try { - selector.close(); - } catch (IOException ioe) { - log.error(sm.getString( - "endpoint.nio.selectorCloseFail"), ioe); - } - break; - } - } catch (Throwable x) { - ExceptionUtils.handleThrowable(x); - log.error("",x); - continue; - } - //either we timed out or we woke up, process events first - if ( keyCount == 0 ) hasEvents = (hasEvents | events()); - - Iterator<SelectionKey> iterator = - keyCount > 0 ? selector.selectedKeys().iterator() : null; - // Walk through the collection of ready keys and dispatch - // any active event. - while (iterator != null && iterator.hasNext()) { - SelectionKey sk = iterator.next(); - NioSocketWrapper attachment = (NioSocketWrapper)sk.attachment(); - // Attachment may be null if another thread has called - // cancelledKey() - if (attachment == null) { - iterator.remove(); - } else { - iterator.remove(); - processKey(sk, attachment); - } - }//while + } catch (Throwable x) { + ExceptionUtils.handleThrowable(x); + log.error("",x); + continue; + } + //either we timed out or we woke up, process events first + if ( keyCount == 0 ) hasEvents = (hasEvents | events()); - //process timeouts - timeout(keyCount,hasEvents); - if ( oomParachute > 0 && oomParachuteData == null ) checkParachute(); - } catch (OutOfMemoryError oom) { - try { - oomParachuteData = null; - releaseCaches(); - log.error("", oom); - }catch ( Throwable oomt ) { - try { - System.err.println(oomParachuteMsg); - oomt.printStackTrace(); - }catch (Throwable letsHopeWeDontGetHere){ - ExceptionUtils.handleThrowable(letsHopeWeDontGetHere); - } + Iterator<SelectionKey> iterator = + keyCount > 0 ? selector.selectedKeys().iterator() : null; + // Walk through the collection of ready keys and dispatch + // any active event. + while (iterator != null && iterator.hasNext()) { + SelectionKey sk = iterator.next(); + NioSocketWrapper attachment = (NioSocketWrapper)sk.attachment(); + // Attachment may be null if another thread has called + // cancelledKey() + if (attachment == null) { + iterator.remove(); + } else { + iterator.remove(); + processKey(sk, attachment); } - } + }//while + + //process timeouts + timeout(keyCount,hasEvents); }//while stopLatch.countDown(); @@ -1641,22 +1547,6 @@ public class NioEndpoint extends Abstrac if (socket != null) { socket.getPoller().cancelledKey(key); } - } catch (OutOfMemoryError oom) { - try { - oomParachuteData = null; - log.error("", oom); - if (socket != null) { - socket.getPoller().cancelledKey(key); - } - releaseCaches(); - } catch (Throwable oomt) { - try { - System.err.println(oomParachuteMsg); - oomt.printStackTrace(); - } catch (Throwable letsHopeWeDontGetHere){ - ExceptionUtils.handleThrowable(letsHopeWeDontGetHere); - } - } } catch (VirtualMachineError vme) { ExceptionUtils.handleThrowable(vme); } catch (Throwable t) { Modified: tomcat/trunk/webapps/docs/config/http.xml URL: http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/config/http.xml?rev=1677839&r1=1677838&r2=1677839&view=diff ============================================================================== --- tomcat/trunk/webapps/docs/config/http.xml (original) +++ tomcat/trunk/webapps/docs/config/http.xml Tue May 5 15:29:49 2015 @@ -777,18 +777,6 @@ <strong>selectorPool.maxSelectors</strong> attribute.</p> </attribute> - <attribute name="oomParachute" required="false"> - <p>(int)The NIO connector implements an OutOfMemoryError strategy called - parachute. It holds a chunk of data as a byte array. In case of an OOM, - this chunk of data is released and the error is reported. This will give - the VM enough room to clean up. The <code>oomParachute</code> represents - the size in bytes of the parachute(the byte array). The default value is - <code>1024*1024</code>(1MB). Please note, this only works for OOM errors - regarding the Java Heap space, and there is absolutely no guarantee - that you will be able to recover at all. If you have an OOM outside of - the Java Heap, then this parachute trick will not help. - </p> - </attribute> </attributes> </subsection> @@ -876,18 +864,6 @@ <code>-1</code> for unlimited cache and <code>0</code> for no cache.</p> </attribute> - <attribute name="oomParachute" required="false"> - <p>(int)The NIO2 connector implements an OutOfMemoryError strategy called - parachute. It holds a chunk of data as a byte array. In case of an OOM, - this chunk of data is released and the error is reported. This will give - the VM enough room to clean up. The <code>oomParachute</code> represents - the size in bytes of the parachute(the byte array). The default value is - <code>1024*1024</code>(1MB). Please note, this only works for OOM errors - regarding the Java Heap space, and there is absolutely no guarantee - that you will be able to recover at all. If you have an OOM outside of - the Java Heap, then this parachute trick will not help. - </p> - </attribute> </attributes> </subsection> --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org