From 269a1d06ff820c287bb21a03fa76e3314110516a Mon Sep 17 00:00:00 2001
From: Jean-Noel Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Mon, 22 Apr 2013 10:28:50 +0000
Subject: [PATCH] OPENDJ-832 Leverage the work queue for processing requests received on the HTTP connection handler
---
opends/src/server/org/opends/server/api/WorkQueue.java | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 55 insertions(+), 0 deletions(-)
diff --git a/opends/src/server/org/opends/server/api/WorkQueue.java b/opends/src/server/org/opends/server/api/WorkQueue.java
index b9fddd5..78d6be1 100644
--- a/opends/src/server/org/opends/server/api/WorkQueue.java
+++ b/opends/src/server/org/opends/server/api/WorkQueue.java
@@ -27,6 +27,9 @@
*/
package org.opends.server.api;
+import static org.opends.messages.CoreMessages.*;
+import static org.opends.server.loggers.ErrorLogger.*;
+
import org.opends.messages.Message;
import org.opends.server.admin.std.server.WorkQueueCfg;
import org.opends.server.config.ConfigException;
@@ -106,6 +109,22 @@
/**
+ * Tries to submit an operation to be processed in the server, without
+ * blocking.
+ *
+ * @param operation
+ * The operation to be processed.
+ * @return true if the operation could be submitted to the queue, false if the
+ * queue was full
+ * @throws DirectoryException
+ * If the provided operation is not accepted for some reason (e.g.,
+ * if the server is shutting down).
+ */
+ public abstract boolean trySubmitOperation(Operation operation)
+ throws DirectoryException;
+
+
+ /**
* Indicates whether the work queue is currently processing any
* requests. Note that this is a point-in-time determination, and
* if any component of the server wishes to depend on a quiescent
@@ -119,6 +138,42 @@
public abstract boolean isIdle();
+ /**
+ * Return the maximum number of worker threads that can be used by this
+ * WorkQueue (The WorkQueue could have a thread pool which adjusts its size).
+ *
+ * @return the maximum number of worker threads that can be used by this
+ * WorkQueue
+ */
+ public abstract int getNumWorkerThreads();
+
+
+ /**
+ * Computes the number of worker threads to use by the working queue based on
+ * the configured number.
+ *
+ * @param configuredNumWorkerThreads
+ * the configured number of worker threads to use
+ * @return the number of worker threads to use
+ */
+ protected int computeNumWorkerThreads(Integer configuredNumWorkerThreads)
+ {
+ if (configuredNumWorkerThreads != null)
+ {
+ return configuredNumWorkerThreads;
+ }
+ else
+ {
+ // Automatically choose based on the number of processors.
+ int cpus = Runtime.getRuntime().availableProcessors();
+ int value = Math.max(24, cpus * 2);
+
+ Message message = INFO_ERGONOMIC_SIZING_OF_WORKER_THREAD_POOL.get(value);
+ logError(message);
+
+ return value;
+ }
+ }
/**
* Waits for the work queue to become idle before returning. Note
--
Gitblit v1.10.0