WIP: feat(server): move the eviction write-back diff onto the worker pool #28
No reviewers
Labels
No labels
Compat/Breaking
Kind/Bug
Kind/Documentation
Kind/Enhancement
Kind/Feature
Kind/Security
Kind/Testing
Priority
Critical
Priority
High
Priority
Low
Priority
Medium
Reviewed
Confirmed
Reviewed
Duplicate
Reviewed
Invalid
Reviewed
Won't Fix
scope/assets
scope/client
scope/networking
scope/renderer
scope/scripting
scope/server
scope/shared
scope/workspace
Status
Abandoned
Status
Blocked
Status
Need More Info
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
Synvael/synvael!28
Loading…
Reference in a new issue
No description provided.
Delete branch "feat/async-write-back"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
What does this PR do?
Eviction in
ServerWorld::reconcileno longer diffs the chunk on the tick thread. I added aJob::WriteBack { pos, chunk, worldgen_version }.reconcilehands the evicted chunk to the pool by value, and the worker resolves the baseline through the sharedChunkCache, builds theChunkData::from_diff, and sendsSaveRequest::WriteorRemoveto the save actor itself. The diff moved into a free function,write_back_chunk, which keeps the existing behaviour of stamping the diff with the chunk's own worldgen version. A chunk withload_failedis still skipped before dispatch.Because the write now happens after
reconcilereturns, a fast evict and re-request could read the old record. I added a guard:ServerWorldhas apending_write_backsset and awrite_back_rxchannel. A worker reports the position on that channel only after itsSaveRequesthas been sent, so the actor's in-order handling places the write before any later read.reconciledrainswrite_back_rxfirst. It does not dispatch aLoadfor a position still in the set, and dispatches it on a later pass. Deferred positions count towardStreamStats::in_flight, so a caller looping until it reaches zero still sees every wanted chunk resident.StreamStatsgainedwrite_backs_in_flight,ServerWorldgainedwrite_backs_in_flight(), andstreaming_idle()now also requires an empty pending set.shutdownevicts everything and then closes the job channel, so the workers finish every queued write-back before they are joined and before the final flush. It now returnsSaveError::Invalidif a worker panicked, since a write-back may have been lost.flushdoes not wait for the pool, so the autosave cannot stall the tick behind queued work. A write-back still on a worker lands after that flush and is covered by the next one or byshutdown.I also removed the
current_versionfield fromServerWorld, which nothing reads any more. Test-onlyJob::PanicandJob::Parkhold the pool back or kill a worker.Docs:
docs/save_format.md("Concurrency and the save actor") anddocs/chunk_streaming.md(the drain, evict and dispatch phases) describe where the diff runs and the guard.Why is this change necessary?
An eviction pass regenerated or fetched the baseline and ran
ChunkData::from_diffon the tick thread for every evicted chunk. Crossing a chunk boundary evicts a whole edge slab at once, so that cost landed on a single tick. Chunk loads and delivery encodes already run on the worker pool, and the eviction diff was the remaining heavy step on the tick thread. This is a performance change and not a correctness fix.Scope of Changes
server, workspace
Testing
Automated, run from this worktree.
rendererandclientcannot build on this machine becauseninjais missing, so every command excludes them (--exclude renderer --exclude client):cargo fmt --all -- --check: clean.cargo clippy --all-targets --all-features --workspace --exclude renderer --exclude client -- -D warnings: clean.cargo test -p server: 113 passed, 0 failed.cargo test --workspace --exclude renderer --exclude client --all-features --profile ci: all suites passed (server 113, plus 48, 25 and 360 in the other crates).New tests in
crates/server/src/tests/world_server.rs:a_chunk_desired_again_waits_for_its_write_back: evicts an edited chunk with the pool parked, desires it again on the next pass, and checks the load is held back and the reloaded chunk holds the edit.shutdown_lands_every_pending_write_back_before_the_final_flusha_panicked_worker_is_reported_by_shutdown_and_never_stalls_flushflush_does_not_wait_for_parked_write_backsThe existing
flushtest helper now takes&mut ServerWorldand drains the pool before it flushes. No existing test body changed.Tick time on an eviction-heavy pass:
feat/entity-chunk-lifecycle)TODO: maintainer. Fill in the pass used (for example the radius-16 walk) and the machine.
tick_stats.rsrecords the tick body per window but the existing tests do not drive an eviction pass through it, so I did not take this measurement.Manual check, not yet done:
Additional Context
Stacks on #24 (feat/entity-chunk-lifecycle); review that one first.
This PR stacks on the open pull request for
feat/entity-chunk-lifecycle, not ondev. The diff against that branch is what is described here, and it will need a retarget todevonce that pull request merges. It builds on the loaded and evicted reporting inStreamStatsfrom that branch.Entity records are still written from the tick thread on eviction, which keeps their ordering trivially safe. The
ChunkCacheis still keyed by position alone; the existing note about that moved with the code intowrite_back_chunk.The one visible behaviour change is that a chunk desired again right after eviction loads one or more passes later than before, while its write-back is pending.
Related Issues
None.
Checklist
dev(or a feature branch offdev) and my PR targetsdev. (Branched from the feature branchfeat/entity-chunk-lifecycle, which is itself offdev; the PR targets that branch until it merges.)///doc comments for Rust) where necessary.View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.