test old async stuff to fix load hang

This commit is contained in:
Bud Gidiere 2020-09-20 17:30:33 -05:00
parent f541b93c6a
commit 6e3d09cf54
No known key found for this signature in database
GPG Key ID: CD18F99E348902F7
3 changed files with 98 additions and 83 deletions

View File

@ -64,7 +64,7 @@ # Patches
| server | Implement bed explosion options | William Blake Galbreath | |
| server | Implement respawn anchor explosion options | William Blake Galbreath | |
| server | Improve Hopper Performance | Aikar | |
| server | Improve async task handler | ishland | |
| server | Improve task performance | ishland | |
| server | Item stuck sleep config | tr7zw | |
| api | Kill AnnotationTest | tr7zw | |
| server | Lagging threshold | William Blake Galbreath | |

View File

@ -1,82 +0,0 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: ishland <ishlandmc@yeah.net>
Date: Sun, 20 Sep 2020 19:43:03 +0300
Subject: [PATCH] Improve async task handler
Replace ConcurrentLinkedQueue and LockSupport hacks to reduce execute times
diff --git a/src/main/java/net/minecraft/server/IAsyncTaskHandler.java b/src/main/java/net/minecraft/server/IAsyncTaskHandler.java
index 5df6be7e8d9b1295ed0700b3be90c3778fc7d77c..95aec7d4705a7a275fe7f5d6aec877dd7ad0f529 100644
--- a/src/main/java/net/minecraft/server/IAsyncTaskHandler.java
+++ b/src/main/java/net/minecraft/server/IAsyncTaskHandler.java
@@ -13,8 +13,9 @@ public abstract class IAsyncTaskHandler<R extends Runnable> implements Mailbox<R
private final String b;
private static final Logger LOGGER = LogManager.getLogger();
- private final Queue<R> d = Queues.newConcurrentLinkedQueue();
+ private final java.util.concurrent.LinkedBlockingDeque<R> d = new java.util.concurrent.LinkedBlockingDeque<>(); // Yatopia
private int e;
+ private R next = null; // Yatopia
protected IAsyncTaskHandler(String s) {
this.b = s;
@@ -79,7 +80,7 @@ public abstract class IAsyncTaskHandler<R extends Runnable> implements Mailbox<R
public final void addTask(R r0) { a(r0); }; // Paper - OBFHELPER
public void a(R r0) {
this.d.add(r0);
- LockSupport.unpark(this.getThread());
+ //LockSupport.unpark(this.getThread()); // Yatopia - replaced by LinkedBlockingQueue
}
public void execute(Runnable runnable) {
@@ -92,21 +93,30 @@ public abstract class IAsyncTaskHandler<R extends Runnable> implements Mailbox<R
}
public void executeAll() { // Paper - protected -> public
+ /* // Yatopia start - replaced logic
while (this.executeNext()) {
;
}
+ */
+ while (!d.isEmpty()) {
+ if (next == null) queuePull();
+ if (!executeNext()) break;
+ }
+ // Yatopia end
}
protected boolean executeNext() {
- R r0 = this.d.peek(); // Paper - decompile fix
+ R r0 = next; // Paper - decompile fix // Yatopia - temp storage
+ if (next == null || !d.isEmpty()) queuePull(); // Yatopia - attempt to get from queue
if (r0 == null) {
return false;
} else if (this.e == 0 && !this.canExecute(r0)) {
return false;
} else {
- this.executeTask(this.d.remove()); // Paper - decompile fix
+ this.executeTask(r0); // Paper - decompile fix // Yatopia - replaced with r0
+ next = null; // Yatopia - clear temp for next task
return true;
}
}
@@ -126,9 +136,17 @@ public abstract class IAsyncTaskHandler<R extends Runnable> implements Mailbox<R
}
+ protected final void queuePull() { bl(); } // Yatopia - OBFHELPER
protected void bl() {
+ /* // Yatopia start - replaced logic
Thread.yield();
LockSupport.parkNanos("waiting for tasks", 100000L);
+ */
+ next = null;
+ try {
+ next = d.poll(100, java.util.concurrent.TimeUnit.MICROSECONDS);
+ } catch (InterruptedException ignored) {}
+ // Yatopia end
}
protected void executeTask(R r0) {

View File

@ -0,0 +1,97 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: ishland <ishlandmc@yeah.net>
Date: Sun, 20 Sep 2020 00:05:44 +0800
Subject: [PATCH] Improve task performance
Replace ConcurrentLinkedQueue + LockSupport hack to reduce time
consumption of addTask(R)V
diff --git a/src/main/java/net/minecraft/server/IAsyncTaskHandler.java b/src/main/java/net/minecraft/server/IAsyncTaskHandler.java
index 5df6be7e8d9b1295ed0700b3be90c3778fc7d77c..7910d95bdd42ed97a5cab75c0da5bdacf030b92f 100644
--- a/src/main/java/net/minecraft/server/IAsyncTaskHandler.java
+++ b/src/main/java/net/minecraft/server/IAsyncTaskHandler.java
@@ -1,11 +1,12 @@
package net.minecraft.server;
import com.google.common.collect.Queues;
+
import java.util.Queue;
-import java.util.concurrent.CompletableFuture;
-import java.util.concurrent.Executor;
+import java.util.concurrent.*;
import java.util.concurrent.locks.LockSupport;
import java.util.function.BooleanSupplier;
+
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@@ -13,9 +14,11 @@ public abstract class IAsyncTaskHandler<R extends Runnable> implements Mailbox<R
private final String b;
private static final Logger LOGGER = LogManager.getLogger();
- private final Queue<R> d = Queues.newConcurrentLinkedQueue();
+ private final LinkedBlockingDeque<R> d = new LinkedBlockingDeque<>(); // Yatopia - improve task performance
private int e;
+ private R next = null; // Yatopia - improve task performance - temp storage for next object
+
protected IAsyncTaskHandler(String s) {
this.b = s;
}
@@ -79,7 +82,7 @@ public abstract class IAsyncTaskHandler<R extends Runnable> implements Mailbox<R
public final void addTask(R r0) { a(r0); }; // Paper - OBFHELPER
public void a(R r0) {
this.d.add(r0);
- LockSupport.unpark(this.getThread());
+ // LockSupport.unpark(this.getThread()); // Yatopia - improve task performance - replaced by LinkedBlockingQueue
}
public void execute(Runnable runnable) {
@@ -92,21 +95,27 @@ public abstract class IAsyncTaskHandler<R extends Runnable> implements Mailbox<R
}
public void executeAll() { // Paper - protected -> public
- while (this.executeNext()) {
- ;
+ // Yatopia start - replaced logic
+ while (!d.isEmpty()) {
+ if(next == null) bl();
+ if(!executeNext()) break;
}
+ // Yatopia end
}
protected boolean executeNext() {
- R r0 = this.d.peek(); // Paper - decompile fix
+ R r0 = next; // Paper - decompile fix // Yatopia - replaced with temp storage
+
+ if(next == null && !d.isEmpty()) bl(); // Yatopia - attempt to get from queue
if (r0 == null) {
return false;
} else if (this.e == 0 && !this.canExecute(r0)) {
return false;
} else {
- this.executeTask(this.d.remove()); // Paper - decompile fix
+ this.executeTask(r0); // Paper - decompile fix // Yatopia - replaced with current r0
+ next = null; // Yatopia - clear storage for next task
return true;
}
}
@@ -127,8 +136,13 @@ public abstract class IAsyncTaskHandler<R extends Runnable> implements Mailbox<R
}
protected void bl() {
- Thread.yield();
- LockSupport.parkNanos("waiting for tasks", 100000L);
+ // Yatopia start - replaced logic
+ next = null;
+ try {
+ next = d.poll(100, TimeUnit.MICROSECONDS);
+ } catch (InterruptedException ignored) {
+ }
+ // Yatopia end
}
protected void executeTask(R r0) {