Skip to content
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

First look at specialized network compression threads #5805

Open
wants to merge 12 commits into
base: minor-next
Choose a base branch
from

Conversation

dktapps
Copy link
Member

@dktapps dktapps commented Jun 5, 2023

Introduction

As described in #5641, using AsyncTasks for compression is no longer cost-effective, due to the large overhead of creating an AsyncTask and scheduling it.

This PR introduces a specialized thread pool for network compression, which once again makes threaded compression practical.
It also uses Snooze to minimize latency.

The current implementation isn't optimal, but it's much faster than using AsyncTasks.

Relevant issues

#5641

Changes

API changes

No public API changes - this is all network internals.

Behavioural changes

  • Several more threads are now started by the server, specifically to handle compression. These threads have a memory footprint of 1-2 MB each, which may become noticeable with large numbers of threads.
  • network.async-compression in pocketmine.yml is now ignored, as is network.async-compression-threshold.
  • A new setting network.compression-threads has been added, with a default of 0 (for now). This can be set to a positive integer or auto in a similar manner to settings.async-workers.

Backwards compatibility

Fully backwards compatible.

Follow-up

Explore whether chunk prepare and compression needs similar treatment. Chunk handling bypasses the usual systems using ChunkRequestTask, which is not modified here.

Tests

This has been mostly playtested and benchmarked on Windows. Unit tests TBD.

closes #5641

This has been mostly tested on Windows so far, where it offers substantial performance gains for compression.
On *nix, the performance advantage is smaller, since there's less overhead to creating new AsyncTask instances; however, the performance benefit is still clearly visible.

There are still some wrinkles to iron out, such as the dumb algorithm used for cycling through threads which wastes memory on small servers, but this change is mainly aimed at large servers, where the benefit will be clearly apparent.
In practice, this should reduce main thread CPU load by 10-20% on some of the largest servers, offering a large amount of headroom for increased player counts.
@dktapps dktapps added Category: Core Related to internal functionality Status: Insufficiently Tested Type: Enhancement Contributes features or other improvements to PocketMine-MP Performance Scalability labels Jun 5, 2023
dktapps added 2 commits June 5, 2023 21:21
CompressBatchTask is kept for internal testing for now
@ShockedPlot7560
Copy link
Member

Related to: #1161

@dktapps
Copy link
Member Author

dktapps commented Jul 13, 2023

Yes, I'd actually forgotten about that issue. Though this change doesn't solve #1161 entirely.

@dktapps dktapps added this to the 5.7 milestone Sep 6, 2023
@dktapps dktapps modified the milestones: 5.8, 5.9 Nov 9, 2023
@dktapps
Copy link
Member Author

dktapps commented Nov 9, 2023

User reports suggest that this change may offer a substantial performance improvement to certain types of servers.

@dktapps dktapps changed the base branch from minor-next to stable November 13, 2023 11:18
@dktapps dktapps changed the base branch from stable to minor-next November 13, 2023 11:18
@dktapps
Copy link
Member Author

dktapps commented Nov 13, 2023

This is potentially affected by pmmp/ext-pmmpthread#42, but profiling suggests that the issue should be minimal for the situations that the ThreadSafeArrays used here are subjected to

@dktapps
Copy link
Member Author

dktapps commented Nov 15, 2023

This should probably include some kind of GC mechanism to dispose of idle pools and free up memory

@dktapps dktapps modified the milestones: 5.9, 5.11 Dec 20, 2023
@dktapps dktapps removed this from the 5.11 milestone Mar 1, 2024
@dktapps dktapps added this to the 5.13 milestone Mar 1, 2024
Joshy3282 added a commit to Joshy3282/PocketMine-MP that referenced this pull request Oct 2, 2024
could be buggy according to pr but wtv
Joshy3282 added a commit to Joshy3282/PocketMine-MP that referenced this pull request Oct 2, 2024
@dktapps dktapps removed this from the 5.14 milestone Nov 16, 2024
@dktapps dktapps self-assigned this Dec 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Category: Core Related to internal functionality Performance Status: Incomplete Work in progress Type: Enhancement Contributes features or other improvements to PocketMine-MP
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants