-
Notifications
You must be signed in to change notification settings - Fork 65
Add FastNetworkManager & cleanup #174
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
18caec8
e8aeec2
f1ccf97
59d716e
a847144
35b815a
ae169a7
b20da40
fbdf4ae
6bed73c
6c56d71
2c91377
b48e82f
0892587
26c55b2
66845f0
0f3fe98
f33e9c9
79bf2b5
7734d3e
dac73a4
4433b3d
728d136
9d371b4
117b0bc
a96120a
8e370e2
211e375
bf55bff
f35ab1b
e73d659
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| package com.falchus.spigot.optimizations; | ||
|
|
||
| import com.windpvp.windspigot.config.WindSpigotConfig; | ||
| import com.google.common.collect.Queues; | ||
| import io.netty.channel.Channel; | ||
| import io.netty.channel.ChannelFuture; | ||
| import io.netty.channel.ChannelFutureListener; | ||
| import net.minecraft.server.NetworkManager; | ||
| import net.minecraft.server.Packet; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.Queue; | ||
|
|
||
| public class FastNetworkManager { | ||
|
|
||
| private final NetworkManager networkManager; | ||
| private final Queue<Packet<?>>[] queues = new Queue[WindSpigotConfig.threadSize]; | ||
|
|
||
| public FastNetworkManager(NetworkManager networkManager) { | ||
| this.networkManager = networkManager; | ||
| for (int i = 0; i < queues.length; i++) { | ||
| queues[i] = Queues.newConcurrentLinkedQueue(); | ||
| } | ||
| } | ||
|
|
||
| public void writePacketLazily(Packet<?> packet, boolean flush) { | ||
| Channel channel = networkManager.channel; | ||
| if (channel == null || !channel.isActive()) return; | ||
|
|
||
| channel.eventLoop().execute(() -> { | ||
| ChannelFuture future = channel.write(packet); | ||
| future.addListener(ChannelFutureListener.FIRE_EXCEPTION_ON_FAILURE); | ||
| if (flush) { | ||
| channel.flush(); | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| public void writePacketLazily(Packet<?> packet) { | ||
| writePacketLazily(packet, false); | ||
| } | ||
|
|
||
| public void queuePacket(Packet<?> packet, int trackerThread) { | ||
| if (packet != null) { | ||
| queues[trackerThread].add(packet); | ||
| } | ||
| } | ||
|
|
||
| public void flushQueuedPackets() { | ||
| Channel channel = networkManager.channel; | ||
| if (channel == null || !channel.isActive()) return; | ||
|
|
||
| ArrayList<Packet<?>> writing = new ArrayList<>(); | ||
| Packet<?> packet; | ||
| for (int i = 0; i < queues.length; i++) { | ||
| Queue<Packet<?>> current = queues[i]; | ||
| queues[i] = Queues.newConcurrentLinkedQueue(); | ||
| while ((packet = current.poll()) != null) { | ||
| writing.add(packet); | ||
| } | ||
| } | ||
| if (writing.isEmpty()) return; | ||
|
|
||
| channel.eventLoop().execute(() -> { | ||
| for (Packet<?> p : writing) { | ||
| ChannelFuture future = channel.write(p); | ||
| future.addListener(ChannelFutureListener.FIRE_EXCEPTION_ON_FAILURE); | ||
| } | ||
| channel.flush(); | ||
| }); | ||
| } | ||
| } | ||
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -590,5 +590,16 @@ private static void tabSpam() { | |
| tabSpamIncrement = getInt("settings.disconnect-spam.increment", 5); | ||
| tabSpamLimit = getInt("settings.disconnect-spam.limit", 750); | ||
| } | ||
|
|
||
|
|
||
| // FalchusSpigot start | ||
| public static int threadSize; | ||
| private static void threadSize() { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems like there's a queue for each entity tracking thread, so wouldn't the thread size just be the tracking threads? |
||
| threadSize = getInt("thread-size", 3); | ||
| if (threadSize == -1) { | ||
| threadSize = Math.max(1, Runtime.getRuntime().availableProcessors() - 1); | ||
| } else { | ||
| threadSize = Math.max(1, threadSize); | ||
| } | ||
| } | ||
| // FalchusSpigot end | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,5 @@ | ||
| package com.windpvp.windspigot.world; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| import com.windpvp.windspigot.async.ResettableLatch; | ||
| import com.windpvp.windspigot.async.entitytracker.AsyncEntityTracker; | ||
| import com.windpvp.windspigot.config.WindSpigotConfig; | ||
|
|
@@ -73,24 +71,7 @@ public void run() { | |
| // this.methodProfiler.a("tracker"); | ||
| if (MinecraftServer.getServer().getPlayerList().getPlayerCount() != 0) // Tuinity | ||
| { | ||
| // Tuinity start - controlled flush for entity tracker packets | ||
| List<NetworkManager> disabledFlushes = new java.util.ArrayList<>( | ||
| MinecraftServer.getServer().getPlayerList().getPlayerCount()); | ||
| for (EntityPlayer player : MinecraftServer.getServer().getPlayerList().players) { | ||
| PlayerConnection connection = player.playerConnection; | ||
| if (connection != null) { | ||
| connection.networkManager.disableAutomaticFlush(); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good that this is replaced, I took a look and the tuinity patch implementation seemed very broken. |
||
| disabledFlushes.add(connection.networkManager); | ||
| } | ||
| } | ||
| try { | ||
| worldserver.getTracker().updatePlayers(); | ||
| } finally { | ||
| for (NetworkManager networkManager : disabledFlushes) { | ||
| networkManager.enableAutomaticFlush(); | ||
| } | ||
| } | ||
| // Tuinity end - controlled flush for entity tracker packets | ||
| worldserver.getTracker().updatePlayers(); | ||
| } | ||
|
|
||
| worldserver.timings.tracker.stopTiming(); // Spigot | ||
|
|
@@ -103,4 +84,4 @@ public ResettableLatch getLatch() { | |
| return latch; | ||
| } | ||
|
|
||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the point of this method with flush enabled?
If flushing, why not just use dispatchPacket in NetworkManager?