Skip to content

Adjust formula for Netty worker threads. - #18493

Merged
cryptoe merged 2 commits into
apache:masterfrom
gianm:netty-thread-adjust
Sep 15, 2025
Merged

Adjust formula for Netty worker threads.#18493
cryptoe merged 2 commits into
apache:masterfrom
gianm:netty-thread-adjust

Conversation

@gianm

@gianm gianm commented Sep 7, 2025

Copy link
Copy Markdown
Contributor

Generally, the new formula leads to much fewer threads at small processor counts, and similar numbers of threads at large processor counts. The purpose of this change is to avoid issues due to having too-large worker thread counts on small machines, such as OutOfMemoryError for too many threads or not enough direct memory.

Comparison table

cpus old new
1 40 2
2 40 4
3 40 5
4 40 7
5 40 8
6 40 10
7 40 11
8 40 13
16 49 25
24 57 37
32 66 49
48 83 73
64 100 97
96 134 145

Generally, the new formula leads to much fewer threads at
small processor counts, and similar numbers of threads
at large processor counts.
@JsonProperty
@Min(1)
private int numMaxThreads = Math.max(10, (JvmUtils.getRuntimeInfo().getAvailableProcessors() * 17) / 16 + 2) + 30;
private int numMaxThreads = JvmUtils.getRuntimeInfo().getAvailableProcessors() * 3 / 2 + 1;

Check notice

Code scanning / CodeQL

Deprecated method or constructor invocation Note

Invoking
JvmUtils.getRuntimeInfo
should be avoided because it has been deprecated.
@kfaraz

kfaraz commented Sep 7, 2025

Copy link
Copy Markdown
Contributor

@gianm , it makes sense to reduce the number of netty worker threads since these
threads mostly sit idle most of the time.

But I wonder if the change is not too drastic, especially since this affects all services.
e.g. even for a machine with 16 cpus, we are halving the value from 49 to 25,
which can affect say an Overlord communicating with a large number of streaming tasks.

Do you think it would make sense to maybe roll this out gradually, like have a formula which reduces
the 49 to say 40-ish and decrease the values further in subsequent Druid releases?

@gianm

gianm commented Sep 8, 2025

Copy link
Copy Markdown
Contributor Author

@gianm , it makes sense to reduce the number of netty worker threads since these threads mostly sit idle most of the time.

But I wonder if the change is not too drastic, especially since this affects all services. e.g. even for a machine with 16 cpus, we are halving the value from 49 to 25, which can affect say an Overlord communicating with a large number of streaming tasks.

Do you think it would make sense to maybe roll this out gradually, like have a formula which reduces the 49 to say 40-ish and decrease the values further in subsequent Druid releases?

I believe the Netty worker threads are only supposed to be running callbacks, so they should need to scale with number of CPUs rather than number of outgoing connections. For that reason I am not expecting the smaller pools to be a bottleneck & I would rather jump straight to a new formula.

Maybe we can validate this with some scale testing prior to release?

@kfaraz

kfaraz commented Sep 9, 2025

Copy link
Copy Markdown
Contributor

I believe the Netty worker threads are only supposed to be running callbacks, so they should need to scale with number of CPUs rather than number of outgoing connections. For that reason I am not expecting the smaller pools to be a bottleneck & I would rather jump straight to a new formula.

Thanks for the clarification, @gianm .

Maybe we can validate this with some scale testing prior to release?

Sure, I think this should be feasible.

@FrankChen021

Copy link
Copy Markdown
Member
image

documents should be updated to align this change.

@uds5501

uds5501 commented Sep 12, 2025

Copy link
Copy Markdown
Contributor

Hey @gianm , we are testing this change in a cluster and will bombard the same with high load. We shall post the results once done.

@gianm

gianm commented Sep 12, 2025

Copy link
Copy Markdown
Contributor Author

documents should be updated to align this change.

Good point. Updated.

|`druid.global.http.compressionCodec`|Compression codec to communicate with others. May be "gzip" or "identity".|`gzip`|
|`druid.global.http.readTimeout`|The timeout for data reads.|`PT15M`|
|`druid.global.http.unusedConnectionTimeout`|The timeout for idle connections in connection pool. The connection in the pool will be closed after this timeout and a new one will be established. This timeout should be less than `druid.global.http.readTimeout`. Set this timeout = ~90% of `druid.global.http.readTimeout`|`PT4M`|
|`druid.global.http.numMaxThreads`|Maximum number of I/O worker threads|`max(10, ((number of cores * 17) / 16 + 2) + 30)`|

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Curious, how did we come up with these old formulas?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gianm , could you please add a short comment in the code regarding the heuristics behind the formula?

@uds5501

uds5501 commented Sep 15, 2025

Copy link
Copy Markdown
Contributor

Hi @gianm , the local tests look good with these I/O worker threads setup (the supervisors for ingestion looks stable and are being queried just fine)

@kfaraz

kfaraz commented Sep 15, 2025

Copy link
Copy Markdown
Contributor

Thanks for performing the verifications, @uds5501 !
Could you share some details of the kind of load you used in your testing?

@cryptoe
cryptoe merged commit a55b8cb into apache:master Sep 15, 2025
62 checks passed
@gianm
gianm deleted the netty-thread-adjust branch September 15, 2025 23:26
@cecemei cecemei added this to the 35.0.0 milestone Oct 21, 2025
riovic918data pushed a commit to riovic918data/druid that referenced this pull request Jun 12, 2026
* Adjust formula for Netty worker threads.

Generally, the new formula leads to much fewer threads at
small processor counts, and similar numbers of threads
at large processor counts.

* Update documentation.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants