Optimize Network Manager to not need synchronization

Removes synchronization from sending packets
Makes normal packet sends no longer need to be wrapped and queued like it use to work.
Adds more packet queue immunities on top of keep alive to let the following scenarios go out
without delay:
  - Keep Alive
  - Chat
  - Kick
  - All of the packets during the Player Joined World event

Hoping that latter one helps join timeout issues more too for slow connections.

Removes processing packet queue off of main thread
  - for the few cases where it is allowed, order is not necessary nor
    should it even be happening concurrently in first place (handshaking/login/status)

Ensures packets sent asynchronously are dispatched on main thread

This helps ensure safety for ProtocolLib as packet listeners
are commonly accessing world state. This will allow you to schedule
a packet to be sent async, but itll be dispatched sync for packet
listeners to process.

This should solve some deadlock risks

This may provide a decent performance improvement because thread synchronization incurs a cache reset
so by avoiding ever entering a synchronized block, we get to avoid that, and packet sending is a really
hot activity.
This commit is contained in:
Aikar
2020-05-06 05:22:03 -04:00
parent 30d007b163
commit fd5c98a9ef
141 changed files with 604 additions and 505 deletions

View File

@@ -6,7 +6,7 @@ Subject: [PATCH] Make the GUI graph fancier
diff --git a/src/main/java/com/destroystokyo/paper/gui/GraphColor.java b/src/main/java/com/destroystokyo/paper/gui/GraphColor.java
new file mode 100644
index 0000000000..a4e641fdcc
index 00000000000..a4e641fdccc
--- /dev/null
+++ b/src/main/java/com/destroystokyo/paper/gui/GraphColor.java
@@ -0,0 +0,0 @@
@@ -56,7 +56,7 @@ index 0000000000..a4e641fdcc
+}
diff --git a/src/main/java/com/destroystokyo/paper/gui/GraphData.java b/src/main/java/com/destroystokyo/paper/gui/GraphData.java
new file mode 100644
index 0000000000..186fc72296
index 00000000000..186fc722965
--- /dev/null
+++ b/src/main/java/com/destroystokyo/paper/gui/GraphData.java
@@ -0,0 +0,0 @@
@@ -109,7 +109,7 @@ index 0000000000..186fc72296
+}
diff --git a/src/main/java/com/destroystokyo/paper/gui/GuiStatsComponent.java b/src/main/java/com/destroystokyo/paper/gui/GuiStatsComponent.java
new file mode 100644
index 0000000000..0f29ad583e
index 00000000000..0f29ad583e7
--- /dev/null
+++ b/src/main/java/com/destroystokyo/paper/gui/GuiStatsComponent.java
@@ -0,0 +0,0 @@
@@ -156,7 +156,7 @@ index 0000000000..0f29ad583e
+}
diff --git a/src/main/java/com/destroystokyo/paper/gui/RAMDetails.java b/src/main/java/com/destroystokyo/paper/gui/RAMDetails.java
new file mode 100644
index 0000000000..e463a86a6a
index 00000000000..e463a86a6ad
--- /dev/null
+++ b/src/main/java/com/destroystokyo/paper/gui/RAMDetails.java
@@ -0,0 +0,0 @@
@@ -236,7 +236,7 @@ index 0000000000..e463a86a6a
+}
diff --git a/src/main/java/com/destroystokyo/paper/gui/RAMGraph.java b/src/main/java/com/destroystokyo/paper/gui/RAMGraph.java
new file mode 100644
index 0000000000..c3e54da4ab
index 00000000000..c3e54da4ab6
--- /dev/null
+++ b/src/main/java/com/destroystokyo/paper/gui/RAMGraph.java
@@ -0,0 +0,0 @@
@@ -385,7 +385,7 @@ index 0000000000..c3e54da4ab
+ }
+}
diff --git a/src/main/java/net/minecraft/server/GuiStatsComponent.java b/src/main/java/net/minecraft/server/GuiStatsComponent.java
index c21db8e6b7..7b6e935257 100644
index c21db8e6b79..7b6e9352578 100644
--- a/src/main/java/net/minecraft/server/GuiStatsComponent.java
+++ b/src/main/java/net/minecraft/server/GuiStatsComponent.java
@@ -0,0 +0,0 @@ import javax.swing.Timer;
@@ -398,7 +398,7 @@ index c21db8e6b7..7b6e935257 100644
});
private final int[] b = new int[256];
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
index 63db74993c..d1f82eff21 100644
index 63db74993c1..d1f82eff218 100644
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
@@ -0,0 +0,0 @@ public abstract class MinecraftServer extends IAsyncTaskHandlerReentrant<TickTas
@@ -411,7 +411,7 @@ index 63db74993c..d1f82eff21 100644
private KeyPair I;
@Nullable
diff --git a/src/main/java/net/minecraft/server/ServerGUI.java b/src/main/java/net/minecraft/server/ServerGUI.java
index 95561d9db4..470009fe4c 100644
index 95561d9db4b..470009fe4c4 100644
--- a/src/main/java/net/minecraft/server/ServerGUI.java
+++ b/src/main/java/net/minecraft/server/ServerGUI.java
@@ -0,0 +0,0 @@ public class ServerGUI extends JComponent {