Use every thread available to the JVM, in a work stealing pool for packet handling

This commit is contained in:
KingRainbow44 2023-09-10 12:26:38 -04:00
parent 3c3adea406
commit 23aff95a2e
No known key found for this signature in database
GPG Key ID: FC2CB64B00D257BE
2 changed files with 7 additions and 9 deletions

View File

@ -1,7 +1,5 @@
package emu.grasscutter.server.game;
import static emu.grasscutter.config.Configuration.GAME_INFO;
import emu.grasscutter.Grasscutter;
import emu.grasscutter.Grasscutter.ServerDebugMode;
import emu.grasscutter.net.packet.*;
@ -9,6 +7,8 @@ import emu.grasscutter.server.event.game.ReceivePacketEvent;
import emu.grasscutter.server.game.GameSession.SessionState;
import it.unimi.dsi.fastutil.ints.*;
import static emu.grasscutter.config.Configuration.GAME_INFO;
public final class GameServerPacketHandler {
private final Int2ObjectMap<PacketHandler> handlers;
@ -76,13 +76,11 @@ public final class GameServerPacketHandler {
}
// Invoke event.
ReceivePacketEvent event = new ReceivePacketEvent(session, opcode, payload);
event.call();
if (!event.isCanceled()) // If event is not canceled, continue.
handler.handle(session, header, event.getPacketData());
var event = new ReceivePacketEvent(session, opcode, payload);
if (!event.call()) // If event is not canceled, continue.
handler.handle(session, header, event.getPacketData());
} catch (Exception ex) {
// TODO Remove this when no more needed
ex.printStackTrace();
Grasscutter.getLogger().warn("Unable to handle packet.", ex);
}
return; // Packet successfully handled
}

View File

@ -14,7 +14,7 @@ public final class GameSessionManager implements KcpListener {
@Getter private static final GameSessionManager instance
= new GameSessionManager();
@Getter private static final ExecutorService executor
= Executors.newFixedThreadPool(4);
= Executors.newWorkStealingPool();
@Getter private static final Map<Ukcp, GameSession> sessions
= new ConcurrentHashMap<>();