Skip to content

Commit 55cd91e

Browse files
committed
refactor(api): reduce build log queue size and polling interval
- Decrease queue size from 1000 to 100 to reduce memory usage - Increase polling frequency from 10s to 1s for more timely processing - Remove unused string writing methods in EventHandler
1 parent 7e3d2d7 commit 55cd91e

File tree

2 files changed

+13
-16
lines changed

2 files changed

+13
-16
lines changed

src/main/java/mindustrytool/handler/ApiGateway.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public ApiGateway(ServerController controller) {
4747
.executor(Config.BACKGROUND_TASK_EXECUTOR)
4848
.build();
4949

50-
public final BlockingQueue<BuildLogDto> buildLogs = new LinkedBlockingQueue<>(1000);
50+
public final BlockingQueue<BuildLogDto> buildLogs = new LinkedBlockingQueue<>(100);
5151

5252
public void init() {
5353
Log.info("Setup api gateway");
@@ -74,7 +74,7 @@ public void init() {
7474

7575
}
7676

77-
}, 0, 10, TimeUnit.SECONDS);
77+
}, 0, 1, TimeUnit.SECONDS);
7878

7979
Log.info("Setup api gateway done");
8080

@@ -156,7 +156,6 @@ public void sendChatMessage(String chat) {
156156

157157
public void sendBuildLog(BuildLogDto buildLog) {
158158
if (!buildLogs.offer(buildLog)) {
159-
buildLogs.clear();
160159
Log.warn("Build log queue is full. Dropping log.");
161160
}
162161
}

src/main/java/mindustrytool/handler/EventHandler.java

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@
44
import com.github.benmanes.caffeine.cache.Caffeine;
55

66
import java.net.InetAddress;
7-
import java.nio.ByteBuffer;
87
import java.util.ArrayList;
9-
import java.util.Arrays;
108
import java.util.Comparator;
119
import java.util.HashMap;
1210
import java.util.List;
@@ -374,19 +372,19 @@ private void setupCustomServerDiscovery() {
374372
// }
375373
}
376374

377-
private void writeString(ByteBuffer buffer, String string) {
378-
writeString(buffer, string, 32);
379-
}
375+
// private void writeString(ByteBuffer buffer, String string) {
376+
// writeString(buffer, string, 32);
377+
// }
380378

381-
private void writeString(ByteBuffer buffer, String string, int maxlen) {
382-
byte[] bytes = string.getBytes(Vars.charset);
383-
if (bytes.length > maxlen) {
384-
bytes = Arrays.copyOfRange(bytes, 0, maxlen);
385-
}
379+
// private void writeString(ByteBuffer buffer, String string, int maxlen) {
380+
// byte[] bytes = string.getBytes(Vars.charset);
381+
// if (bytes.length > maxlen) {
382+
// bytes = Arrays.copyOfRange(bytes, 0, maxlen);
383+
// }
386384

387-
buffer.put((byte) bytes.length);
388-
buffer.put(bytes);
389-
}
385+
// buffer.put((byte) bytes.length);
386+
// buffer.put(bytes);
387+
// }
390388

391389
public void onServerLoad(ServerLoadEvent event) {
392390
Config.isLoaded = true;

0 commit comments

Comments
 (0)