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

Async chunk I/O #6560

Open
dktapps opened this issue Dec 5, 2024 · 2 comments
Open

Async chunk I/O #6560

dktapps opened this issue Dec 5, 2024 · 2 comments
Labels
BC break Breaks API compatibility Category: Core Related to internal functionality Opinions Wanted Request for comments & opinions from the community Performance Type: Enhancement Contributes features or other improvements to PocketMine-MP

Comments

@dktapps
Copy link
Member

dktapps commented Dec 5, 2024

Problem description

I attempted to implement async chunk I/O in PM as far back as 2017 in #1895.
However, this PR failed for a variety of reasons, including complexity, bugs, and huge impact to API (and therefore plugins).

Async chunk I/O is no longer as in-demand as it was a few years ago, due to massive improvements in server disk hardware (NVMe and the like), but it would still be desirable if done right. However, the advantage has to be weighed against the cost of transmitting the data between threads, since serialization & deserialization for passing stuff between threads can have significant costs of its own.

Proposed solution

The biggest obstacle is that, in order to avoid major sweeping API breaks for a multitude of functions, we'd need to support both sync and async chunk I/O, because many API methods directly used by plugins currently auto-load chunks synchronously, and there isn't a clear way to avoid significant increases in complexity for tasks as simple as getBlock() unless synchronous chunk loading is supported.

(However, it's worth mentioning that plugins seem to have adapted fairly well to the use of Promises for generation, and major advances have been made overall since 2018, so maybe this might be easier in 2024 than back then.)

#1895 was abandoned because I'd designed it in such a way that made it impossible to support both sync and async chunk loading. A better solution might involve using ThreadSafe objects to create waitable Futures or something of that nature. That way, stuff that doesn't require sync chunk loading (like players) can request & wait, while stuff that does need sync loading could wait on the future (which would block the main thread as I/O currently does).

Alternative solutions that don't require API changes

@dktapps dktapps added Category: Core Related to internal functionality BC break Breaks API compatibility Type: Enhancement Contributes features or other improvements to PocketMine-MP Performance Opinions Wanted Request for comments & opinions from the community labels Dec 5, 2024
@dadodasyra
Copy link

dadodasyra commented Dec 19, 2024

Async chunk I/O is no longer as in-demand as it was a few years ago

image
image
image
(faction & minage are pm servers)
And that's not auto saves. I mean, firstly, why does pm saves to disk on each chunk unload ? What's the purpose of auto saving if it's live saving and there's no cache at all. + It seems like a terrible idea on leveldb which seems to rewrite bunch of useless data due to the fact that it's not regions anymore but huge files.

@dktapps
Copy link
Member Author

dktapps commented Dec 19, 2024

why does pm saves to disk on each chunk unload?

What else is it supposed to do? Unloading a chunk means deleting it from memory. It has to save it if there were modifications. The cache is World->chunks. Not sure what more you want.

It seems like a terrible idea on leveldb which seems to rewrite bunch of useless data due to the fact that it's not regions anymore but huge files.

Yeah, leveldb as per vanilla's usage isn't great. A lot of it is to do with key sorting - data gets put next to each other because of the key format that wouldn't be next to each other in the actual world. Similar reason why we use morton codes for internal array indexing. However, it shouldn't be rewriting whole files, just compressed blocks of data (usually 64KB).

Most likely the problem you're seeing is something to do with auto compaction and not to do with PM's actual I/O activity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BC break Breaks API compatibility Category: Core Related to internal functionality Opinions Wanted Request for comments & opinions from the community Performance Type: Enhancement Contributes features or other improvements to PocketMine-MP
Projects
None yet
Development

No branches or pull requests

2 participants