forked from I2P_Developers/i2p.i2p
propagate from branch 'i2p.i2p.zzz.test2' (head 9dca19f228a66b5ac646c3d97d4f018c733081de)
to branch 'i2p.i2p' (head e7f2b0990f1ff9ab0e0d8633ac2faf35a993b917)
This commit is contained in:
@ -15,11 +15,7 @@ import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.SortedSet;
|
||||
import java.util.StringTokenizer;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.SynchronousQueue;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.ThreadFactory;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
|
||||
import net.i2p.I2PAppContext;
|
||||
import net.i2p.app.ClientAppManager;
|
||||
@ -37,6 +33,7 @@ import net.i2p.util.FileUtil;
|
||||
import net.i2p.util.I2PAppThread;
|
||||
import net.i2p.util.PortMapper;
|
||||
import net.i2p.util.SecureDirectory;
|
||||
import net.i2p.util.I2PSSLSocketFactory;
|
||||
import net.i2p.util.SystemVersion;
|
||||
import org.eclipse.jetty.security.HashLoginService;
|
||||
import org.eclipse.jetty.security.ConstraintMapping;
|
||||
@ -121,7 +118,9 @@ public class RouterConsoleRunner implements RouterApp {
|
||||
private static final String USAGE = "Bad RouterConsoleRunner arguments, check clientApp.0.args in your clients.config file! " +
|
||||
"Usage: [[port host[,host]] [-s sslPort [host[,host]]] [webAppsDir]]";
|
||||
|
||||
/** this is for the handlers only. We will adjust for the connectors and acceptors below. */
|
||||
private static final int MIN_THREADS = 1;
|
||||
/** this is for the handlers only. We will adjust for the connectors and acceptors below. */
|
||||
private static final int MAX_THREADS = 24;
|
||||
private static final int MAX_IDLE_TIME = 90*1000;
|
||||
private static final String THREAD_NAME = "RouterConsole Jetty";
|
||||
@ -343,19 +342,45 @@ public class RouterConsoleRunner implements RouterApp {
|
||||
_server = new Server();
|
||||
_server.setGracefulShutdown(1000);
|
||||
|
||||
try {
|
||||
ThreadPool ctp = new CustomThreadPoolExecutor();
|
||||
// Gone in Jetty 7
|
||||
//ctp.prestartAllCoreThreads();
|
||||
_server.setThreadPool(ctp);
|
||||
} catch (Throwable t) {
|
||||
// In Jetty 6, QTP was not concurrent, so we switched to
|
||||
// ThreadPoolExecutor with a fixed-size queue, a set maxThreads,
|
||||
// and a RejectedExecutionPolicy of CallerRuns.
|
||||
// Unfortunately, CallerRuns causes lockups in Jetty NIO (ticket #1395)
|
||||
// In addition, no flavor of TPE gives us what QTP does:
|
||||
// - TPE direct handoff (which we were using) never queues.
|
||||
// This doesn't provide any burst management when maxThreads is reached.
|
||||
// CallerRuns was an attempt to work around that.
|
||||
// - TPE unbounded queue does not adjust the number of threads.
|
||||
// This doesn't provide automatic resource management.
|
||||
// - TPE bounded queue does not add threads until the queue is full.
|
||||
// This doesn't provide good responsiveness to even small bursts.
|
||||
// QTP adds threads as soon as the queue is non-empty.
|
||||
// QTP as of Jetty 7 uses concurrent.
|
||||
// QTP unbounded queue is the default in Jetty.
|
||||
// So switch back to QTP with a bounded queue.
|
||||
//
|
||||
// ref:
|
||||
// http://docs.oracle.com/javase/6/docs/api/java/util/concurrent/ThreadPoolExecutor.html
|
||||
// https://wiki.eclipse.org/Jetty/Howto/High_Load
|
||||
//
|
||||
//try {
|
||||
// ThreadPool ctp = new CustomThreadPoolExecutor();
|
||||
// // Gone in Jetty 7
|
||||
// //ctp.prestartAllCoreThreads();
|
||||
// _server.setThreadPool(ctp);
|
||||
//} catch (Throwable t) {
|
||||
// class not found...
|
||||
System.out.println("INFO: Jetty concurrent ThreadPool unavailable, using QueuedThreadPool");
|
||||
QueuedThreadPool qtp = new QueuedThreadPool(MAX_THREADS);
|
||||
qtp.setMinThreads(MIN_THREADS);
|
||||
//System.out.println("INFO: Jetty concurrent ThreadPool unavailable, using QueuedThreadPool");
|
||||
LinkedBlockingQueue<Runnable> lbq = new LinkedBlockingQueue<Runnable>(4*MAX_THREADS);
|
||||
QueuedThreadPool qtp = new QueuedThreadPool(lbq);
|
||||
// min and max threads will be set below
|
||||
//qtp.setMinThreads(MIN_THREADS);
|
||||
//qtp.setMaxThreads(MAX_THREADS);
|
||||
qtp.setMaxIdleTimeMs(MAX_IDLE_TIME);
|
||||
qtp.setName(THREAD_NAME);
|
||||
qtp.setDaemon(true);
|
||||
_server.setThreadPool(qtp);
|
||||
}
|
||||
//}
|
||||
|
||||
HandlerCollection hColl = new HandlerCollection();
|
||||
ContextHandlerCollection chColl = new ContextHandlerCollection();
|
||||
@ -490,6 +515,10 @@ public class RouterConsoleRunner implements RouterApp {
|
||||
sslFactory.setKeyStorePassword(_context.getProperty(PROP_KEYSTORE_PASSWORD, DEFAULT_KEYSTORE_PASSWORD));
|
||||
// the X.509 cert password (if not present, verifyKeyStore() returned false)
|
||||
sslFactory.setKeyManagerPassword(_context.getProperty(PROP_KEY_PASSWORD, "thisWontWork"));
|
||||
sslFactory.addExcludeProtocols(I2PSSLSocketFactory.EXCLUDE_PROTOCOLS.toArray(
|
||||
new String[I2PSSLSocketFactory.EXCLUDE_PROTOCOLS.size()]));
|
||||
sslFactory.addExcludeCipherSuites(I2PSSLSocketFactory.INCLUDE_CIPHERS.toArray(
|
||||
new String[I2PSSLSocketFactory.EXCLUDE_CIPHERS.size()]));
|
||||
StringTokenizer tok = new StringTokenizer(_sslListenHost, " ,");
|
||||
while (tok.hasMoreTokens()) {
|
||||
String host = tok.nextToken().trim();
|
||||
@ -548,6 +577,10 @@ public class RouterConsoleRunner implements RouterApp {
|
||||
System.err.println("Unable to bind routerconsole to any address on port " + _listenPort + (sslPort > 0 ? (" or SSL port " + sslPort) : ""));
|
||||
return;
|
||||
}
|
||||
// Each address spawns a Connector and an Acceptor thread
|
||||
// If the min is less than this, we have no thread for the handlers or the expiration thread.
|
||||
qtp.setMinThreads(MIN_THREADS + (2 * boundAddresses));
|
||||
qtp.setMaxThreads(MAX_THREADS + (2 * boundAddresses));
|
||||
|
||||
File tmpdir = new SecureDirectory(workDir, ROUTERCONSOLE + "-" +
|
||||
(_listenPort != null ? _listenPort : _sslListenPort));
|
||||
@ -859,6 +892,7 @@ public class RouterConsoleRunner implements RouterApp {
|
||||
* Just to set the name and set Daemon
|
||||
* @since Jetty 6
|
||||
*/
|
||||
/*****
|
||||
private static class CustomThreadPoolExecutor extends ExecutorThreadPool {
|
||||
public CustomThreadPoolExecutor() {
|
||||
super(new ThreadPoolExecutor(
|
||||
@ -869,11 +903,13 @@ public class RouterConsoleRunner implements RouterApp {
|
||||
);
|
||||
}
|
||||
}
|
||||
*****/
|
||||
|
||||
/**
|
||||
* Just to set the name and set Daemon
|
||||
* @since Jetty 6
|
||||
*/
|
||||
/*****
|
||||
private static class CustomThreadFactory implements ThreadFactory {
|
||||
|
||||
public Thread newThread(Runnable r) {
|
||||
@ -883,5 +919,6 @@ public class RouterConsoleRunner implements RouterApp {
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
*****/
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user