diff options
Diffstat (limited to 'vespaclient-container-plugin/src/main/java/com/yahoo/document/restapi')
-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 |