You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@bookkeeper.apache.org by GitBox <gi...@apache.org> on 2018/04/04 00:15:43 UTC
[GitHub] sijie closed pull request #1308: longPollThreadPool can not be null
sijie closed pull request #1308: longPollThreadPool can not be null
URL: https://github.com/apache/bookkeeper/pull/1308
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git a/bookkeeper-server/src/main/java/org/apache/bookkeeper/conf/ServerConfiguration.java b/bookkeeper-server/src/main/java/org/apache/bookkeeper/conf/ServerConfiguration.java
index 2aaea61f5..e9950fd1c 100644
--- a/bookkeeper-server/src/main/java/org/apache/bookkeeper/conf/ServerConfiguration.java
+++ b/bookkeeper-server/src/main/java/org/apache/bookkeeper/conf/ServerConfiguration.java
@@ -1288,10 +1288,15 @@ public ServerConfiguration setNumLongPollWorkerThreads(int numThreads) {
/**
* Get the number of threads that should handle long poll requests.
- * @return
+ *
+ * <p>If the number of threads is zero or negative, bookie will fallback to
+ * use read threads. If there is no read threads used, it will create a thread pool
+ * with {@link Runtime#availableProcessors()} threads.
+ *
+ * @return the number of threads that should handle long poll requests, default value is 0.
*/
public int getNumLongPollWorkerThreads() {
- return getInt(NUM_LONG_POLL_WORKER_THREADS, 10);
+ return getInt(NUM_LONG_POLL_WORKER_THREADS, 0);
}
/**
diff --git a/bookkeeper-server/src/main/java/org/apache/bookkeeper/processor/RequestProcessor.java b/bookkeeper-server/src/main/java/org/apache/bookkeeper/processor/RequestProcessor.java
index 19f095c07..2c8cf7af3 100644
--- a/bookkeeper-server/src/main/java/org/apache/bookkeeper/processor/RequestProcessor.java
+++ b/bookkeeper-server/src/main/java/org/apache/bookkeeper/processor/RequestProcessor.java
@@ -25,7 +25,7 @@
/**
* A request processor that is used for processing requests at bookie side.
*/
-public interface RequestProcessor {
+public interface RequestProcessor extends AutoCloseable {
/**
* Close the request processor.
diff --git a/bookkeeper-server/src/main/java/org/apache/bookkeeper/proto/BookieRequestProcessor.java b/bookkeeper-server/src/main/java/org/apache/bookkeeper/proto/BookieRequestProcessor.java
index 7e65ced11..4102e75c8 100644
--- a/bookkeeper-server/src/main/java/org/apache/bookkeeper/proto/BookieRequestProcessor.java
+++ b/bookkeeper-server/src/main/java/org/apache/bookkeeper/proto/BookieRequestProcessor.java
@@ -56,6 +56,8 @@
import java.util.concurrent.RejectedExecutionException;
import java.util.concurrent.TimeUnit;
+import lombok.AccessLevel;
+import lombok.Getter;
import org.apache.bookkeeper.auth.AuthProviderFactoryFactory;
import org.apache.bookkeeper.auth.AuthToken;
import org.apache.bookkeeper.bookie.Bookie;
@@ -92,6 +94,7 @@
/**
* The threadpool used to execute all read entry requests issued to this server.
*/
+ @Getter(AccessLevel.PACKAGE)
private final OrderedExecutor readThreadPool;
/**
@@ -108,6 +111,7 @@
* The threadpool used to execute all long poll requests issued to this server
* after they are done waiting.
*/
+ @Getter(AccessLevel.PACKAGE)
private final OrderedExecutor longPollThreadPool;
/**
@@ -158,10 +162,18 @@ public BookieRequestProcessor(ServerConfiguration serverCfg, Bookie bookie,
"BookieWriteThreadPool",
serverCfg.getMaxPendingAddRequestPerThread(),
statsLogger);
- this.longPollThreadPool = createExecutor(
- this.serverCfg.getNumLongPollWorkerThreads(),
+ if (serverCfg.getNumLongPollWorkerThreads() <= 0 && readThreadPool != null) {
+ this.longPollThreadPool = this.readThreadPool;
+ } else {
+ int numThreads = this.serverCfg.getNumLongPollWorkerThreads();
+ if (numThreads <= 0) {
+ numThreads = Runtime.getRuntime().availableProcessors();
+ }
+ this.longPollThreadPool = createExecutor(
+ numThreads,
"BookieLongPollThread-" + serverCfg.getBookiePort(),
OrderedExecutor.NO_TASK_LIMIT, statsLogger);
+ }
this.highPriorityThreadPool = createExecutor(
this.serverCfg.getNumHighPriorityWorkerThreads(),
"BookieHighPriorityThread-" + serverCfg.getBookiePort(),
@@ -203,7 +215,9 @@ public BookieRequestProcessor(ServerConfiguration serverCfg, Bookie bookie,
public void close() {
shutdownExecutor(writeThreadPool);
shutdownExecutor(readThreadPool);
- shutdownExecutor(longPollThreadPool);
+ if (serverCfg.getNumLongPollWorkerThreads() > 0 || readThreadPool == null) {
+ shutdownExecutor(longPollThreadPool);
+ }
shutdownExecutor(highPriorityThreadPool);
}
@@ -362,7 +376,7 @@ private void processReadRequestV3(final BookkeeperProtocol.Request r, final Chan
final ReadEntryProcessorV3 read;
final OrderedExecutor threadPool;
if (RequestUtils.isLongPollReadRequest(r.getReadRequest())) {
- ExecutorService lpThread = null == longPollThreadPool ? null : longPollThreadPool.chooseThread(c);
+ ExecutorService lpThread = longPollThreadPool.chooseThread(c);
read = new LongPollReadEntryProcessorV3(r, c, this, fenceThread,
lpThread, requestTimer);
diff --git a/bookkeeper-server/src/test/java/org/apache/bookkeeper/proto/TestBookieRequestProcessor.java b/bookkeeper-server/src/test/java/org/apache/bookkeeper/proto/TestBookieRequestProcessor.java
index c7601d0a9..b212e49e4 100644
--- a/bookkeeper-server/src/test/java/org/apache/bookkeeper/proto/TestBookieRequestProcessor.java
+++ b/bookkeeper-server/src/test/java/org/apache/bookkeeper/proto/TestBookieRequestProcessor.java
@@ -21,17 +21,56 @@
package org.apache.bookkeeper.proto;
import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNotSame;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
import com.google.protobuf.ByteString;
+import org.apache.bookkeeper.bookie.Bookie;
+import org.apache.bookkeeper.conf.ServerConfiguration;
import org.apache.bookkeeper.proto.BookkeeperProtocol.AddRequest;
import org.apache.bookkeeper.proto.BookkeeperProtocol.ReadRequest;
+import org.apache.bookkeeper.stats.NullStatsLogger;
import org.junit.Test;
/**
* Test utility methods from bookie request processor.
*/
public class TestBookieRequestProcessor {
+
+ @Test
+ public void testConstructLongPollThreads() throws Exception {
+ // long poll threads == read threads
+ ServerConfiguration conf = new ServerConfiguration();
+ try (BookieRequestProcessor processor = new BookieRequestProcessor(
+ conf, mock(Bookie.class), NullStatsLogger.INSTANCE, null)) {
+ assertSame(processor.getReadThreadPool(), processor.getLongPollThreadPool());
+ }
+
+ // force create long poll threads if there is no read threads
+ conf = new ServerConfiguration();
+ conf.setNumReadWorkerThreads(0);
+ try (BookieRequestProcessor processor = new BookieRequestProcessor(
+ conf, mock(Bookie.class), NullStatsLogger.INSTANCE, null)) {
+ assertNull(processor.getReadThreadPool());
+ assertNotNull(processor.getLongPollThreadPool());
+ }
+
+ // long poll threads and no read threads
+ conf = new ServerConfiguration();
+ conf.setNumReadWorkerThreads(2);
+ conf.setNumLongPollWorkerThreads(2);
+ try (BookieRequestProcessor processor = new BookieRequestProcessor(
+ conf, mock(Bookie.class), NullStatsLogger.INSTANCE, null)) {
+ assertNotNull(processor.getReadThreadPool());
+ assertNotNull(processor.getLongPollThreadPool());
+ assertNotSame(processor.getReadThreadPool(), processor.getLongPollThreadPool());
+ }
+ }
+
@Test
public void testFlagsV3() {
ReadRequest read = ReadRequest.newBuilder()
diff --git a/conf/bk_server.conf b/conf/bk_server.conf
index 8c294b9a9..8016a7867 100755
--- a/conf/bk_server.conf
+++ b/conf/bk_server.conf
@@ -107,7 +107,7 @@ bookiePort=3181
# numReadWorkerThreads=8
# The number of threads that should handle long poll requests.
-# numLongPollWorkerThreads=10
+# numLongPollWorkerThreads=0
# The number of threads used for handling journal callback. If a zero or negative number is provided,
# the callbacks are executed directly at force write threads.
diff --git a/site/_data/config/bk_server.yaml b/site/_data/config/bk_server.yaml
index 6eeb32927..ce45f2028 100644
--- a/site/_data/config/bk_server.yaml
+++ b/site/_data/config/bk_server.yaml
@@ -55,7 +55,7 @@ groups:
default: 8
- param: numLongPollWorkerThreads
description: The number of threads that handle long poll requests. If zero, long poll requests are handled by [Netty threads](//netty.io/wiki/thread-model.html) directly.
- default: 10
+ default: 0
- param: numJournalCallbackThreads
description: The number of threads that handle journal callbacks. If zero, journal callbacks are executed directly on force write threads.
default: 1
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services