Skip to content

Commit ab8903e

Browse files
committed
chore: cleanup & improve networking (#1433)
The current network implementation has some issues that needed to be addressed. Most noticeble are: - issues with very high native memory consumption due to netty not releasing native memory instantly - issues with a lot of loaded classes that were auto generated - use of ASM which leads to issues with server implementations - rpc code generation can be noticeably improved, especially to ease the usage - and many places where the old code was just messy and could be replaced with a cleaner & easier to read version - bump the required java version for cloudnet to 22 & enable preview features. - replace the usages of ASM in code generation with the java classfile api - rewrite rpc handling & code generation completely - improve default values for settings (for example lower thread counts for packet handling) - improve chunked data transfer, prevent race conditions when querying files - use custom buffer allocator that releases native memory immediately instead of relying on GC - higher test coverage - ... and many more small cleanups and improvements Improved networking that should ease the use for external users and definitely decrease the amount of reported errors.
1 parent 545d705 commit ab8903e

File tree

237 files changed

+9577
-6409
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

237 files changed

+9577
-6409
lines changed

.env

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
MEMORY=512
2-
JAVA_COMPOSE_OPTS=-XX:+UseZGC -XX:+PerfDisableSharedMem -XX:+DisableExplicitGC
2+
JAVA_COMPOSE_OPTS=-XX:+UseZGC -XX:+PerfDisableSharedMem
33
CLOUDNET_COMPOSE_OPTS=

.github/workflows/codeql-analysis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
- name: Setup java
2323
uses: actions/setup-java@v4
2424
with:
25-
java-version: 21
25+
java-version: 22
2626
check-latest: true
2727
distribution: 'zulu'
2828

.github/workflows/gradle-release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
- name: Setup java
2121
uses: actions/setup-java@v4
2222
with:
23-
java-version: 21
23+
java-version: 22
2424
check-latest: true
2525
distribution: 'zulu'
2626

.github/workflows/gradle.yml

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,6 @@ jobs:
1616
build:
1717
runs-on: ubuntu-latest
1818
name: Build and publish
19-
strategy:
20-
fail-fast: false
21-
matrix:
22-
java:
23-
- 21
2419

2520
steps:
2621
- name: Checkout repository
@@ -32,14 +27,14 @@ jobs:
3227
- name: Setup java
3328
uses: actions/setup-java@v4
3429
with:
30+
java-version: 22
3531
check-latest: true
3632
distribution: 'zulu'
37-
java-version: ${{ matrix.java }}
3833

3934
- name: Setup gradle cache
4035
uses: gradle/actions/setup-gradle@v3
4136
with:
42-
cache-read-only: ${{ github.ref != 'refs/heads/nightly' || matrix.java != 21 }}
37+
cache-read-only: ${{ github.ref != 'refs/heads/nightly' }}
4338

4439
- name: Setup Loom cache
4540
uses: actions/cache@v4
@@ -52,7 +47,7 @@ jobs:
5247
run: ./gradlew build test shadowJar genUpdaterInformation --stacktrace
5348

5449
- name: Publish test summary
55-
if: ${{ github.event_name == 'push' && !startsWith(github.ref, 'refs/heads/gh-readonly-queue/') && matrix.java == 21 }}
50+
if: ${{ github.event_name == 'push' && !startsWith(github.ref, 'refs/heads/gh-readonly-queue/') }}
5651
uses: EnricoMi/publish-unit-test-result-action@v2
5752
with:
5853
junit_files: "**/build/test-results/test/TEST-*.xml"
@@ -63,7 +58,7 @@ jobs:
6358

6459
- name: Publish updater metadata
6560
uses: s0/git-publish-subdir-action@develop
66-
if: ${{ github.event_name == 'push' && !startsWith(github.ref, 'refs/heads/renovate/') && !startsWith(github.ref, 'refs/heads/gh-readonly-queue/') && matrix.java == 21 }}
61+
if: ${{ github.event_name == 'push' && !startsWith(github.ref, 'refs/heads/renovate/') && !startsWith(github.ref, 'refs/heads/gh-readonly-queue/') }}
6762
env:
6863
REPO: [email protected]:CloudNetService/launchermeta.git
6964
BRANCH: ${{ steps.branch-name.outputs.current_branch }}
@@ -75,7 +70,6 @@ jobs:
7570
MESSAGE: 'Update launcher meta for {target-branch} (commit: {sha})'
7671

7772
- name: Set version type in GitHub environment
78-
if: ${{ matrix.java == 21 }}
7973
run: |
8074
if [ "$(./gradlew properties | awk '/^version:/ { print $2; }' | grep '\-SNAPSHOT')" ]; then
8175
echo "STATUS=snapshot" >> $GITHUB_ENV
@@ -84,14 +78,14 @@ jobs:
8478
fi
8579
8680
- name: Publish snapshot to Sonatype
87-
if: ${{ github.event_name == 'push' && env.STATUS != 'release' && startsWith(github.ref, 'refs/heads/nightly') && !startsWith(github.ref, 'refs/heads/gh-readonly-queue/') && matrix.java == 21 }}
81+
if: ${{ github.event_name == 'push' && env.STATUS != 'release' && startsWith(github.ref, 'refs/heads/nightly') && !startsWith(github.ref, 'refs/heads/gh-readonly-queue/') }}
8882
run: ./gradlew publish
8983
env:
9084
SONATYPE_USER: "${{ secrets.SONATYPE_USER }}"
9185
SONATYPE_TOKEN: "${{ secrets.SONATYPE_TOKEN }}"
9286

9387
- name: Prepare artifacts zip
94-
if: ${{ github.event_name == 'push' && !startsWith(github.ref, 'refs/heads/gh-readonly-queue/') && matrix.java == 21 }}
88+
if: ${{ github.event_name == 'push' && !startsWith(github.ref, 'refs/heads/gh-readonly-queue/') }}
9589
run: |
9690
mkdir -p temp/;
9791
mkdir -p temp/plugins;
@@ -104,7 +98,7 @@ jobs:
10498
10599
- name: Upload artifacts zip
106100
uses: actions/upload-artifact@v4
107-
if: ${{ github.event_name == 'push' && !startsWith(github.ref, 'refs/heads/gh-readonly-queue/') && matrix.java == 21 }}
101+
if: ${{ github.event_name == 'push' && !startsWith(github.ref, 'refs/heads/gh-readonly-queue/') }}
108102
with:
109103
name: CloudNet
110104
path: temp/

.idea/inspectionProfiles/CloudNet.xml

Lines changed: 4 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.template/start.bat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ IF %ERRORLEVEL% NEQ 0 (
77
EXIT /b 1
88
) ELSE (
99
:: DO NOT CHANGE THE SUPPLIED MEMORY HERE. THIS HAS NO EFFECT ON THE NODE INSTANCE. USE THE launcher.cnl INSTEAD
10-
java -Xms128M -Xmx128M -XX:+UseZGC -XX:+PerfDisableSharedMem -XX:+DisableExplicitGC -jar launcher.jar
10+
java -Xms128M -Xmx128M -XX:+UseZGC -XX:+PerfDisableSharedMem -jar launcher.jar
1111
)

.template/start.command

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ cd "$(dirname "$0")" || exit 1
55
# check if java is installed
66
if [ -x "$(command -v java)" ]; then
77
# DO NOT CHANGE THE SUPPLIED MEMORY HERE. THIS HAS NO EFFECT ON THE NODE INSTANCE. USE THE launcher.cnl INSTEAD
8-
java -Xms128M -Xmx128M -XX:+UseZGC -XX:+PerfDisableSharedMem -XX:+DisableExplicitGC -jar launcher.jar
8+
java -Xms128M -Xmx128M -XX:+UseZGC -XX:+PerfDisableSharedMem -jar launcher.jar
99
else
1010
echo "No valid java installation was found, please install java in order to run CloudNet"
1111
exit 1

.template/start.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ if [ -x "$(command -v java)" ]; then
88
# this check is elevated as tmux is sometimes present by default
99
if [ -x "$(command -v screen)" ]; then
1010
# DO NOT CHANGE THE SUPPLIED MEMORY HERE. THIS HAS NO EFFECT ON THE NODE INSTANCE. USE THE launcher.cnl INSTEAD
11-
screen -DRSq CloudNet java -Xms128M -Xmx128M -XX:+UseZGC -XX:+PerfDisableSharedMem -XX:+DisableExplicitGC -jar launcher.jar
11+
screen -DRSq CloudNet java -Xms128M -Xmx128M -XX:+UseZGC -XX:+PerfDisableSharedMem -jar launcher.jar
1212
elif [ -x "$(command -v tmux)" ]; then
1313
# DO NOT CHANGE THE SUPPLIED MEMORY HERE. THIS HAS NO EFFECT ON THE NODE INSTANCE. USE THE launcher.cnl INSTEAD
14-
tmux new-session -As CloudNet java -Xms128M -Xmx128M -XX:+UseZGC -XX:+PerfDisableSharedMem -XX:+DisableExplicitGC -jar launcher.jar
14+
tmux new-session -As CloudNet java -Xms128M -Xmx128M -XX:+UseZGC -XX:+PerfDisableSharedMem -jar launcher.jar
1515
else
1616
echo "No screen or tmux installation found, you need to install at least one of them to run CloudNet"
1717
exit 1

build-extensions/src/main/kotlin/extensions.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ private fun resolveRepository(
131131
repositories: Iterable<MavenArtifactRepository>
132132
): MavenArtifactRepository? {
133133
return repositories.firstOrNull {
134-
val url = URL(it.url.toURL(), testUrlPath)
134+
val url = it.url.resolve(testUrlPath).toURL()
135135
with(url.openConnection() as HttpURLConnection) {
136136
useCaches = false
137137
readTimeout = 30000

build.gradle.kts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,18 +96,29 @@ subprojects {
9696
testLogging {
9797
events("started", "passed", "skipped", "failed")
9898
}
99+
100+
// allow dynamic agent loading for mockito
101+
jvmArgs(
102+
"--enable-preview",
103+
"-XX:+EnableDynamicAgentLoading",
104+
"--add-opens=java.base/java.lang.invoke=ALL-UNNAMED"
105+
)
106+
99107
// always pass down all given system properties
100108
systemProperties(System.getProperties().mapKeys { it.key.toString() })
101109
}
102110

103111
tasks.withType<JavaCompile>().configureEach {
104-
sourceCompatibility = JavaVersion.VERSION_21.toString()
105-
targetCompatibility = JavaVersion.VERSION_21.toString()
106-
// options
112+
sourceCompatibility = JavaVersion.VERSION_22.toString()
113+
targetCompatibility = JavaVersion.VERSION_22.toString()
114+
107115
options.encoding = "UTF-8"
108116
options.isIncremental = true
109-
// we are aware that those are there, but we only do that if there is no other way we can use - so please keep the terminal clean!
110-
options.compilerArgs = mutableListOf("-Xlint:-deprecation,-unchecked")
117+
118+
if (project.path != ":launcher:java8") {
119+
options.compilerArgs.add("--enable-preview")
120+
options.compilerArgs.add("-Xlint:-deprecation,-unchecked,-preview")
121+
}
111122
}
112123

113124
tasks.withType<Checkstyle> {

checkstyle.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@
224224
<module name="CatchParameterName">
225225
<message key="name.invalidPattern"
226226
value="Catch parameter name ''{0}'' must match pattern ''{1}''."/>
227-
<property name="format" value="^[a-z]([a-z0-9][a-zA-Z0-9]*)?$"/>
227+
<property name="format" value="^[a-z_]([a-z0-9][a-zA-Z0-9]*)?$"/>
228228
</module>
229229
<module name="LocalVariableName">
230230
<message key="name.invalidPattern"
@@ -332,7 +332,7 @@
332332
</module>
333333
<module name="SingleLineJavadoc"/>
334334
<module name="EmptyCatchBlock">
335-
<property name="exceptionVariableName" value="ignored|expected"/>
335+
<property name="exceptionVariableName" value="ignored|expected|_"/>
336336
</module>
337337
<module name="CommentsIndentation">
338338
<property name="tokens" value="SINGLE_LINE_COMMENT, BLOCK_COMMENT_BEGIN"/>

common/src/main/java/eu/cloudnetservice/common/io/FileUtil.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ public final class FileUtil {
6363
.filter(prov -> prov.getScheme().equalsIgnoreCase("jar"))
6464
.findFirst()
6565
.orElseThrow(() -> new ExceptionInInitializerError("Unable to find a file system provider supporting jars"));
66+
67+
// pre-create the temporary directory
68+
FileUtil.createDirectory(TEMP_DIR);
6669
}
6770

6871
private FileUtil() {

driver/build.gradle.kts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,13 @@ tasks.withType<ShadowJar> {
3030
}
3131

3232
tasks.withType<JavaCompile> {
33-
options.compilerArgs = listOf("-AaerogelAutoFileName=autoconfigure/driver.aero")
33+
options.compilerArgs.add("-AaerogelAutoFileName=autoconfigure/driver.aero")
3434
}
3535

3636
tasks.withType<Test> {
3737
dependsOn(":common:jar")
3838
}
3939

40-
extensions.configure<JavaPluginExtension> {
41-
sourceSets {
42-
create("ap")
43-
}
44-
}
45-
4640
dependencies {
4741
"api"(projects.common)
4842
"api"(projects.ext.updater)
@@ -67,8 +61,5 @@ dependencies {
6761
"implementation"(variantOf(libs.nettyNativeEpoll) { classifier("linux-x86_64") })
6862
"implementation"(variantOf(libs.nettyNativeEpoll) { classifier("linux-aarch_64") })
6963

70-
// hack - depend on the output of the ap output to apply the annotation process to this project too
71-
"annotationProcessor"(project.sourceSets()["ap"].output)
72-
7364
"testImplementation"(projects.common.dependencyProject.sourceSets()["main"].output)
7465
}

driver/src/ap/java/eu/cloudnetservice/driver/ap/RPCValidationProcessor.java

Lines changed: 0 additions & 126 deletions
This file was deleted.

0 commit comments

Comments
 (0)