1817N/A * Copyright 2009 Google Inc. All Rights Reserved. 1817N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1817N/A * This code is free software; you can redistribute it and/or modify it 1817N/A * under the terms of the GNU General Public License version 2 only, as 1817N/A * published by the Free Software Foundation. 1817N/A * This code is distributed in the hope that it will be useful, but WITHOUT 1817N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1817N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1817N/A * version 2 for more details (a copy is included in the LICENSE file that 1817N/A * You should have received a copy of the GNU General Public License version 1817N/A * 2 along with this work; if not, write to the Free Software Foundation, 1817N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2362N/A * or visit www.oracle.com if you need additional information or have any 1817N/A * Reproduces O(N^2) behavior of JDK6/7 select() call. This happens when 1817N/A * a selector has many unprocessed updates to its interest set (e.g. adding 1817N/A * OP_READ on a bunch of newly accepted sockets). The O(N^2) is triggered 1817N/A * by cancelling a number of selection keys (or just closing a few sockets). 1817N/A * In this case, select() will first go through the list of cancelled keys 1817N/A * and try to deregister them. That deregistration is O(N^2) over the list 1817N/A * of unprocessed updates to the interest set. 1817N/A * <p> This O(N^2) behavior is a BUG in JVM and should be fixed. 1817N/A * <p> The test first creates initCount connections, and adds them 1817N/A * to the server epoll set. It then creates massCount connections, 1817N/A * registers interest (causing updateList to be populated with massCount*2 1817N/A * elements), but does not add them to epoll set (that would've cleared 1817N/A * updateList). The test then closes initCount connections, thus populating 1817N/A * deregistration queue. The subsequent call to selectNow() will first process 1817N/A * deregistration queue, performing O(N^2) over updateList size, 1817N/A * <p> Note that connect rate is artificially slowed down to compensate 1817N/A * for what I believe is a Linux bug, where too high of a connection rate 1817N/A * ends up in SYN's being dropped and then slow retransmits. 1817N/A // the final select should run in less than 1000ms. 1817N/A * Returns the elapsed time since startNanos, in milliseconds. 1817N/A * @param startNanos the start time; this must be a value returned 1817N/A * by {@link System.nanoTime} 1817N/A // Create server channel, add it to selector and run epoll_ctl. 1817N/A // Set up initial set of client sockets. 1817N/A log(
"Starting initial client connections");
1817N/A // Accept all initial client sockets, add to selector and run 1817N/A // Set up mass set of client sockets. 1817N/A log(
"Requesting mass client connections");
1817N/A // Accept all mass client sockets, add to selector and do NOT 1817N/A // Close initial set of sockets. 1817N/A // Now get the timing of select() call. 1817N/A (
"\n\n\n\n\nFAILURE: The final selectNow() took " +
1817N/A "- seems like O(N^2) bug is still here\n\n");
1817N/A // See if more new sockets got stacked behind. 1817N/A // Cause an additional updateList entry per channel. 1817N/A log(
"Exited clientSelector.select(), loop #"