Skip to content

Commit

Permalink
Adjust backoff times
Browse files Browse the repository at this point in the history
Blocking for too long may introduce unneccesary stalls
  • Loading branch information
Spottedleaf authored and jpenilla committed Jun 21, 2022
1 parent 4fb893c commit b5bc463
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,10 @@ public void saveImage(final Image image) {

long executed = this.imageIOExecutorExecutedTasks.get();
long submitted = this.imageIOExecutorSubmittedTasks.get();
for (int failures = 0; (submitted - executed) >= IMAGEIO_MAX_TASKS; ++failures) {
for (int failures = 1; (submitted - executed) >= IMAGEIO_MAX_TASKS; ++failures) {
boolean interrupted = Thread.interrupted();
LockSupport.parkNanos(TimeUnit.MILLISECONDS.toNanos(Math.min(50, failures)));
Thread.yield();
LockSupport.parkNanos(TimeUnit.MILLISECONDS.toNanos(Math.min(25, failures)));
if (interrupted) {
Thread.currentThread().interrupt();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -485,12 +485,13 @@ private static int applyDepthCheckerboard(final double fluidCountY, final int co

private @Nullable ChunkSnapshot chunkSnapshot(final int x, final int z) {
final CompletableFuture<ChunkSnapshot> future = this.chunkSnapshotProvider.asyncSnapshot(this.level, x, z, false);
for (int failures = 0; !future.isDone(); ++failures) {
for (int failures = 1; !future.isDone(); ++failures) {
if (!this.running()) {
return null;
}
boolean interrupted = Thread.interrupted();
LockSupport.parkNanos(TimeUnit.MILLISECONDS.toNanos(Math.min(100, failures)));
Thread.yield();
LockSupport.parkNanos(TimeUnit.MILLISECONDS.toNanos(Math.min(5, failures)));
if (interrupted) {
Thread.currentThread().interrupt();
}
Expand Down

0 comments on commit b5bc463

Please sign in to comment.