Skip to content

Commit

Permalink
new: backport more stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
ishland committed Jan 27, 2025
1 parent 9a6e5ca commit 6a93ca0
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 0 deletions.
31 changes: 31 additions & 0 deletions patches/main/0020-change-make-threads-alloc-more-aggressive.patch
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""";

40 changes: 40 additions & 0 deletions patches/main/0021-new-allow-setting-thread-priority.patch
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()));
});

0 comments on commit 6a93ca0

Please sign in to comment.