-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
71 additions
and
0 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
patches/main/0020-change-make-threads-alloc-more-aggressive.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 | ||
From: ishland <[email protected]> | ||
Date: Mon, 27 Jan 2025 11:05:26 +0800 | ||
Subject: [PATCH] change: make threads alloc more aggressive | ||
|
||
Backported from 2c331e72d09388b4199377397f44d270cf672713 with small changes | ||
|
||
diff --git a/c2me-base/src/main/java/com/ishland/c2me/base/ModuleEntryPoint.java b/c2me-base/src/main/java/com/ishland/c2me/base/ModuleEntryPoint.java | ||
index 404ef427..9fd23703 100644 | ||
--- a/c2me-base/src/main/java/com/ishland/c2me/base/ModuleEntryPoint.java | ||
+++ b/c2me-base/src/main/java/com/ishland/c2me/base/ModuleEntryPoint.java | ||
@@ -18,14 +18,11 @@ public class ModuleEntryPoint { | ||
1, | ||
min( | ||
if( is_windows, | ||
- (cpus / 1.6 - 2), | ||
- (cpus / 1.2 - 2) | ||
- ), | ||
- if( is_j9vm, | ||
- ( ( mem_gb - (if(is_client, 0.6, 0.2)) ) / 0.4 ), | ||
- ( ( mem_gb - (if(is_client, 1.2, 0.6)) ) / 0.6 ) | ||
- ) | ||
- ) - if(is_client, 2, 0) | ||
+ (cpus / 1.6), | ||
+ (cpus / 1.3) | ||
+ ) - if(is_client, 1, 0), | ||
+ ( ( mem_gb - (if(is_client, 1.2, 0.6)) ) / 0.6 ) | ||
+ ) | ||
) | ||
\040"""; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 | ||
From: ishland <[email protected]> | ||
Date: Mon, 27 Jan 2025 11:24:56 +0800 | ||
Subject: [PATCH] new: allow setting thread priority | ||
|
||
Backported from 333ab1a32ab01ee899776b230f9ed13089ded1f5 | ||
|
||
diff --git a/c2me-base/src/main/java/com/ishland/c2me/base/ModuleEntryPoint.java b/c2me-base/src/main/java/com/ishland/c2me/base/ModuleEntryPoint.java | ||
index 9fd23703..e70e6c80 100644 | ||
--- a/c2me-base/src/main/java/com/ishland/c2me/base/ModuleEntryPoint.java | ||
+++ b/c2me-base/src/main/java/com/ishland/c2me/base/ModuleEntryPoint.java | ||
@@ -36,6 +36,16 @@ public class ModuleEntryPoint { | ||
""".indent(1)) | ||
.getString(DEFAULT_EXPRESSION, DEFAULT_EXPRESSION); | ||
|
||
+ public static final long threadPoolPriority = new ConfigSystem.ConfigAccessor() | ||
+ .key("threadPoolPriority") | ||
+ .comment(""" | ||
+ Sets the thread priority for worker threads | ||
+ | ||
+ References: | ||
+ - https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/lang/Thread.html#setPriority(int) | ||
+ """) | ||
+ .getLong(Thread.NORM_PRIORITY - 1, Thread.NORM_PRIORITY - 1, ConfigSystem.LongChecks.POSITIVE_VALUES_ONLY); | ||
+ | ||
public static final int defaultParallelism; | ||
|
||
private static int tryEvaluateExpression(String expression) { | ||
diff --git a/c2me-base/src/main/java/com/ishland/c2me/base/common/GlobalExecutors.java b/c2me-base/src/main/java/com/ishland/c2me/base/common/GlobalExecutors.java | ||
index e5a81999..34485a08 100644 | ||
--- a/c2me-base/src/main/java/com/ishland/c2me/base/common/GlobalExecutors.java | ||
+++ b/c2me-base/src/main/java/com/ishland/c2me/base/common/GlobalExecutors.java | ||
@@ -14,6 +14,7 @@ public class GlobalExecutors { | ||
private static final AtomicInteger prioritizedSchedulerCounter = new AtomicInteger(0); | ||
public static final ExecutorManager prioritizedScheduler = new ExecutorManager(GlobalExecutors.GLOBAL_EXECUTOR_PARALLELISM, thread -> { | ||
thread.setDaemon(true); | ||
+ thread.setPriority(Math.max(Thread.MIN_PRIORITY, Math.min(Thread.MAX_PRIORITY, (int) ModuleEntryPoint.threadPoolPriority))); | ||
thread.setName("c2me-worker-%d".formatted(prioritizedSchedulerCounter.getAndIncrement())); | ||
}); | ||
|