Skip to content

Commit 1ec6110

Browse files
committed
Added env config for worker pool threads
1 parent a9b45a0 commit 1ec6110

2 files changed

Lines changed: 21 additions & 1 deletion

File tree

src/main/java/com/uid2/operator/Const.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,7 @@ public class Config extends com.uid2.shared.Const.Config {
4242

4343
public static final String ComputeHeavyRequestPoolThreadCountProp = "compute_heavy_request_pool_thread_count";
4444
public static final String EnableAsyncBatchRequestProp = "enable_async_batch_request";
45+
46+
public static final String DefaultWorkerPoolThreadCount = "default_worker_pool_thread_count";
4547
}
4648
}

src/main/java/com/uid2/operator/Main.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -505,10 +505,15 @@ private static Vertx createVertx() {
505505
? 60 * 1000
506506
: 3600 * 1000;
507507

508+
// Worker pool size: read from env var, default to (cpus-2)/2 + 1 clamped to min 2
509+
final int defaultWorkerPoolSize = Math.max(2, (Runtime.getRuntime().availableProcessors() - 2) / 2 + 1);
510+
final int workerPoolSize = getEnvInt(Const.Config.DefaultWorkerPoolThreadCount, defaultWorkerPoolSize);
511+
LOGGER.info("Creating Vertx with worker pool size: {}", workerPoolSize);
512+
508513
VertxOptions vertxOptions = new VertxOptions()
509514
.setMetricsOptions(metricOptions)
510515
.setBlockedThreadCheckInterval(threadBlockedCheckInterval)
511-
.setWorkerPoolSize(12);
516+
.setWorkerPoolSize(workerPoolSize);
512517

513518
return Vertx.vertx(vertxOptions);
514519
}
@@ -642,4 +647,17 @@ private IOperatorKeyRetriever createOperatorKeyRetriever() throws Exception {
642647
}
643648
}
644649
}
650+
651+
private static int getEnvInt(String name, int defaultValue) {
652+
String value = System.getenv(name);
653+
if (value == null || value.isEmpty()) {
654+
return defaultValue;
655+
}
656+
try {
657+
return Integer.parseInt(value);
658+
} catch (NumberFormatException e) {
659+
LOGGER.warn("Invalid integer value for environment variable {}: '{}', using default: {}", name, value, defaultValue);
660+
return defaultValue;
661+
}
662+
}
645663
}

0 commit comments

Comments
 (0)