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

Less terrible chunk sending #138

Draft
wants to merge 17 commits into
base: master
Choose a base branch
from
Draft

Conversation

ReCore-sys
Copy link
Collaborator

@ReCore-sys ReCore-sys commented Dec 10, 2024

This PR fixes the atrocious chunk sending system I implemented before. Turns out simply hurling over 500 chunks at a client every 5 seconds was a sub-optimal strategy, who would have guessed?

Description

This PR implements a smarter "on-demand" chunk sending system to avoid overloading both the server and the client. The previous system had many flaws, including huge lag spikes for both the client and the server, extremely delayed chunk loading times, players only receiving world data every 5 seconds leading to extremely long join times, loading and sending heaps of unneeded data and unnecessarily prolonged component locking which has the potential to slow down the entire server. This new system splits the work over many tasks/threads and doesn't fetch or send unnecessary data, massively reducing the load on both the client and the server.
It works by attaching a ChunkReciever component to players and then using that to calculate what chunks the client needs whenever they cross a chunk border, meaning that clients will almost immediately receive the chunks they just came into view range of and also makes sure they aren't sent chunks they can already see. It also splits the work as much as it can by having 2 ECS systems used, one that fetches the chunks from the database and one that sends those chunks to the client. It also uses a separate tokio task for each player when fetching or sending chunk, splitting the work up even further. This approach is explained in more detail in the docs (WIP).
It is important to note that this PR doesn't add support for chunks being updated or chunks being sent over multiple ticks, those will need to be addressed in future PRs.

Motivation and Context

The previous chunk sending system worked (somewhat) and was merged to just get something quick and dirty out the door as soon as possible. This PR massively improves pretty much everything about it, and should hold up for the foreseeable future.

How has this been tested?

These changes are hard to test with unit tests, but has been manually tested extensively. Some deadlocking issues did crop up and while I'm pretty confident they have been fixed, I was unable to reproduce them reliably so there is a chance they might persist.

Screenshots (if appropriate):

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Refactor (restructuring code, without changing its behavior)

Checklist:

  • My code follows the code style of this project.
  • I have added tests to cover my changes.
  • All new and existing tests passed.
  • Clippy passes with no warnings.

@ReCore-sys ReCore-sys linked an issue Dec 10, 2024 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Better chunk sending
1 participant