HADOOP-15311. HttpServer2 needs a way to configure the acceptor/selector count. Contributed by Erik Krogen
This commit is contained in:
parent
a82d4a2e3a
commit
9d6994da19
|
@ -134,6 +134,14 @@ public final class HttpServer2 implements FilterContainer {
|
||||||
"hadoop.http.socket.backlog.size";
|
"hadoop.http.socket.backlog.size";
|
||||||
public static final int HTTP_SOCKET_BACKLOG_SIZE_DEFAULT = 128;
|
public static final int HTTP_SOCKET_BACKLOG_SIZE_DEFAULT = 128;
|
||||||
public static final String HTTP_MAX_THREADS_KEY = "hadoop.http.max.threads";
|
public static final String HTTP_MAX_THREADS_KEY = "hadoop.http.max.threads";
|
||||||
|
public static final String HTTP_ACCEPTOR_COUNT_KEY =
|
||||||
|
"hadoop.http.acceptor.count";
|
||||||
|
// -1 to use default behavior of setting count based on CPU core count
|
||||||
|
public static final int HTTP_ACCEPTOR_COUNT_DEFAULT = -1;
|
||||||
|
public static final String HTTP_SELECTOR_COUNT_KEY =
|
||||||
|
"hadoop.http.selector.count";
|
||||||
|
// -1 to use default behavior of setting count based on CPU core count
|
||||||
|
public static final int HTTP_SELECTOR_COUNT_DEFAULT = -1;
|
||||||
public static final String HTTP_TEMP_DIR_KEY = "hadoop.http.temp.dir";
|
public static final String HTTP_TEMP_DIR_KEY = "hadoop.http.temp.dir";
|
||||||
|
|
||||||
public static final String FILTER_INITIALIZER_PROPERTY
|
public static final String FILTER_INITIALIZER_PROPERTY
|
||||||
|
@ -465,7 +473,9 @@ public final class HttpServer2 implements FilterContainer {
|
||||||
|
|
||||||
private ServerConnector createHttpChannelConnector(
|
private ServerConnector createHttpChannelConnector(
|
||||||
Server server, HttpConfiguration httpConfig) {
|
Server server, HttpConfiguration httpConfig) {
|
||||||
ServerConnector conn = new ServerConnector(server);
|
ServerConnector conn = new ServerConnector(server,
|
||||||
|
conf.getInt(HTTP_ACCEPTOR_COUNT_KEY, HTTP_ACCEPTOR_COUNT_DEFAULT),
|
||||||
|
conf.getInt(HTTP_SELECTOR_COUNT_KEY, HTTP_SELECTOR_COUNT_DEFAULT));
|
||||||
ConnectionFactory connFactory = new HttpConnectionFactory(httpConfig);
|
ConnectionFactory connFactory = new HttpConnectionFactory(httpConfig);
|
||||||
conn.addConnectionFactory(connFactory);
|
conn.addConnectionFactory(connFactory);
|
||||||
configureChannelConnector(conn);
|
configureChannelConnector(conn);
|
||||||
|
|
|
@ -147,7 +147,7 @@ public class TestHttpServer extends HttpServerFunctionalTest {
|
||||||
|
|
||||||
@BeforeClass public static void setup() throws Exception {
|
@BeforeClass public static void setup() throws Exception {
|
||||||
Configuration conf = new Configuration();
|
Configuration conf = new Configuration();
|
||||||
conf.setInt(HttpServer2.HTTP_MAX_THREADS_KEY, 10);
|
conf.setInt(HttpServer2.HTTP_MAX_THREADS_KEY, MAX_THREADS);
|
||||||
server = createTestServer(conf);
|
server = createTestServer(conf);
|
||||||
server.addServlet("echo", "/echo", EchoServlet.class);
|
server.addServlet("echo", "/echo", EchoServlet.class);
|
||||||
server.addServlet("echomap", "/echomap", EchoMapServlet.class);
|
server.addServlet("echomap", "/echomap", EchoMapServlet.class);
|
||||||
|
@ -196,6 +196,27 @@ public class TestHttpServer extends HttpServerFunctionalTest {
|
||||||
start.countDown();
|
start.countDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test that the number of acceptors and selectors can be configured by
|
||||||
|
* trying to configure more of them than would be allowed based on the
|
||||||
|
* maximum thread count.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testAcceptorSelectorConfigurability() throws Exception {
|
||||||
|
Configuration conf = new Configuration();
|
||||||
|
conf.setInt(HttpServer2.HTTP_MAX_THREADS_KEY, MAX_THREADS);
|
||||||
|
conf.setInt(HttpServer2.HTTP_ACCEPTOR_COUNT_KEY, MAX_THREADS - 2);
|
||||||
|
conf.setInt(HttpServer2.HTTP_SELECTOR_COUNT_KEY, MAX_THREADS - 2);
|
||||||
|
HttpServer2 badserver = createTestServer(conf);
|
||||||
|
try {
|
||||||
|
badserver.start();
|
||||||
|
// Should not succeed
|
||||||
|
fail();
|
||||||
|
} catch (IOException ioe) {
|
||||||
|
assertTrue(ioe.getCause() instanceof IllegalStateException);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test public void testEcho() throws Exception {
|
@Test public void testEcho() throws Exception {
|
||||||
assertEquals("a:b\nc:d\n",
|
assertEquals("a:b\nc:d\n",
|
||||||
readOutput(new URL(baseUrl, "/echo?a=b&c=d")));
|
readOutput(new URL(baseUrl, "/echo?a=b&c=d")));
|
||||||
|
|
Loading…
Reference in New Issue