From 754e815ad4bf8c056da00beb2d0643ef37842b00 Mon Sep 17 00:00:00 2001 From: PengFei Li Date: Mon, 25 Dec 2023 20:36:34 +0800 Subject: [PATCH] [Enhancement] Support to configure the number of http worker threads on FE (#37530) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Why I'm doing: Http worker threads on FE are used to deal with http requests. Some requests may do heavy operations which will block threads, such as transaction stream load commit, and other operations that need to get lock. As a result, http server can't deal with other requests. Before optimizing these heavy operations, we first make the number of http worker threads to be configurable, and increase it as a candidate solution if the problem happens. What I'm doing: Add a configuration to adjust the number of http worker threads on FE Signed-off-by: PengFei Li Signed-off-by: 张敢 --- docs/en/administration/FE_configuration.md | 6 ++++++ docs/zh/administration/FE_configuration.md | 6 ++++++ .../src/main/java/com/starrocks/common/Config.java | 11 +++++++++++ .../src/main/java/com/starrocks/http/HttpServer.java | 3 ++- 4 files changed, 25 insertions(+), 1 deletion(-) diff --git a/docs/en/administration/FE_configuration.md b/docs/en/administration/FE_configuration.md index 182b24c372449f..2d0d339be8b375 100644 --- a/docs/en/administration/FE_configuration.md +++ b/docs/en/administration/FE_configuration.md @@ -1016,6 +1016,12 @@ This section provides an overview of the static parameters that you can configur - **Default:** 8030 - **Description:** The port on which the HTTP server in the FE node listens. +#### http_worker_threads_num + +- **Default:** 0 +- **Description:** Number of worker threads for http server to deal with http requests. For a negative or 0 value, the number of threads will be twice the number of cpu cores. +- Introduced in: 2.5.18,3.0.10,3.1.7,3.2.2 + #### http_backlog_num - **Default:** 1024 diff --git a/docs/zh/administration/FE_configuration.md b/docs/zh/administration/FE_configuration.md index 2e517a2c512d93..1ac9fd593a68df 100644 --- a/docs/zh/administration/FE_configuration.md +++ b/docs/zh/administration/FE_configuration.md @@ -935,6 +935,12 @@ Compaction Score 代表了一个表分区是否值得进行 Compaction 的评分 - 含义:FE 节点上 HTTP 服务器的端口。 - 默认值:8030 +#### http_worker_threads_num + +- 含义:Http Server 用于处理 HTTP 请求的线程数。如果配置为负数或 0 ,线程数将设置为 CPU 核数的 2 倍。 +- 默认值:0 +- 引入版本:2.5.18,3.0.10,3.1.7,3.2.2 + #### http_backlog_num - 含义:HTTP 服务器支持的 Backlog 队列长度。 diff --git a/fe/fe-core/src/main/java/com/starrocks/common/Config.java b/fe/fe-core/src/main/java/com/starrocks/common/Config.java index 51ded77ca69a6c..66636339e63a11 100644 --- a/fe/fe-core/src/main/java/com/starrocks/common/Config.java +++ b/fe/fe-core/src/main/java/com/starrocks/common/Config.java @@ -592,6 +592,17 @@ public class Config extends ConfigBase { @ConfField public static int http_port = 8030; + /** + * Number of worker threads for http server to deal with http requests which may do + * some I/O operations. If set with a non-positive value, it will use netty's default + * value DEFAULT_EVENT_LOOP_THREADS which is availableProcessors * 2. The + * default value is 0 which is same as the previous behaviour. + * See DEFAULT_EVENT_LOOP_THREADS + * for details. + */ + @ConfField + public static int http_worker_threads_num = 0; + /** * The backlog_num for netty http server * When you enlarge this backlog_num, you should ensure its value larger than diff --git a/fe/fe-core/src/main/java/com/starrocks/http/HttpServer.java b/fe/fe-core/src/main/java/com/starrocks/http/HttpServer.java index 60363a2e708f8c..482f1ea2b76112 100644 --- a/fe/fe-core/src/main/java/com/starrocks/http/HttpServer.java +++ b/fe/fe-core/src/main/java/com/starrocks/http/HttpServer.java @@ -257,7 +257,8 @@ private class HttpServerThread implements Runnable { public void run() { // Configure the server. EventLoopGroup bossGroup = new NioEventLoopGroup(); - EventLoopGroup workerGroup = new NioEventLoopGroup(); + int numWorkerThreads = Math.max(0, Config.http_worker_threads_num); + EventLoopGroup workerGroup = new NioEventLoopGroup(numWorkerThreads); try { serverBootstrap = new ServerBootstrap(); serverBootstrap.option(ChannelOption.SO_BACKLOG, Config.http_backlog_num);