HBASE-7498 Make REST server thread pool size configurable

git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1429364 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
jxiang 2013-01-05 19:31:40 +00:00
parent c8138e1c3e
commit c543a70e68
2 changed files with 35 additions and 0 deletions

View File

@ -44,6 +44,7 @@ import org.mortbay.jetty.Server;
import org.mortbay.jetty.nio.SelectChannelConnector; import org.mortbay.jetty.nio.SelectChannelConnector;
import org.mortbay.jetty.servlet.Context; import org.mortbay.jetty.servlet.Context;
import org.mortbay.jetty.servlet.ServletHolder; import org.mortbay.jetty.servlet.ServletHolder;
import org.mortbay.thread.QueuedThreadPool;
import com.sun.jersey.spi.container.servlet.ServletContainer; import com.sun.jersey.spi.container.servlet.ServletContainer;
@ -140,6 +141,17 @@ public class RESTServer implements Constants {
server.addConnector(connector); server.addConnector(connector);
// Set the default max thread number to 100 to limit
// the number of concurrent requests so that REST server doesn't OOM easily.
// Jetty set the default max thread number to 250, if we don't set it.
//
// Our default min thread number 2 is the same as that used by Jetty.
int maxThreads = servlet.getConfiguration().getInt("hbase.rest.threads.max", 100);
int minThreads = servlet.getConfiguration().getInt("hbase.rest.threads.min", 2);
QueuedThreadPool threadPool = new QueuedThreadPool(maxThreads);
threadPool.setMinThreads(minThreads);
server.setThreadPool(threadPool);
server.setSendServerVersion(false); server.setSendServerVersion(false);
server.setSendDateHeader(false); server.setSendDateHeader(false);
server.setStopAtShutdown(true); server.setStopAtShutdown(true);

View File

@ -930,4 +930,27 @@
properties from a zoo.cfg file has been deprecated. properties from a zoo.cfg file has been deprecated.
</description> </description>
</property> </property>
<property>
<name>hbase.rest.threads.max</name>
<value>100</value>
<description>
The maximum number of threads of the REST server thread pool.
Threads in the pool are reused to process REST requests. This
controls the maximum number of requests processed concurrently.
It may help to control the memory used by the REST server to
avoid OOM issues. If the thread pool is full, incoming requests
will be queued up and wait for some free threads. The default
is 100.
</description>
</property>
<property>
<name>hbase.rest.threads.min</name>
<value>2</value>
<description>
The minimum number of threads of the REST server thread pool.
The thread pool always has at least these number of threads so
the REST server is ready to serve incoming requests. The default
is 2.
</description>
</property>
</configuration> </configuration>