diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2017-01-26 14:31:15 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-01-26 14:31:15 +0100 |
commit | 7c4f0c4cd53d142444e40d66c436da989f263bce (patch) | |
tree | 18dc4a48fdf5283e2ddd8cc0072fa16aba182899 /vespaclient-container-plugin/src/main/java/com/yahoo/document/restapi/resource/RestApi.java | |
parent | 8c19df88fe4d16fe6f8b74394ec29847c0269a48 (diff) | |
parent | b657a7f6750a95af69f777c3fc6de0967875ebe8 (diff) |
Merge pull request #1608 from yahoo/dybdahl/threads
Make document API use max 40% of threads, and feeding use max 40%.
Diffstat (limited to 'vespaclient-container-plugin/src/main/java/com/yahoo/document/restapi/resource/RestApi.java')
-rw-r--r-- | vespaclient-container-plugin/src/main/java/com/yahoo/document/restapi/resource/RestApi.java | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/vespaclient-container-plugin/src/main/java/com/yahoo/document/restapi/resource/RestApi.java b/vespaclient-container-plugin/src/main/java/com/yahoo/document/restapi/resource/RestApi.java index 18628af3eca..80769909b9f 100644 --- a/vespaclient-container-plugin/src/main/java/com/yahoo/document/restapi/resource/RestApi.java +++ b/vespaclient-container-plugin/src/main/java/com/yahoo/document/restapi/resource/RestApi.java @@ -6,6 +6,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.google.inject.Inject; import com.fasterxml.jackson.databind.node.ObjectNode; +import com.yahoo.container.handler.ThreadpoolConfig; import com.yahoo.container.jdisc.HttpRequest; import com.yahoo.container.jdisc.HttpResponse; import com.yahoo.container.jdisc.LoggingRequestHandler; @@ -52,17 +53,24 @@ public class RestApi extends LoggingRequestHandler { private static final String APPLICATION_JSON = "application/json"; private final OperationHandler operationHandler; private SingleDocumentParser singleDocumentParser; - private ObjectMapper mapper = new ObjectMapper(); - private AtomicInteger threadsAvailableForApi = new AtomicInteger(200 /*max concurrent requests */); + private final ObjectMapper mapper = new ObjectMapper(); + private final AtomicInteger threadsAvailableForApi; @Inject public RestApi(Executor executor, AccessLog accessLog, DocumentmanagerConfig documentManagerConfig, - LoadTypeConfig loadTypeConfig) { + LoadTypeConfig loadTypeConfig, ThreadpoolConfig threadpoolConfig) { super(executor, accessLog); MessageBusParams params = new MessageBusParams(new LoadTypeSet(loadTypeConfig)); params.setDocumentmanagerConfig(documentManagerConfig); this.operationHandler = new OperationHandlerImpl(new MessageBusDocumentAccess(params)); this.singleDocumentParser = new SingleDocumentParser(new DocumentTypeManager(documentManagerConfig)); + // 40% of the threads can be blocked before we deny requests. + if (threadpoolConfig != null) { + threadsAvailableForApi = new AtomicInteger(Math.max((int) (0.4 * threadpoolConfig.maxthreads()), 1)); + } else { + log.warning("No config for threadpool, using 200 for max blocking threads for document rest API."); + threadsAvailableForApi = new AtomicInteger(200); + } } // For testing and development @@ -73,7 +81,7 @@ public class RestApi extends LoggingRequestHandler { int threadsAvailable) { super(executor, accessLog); this.operationHandler = operationHandler; - this.threadsAvailableForApi.set(threadsAvailable); + this.threadsAvailableForApi = new AtomicInteger(threadsAvailable); } @Override |