feat: MMO-scale world server with lazy zones, terrain, perf optimisations#65
Merged
feat: MMO-scale world server with lazy zones, terrain, perf optimisations#65
Conversation
Create the missing guide files that were referenced from README, getting-started, configuration, and world-server docs. Both guides point to asobi_lua (the standalone Lua runtime package) for full documentation. Register guides in ex_doc extras config.
…isations Scales the world server to handle large tile-based MMOs (128K x 128K+ tiles, 500+ players per shard). ## New modules - `asobi_zone_manager` — lazy zone lifecycle with on-demand spawn and idle reaping - `asobi_terrain` — pure functional chunk encode/decode/compress - `asobi_terrain_provider` — behaviour for terrain data sources - `asobi_terrain_store` — ETS cache with lazy loading and generate fallback - `asobi_spatial_grid` — O(1) cell-based spatial index for entity queries - `asobi_ws_binary` — opt-in binary WebSocket protocol (TLV format) ## Zone system changes - Lazy zone loading with configurable idle timeout and max active zones - Zones hibernate when empty, touch zone_manager on tick - Zones serve terrain chunks on subscribe (one-shot, not per-tick) - Zone manager uses ETS fast-path for hot lookups ## World server integration - New optional behaviour callbacks: `terrain_provider/1`, `on_zone_loaded/2`, `on_zone_unloaded/2` - Terrain store started automatically when game module provides a terrain_provider - Zone manager wired into supervision tree ## Performance optimisations - Broadcast batching: encode delta once, send pre-encoded binary to all subscribers - Adaptive tick rates: hot zones (full rate), cold zones (reduced), empty zones (not ticked) - Spatial grid: O(1) cell lookup replaces O(n) maps:fold - Binary protocol: ~25% savings vs JSON+base64 ## Config keys - `lazy_zones` (auto-true when grid_size > 100) - `zone_idle_timeout` (default 30000ms) - `max_active_zones` (default 10000) - `spatial_grid_cell_size` (opt-in spatial index) - `cold_tick_divisor` (default 10) ## Tests - 65+ new tests covering terrain, zone manager, spatial grid, broadcast batching, adaptive ticks, binary protocol, and end-to-end integration - All 230 existing tests still pass ## Docs - New guides: large-worlds.md, performance-tuning.md - Updated world-server.md with link to large-worlds
- asobi_spatial:query_rect returns [{binary(), map()}], not 3-tuples
- Terrain serving block: bind unmatched return value
- terminate_zone result: explicitly ignore with _ =
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Scales the world server to handle large tile-based MMOs (128K x 128K+ tiles, 500+ players per shard). Validated with a 5-minute benchmark of 500 real WebSocket players on a 2000x2000 zone grid: 6.4M messages, 9.88 GB of delta updates, zero failures.
Key additions
asobi_terrainencoding,asobi_terrain_providerbehaviour,asobi_terrain_storecache. Serves 2-4KB compressed chunks on zone subscribe.terrain_provider/1,on_zone_loaded/2,on_zone_unloaded/2.Benchmark results (500 players, 2000x2000 grid, 5 min)
Test plan
Related