feat(network): grow the send buffer on demand instead of disconnecting (#2639)
## Problem A connection's send buffer is a fixed 256 KB. A burst of world traffic (a crowded area, a mass spawn, a war) that outruns the client's acknowledgements fills it, `NetState.Send()` reports "send buffer exhausted", and the player is disconnected. Raising the size for everyone multiplies the per-connection footprint (4096 × 256 KB is already 1 GB at full occupancy, page-locked on Windows). ## What changes - **Growth.** When a packet does not fit (the write span is too small, the packet is larger than the span, or compression returns 0), `Send()` asks the transport to grow the buffer to the next power-of-two tier and retries, up to `network.sendBufferMaxSize` (2 MB). Compression retries once per tier since its output size is not known in advance, including when the buffer is completely full. Only when growth is refused does the existing exhaustion disconnect run. The success path is unchanged. - **Memory ceiling.** Growth is refused (with a once-a-minute warning) when the process working set exceeds `network.memoryCeilingPercent` (80) of the memory available to the process (container-aware; `0` turns the check off). The figure is sampled at startup and refreshed each maintenance tick. - **Shrink.** A grown socket returns to the base buffer once it is drained and 30 s have passed since its last growth, attempted from the `DataSent` handler and from the 5 s alive sweep. - **Retention.** Every minute a timer calls the transport's `Maintain()`, which trims idle tier slabs down to the peak concurrent usage of the last 15 minutes, so recurring bursts reuse buffers without allocation while rare ones give the memory back. The line logs at Debug, and only when capacity, usage, or the floor changed or a growth was refused (budget, at max, or ceiling), so an idle shard logs nothing. - **Budget.** `network.sendBufferGrowthBudget` (256 MB) caps the tier pools' capacity; a positive value below one tier slab is raised with a warning, a negative one is clamped to 0 (growth off). Worst case is base × connections plus the budget. - Settings are coerced with accurate warnings (power of two, minimum, 256 MB transport ceiling). `[dumpnetstates` gains the send buffer size. `dev-docs/server-requirements.md` describes the new memory story. ## Tests `NetStateSendBufferTests` (real loopback sockets): growth instead of disconnect with a byte-exact stream, compressed growth against the compressor's own output, the grow-then-copy path, growth with a send genuinely in flight, refusal past the maximum, refusal under the ceiling, refusal on a closing socket, shrink after the hold (direct and through the alive sweep), and the setting coercions. Server.Tests 891 passed, UOContent.Tests 1052 passed against the published 1.0.12. Reviewed per task, whole-branch, and adversarially by a second model (twice, the second time jointly with the transport branch); all findings addressed.
This commit is contained in:
parent
c02909e2c8
commit
31cd19b05b
8 changed files with 761 additions and 48 deletions
|
|
@ -68,8 +68,13 @@ Optional systems can add substantially more. The pathfinding prebake
|
|||
(`pathfinding.prebakeMaps`) peaks above 1 GB of heap while baking. Budget for it or leave it off on
|
||||
small hosts.
|
||||
|
||||
Network buffers are minor by comparison: 64 KB receive plus a configurable 256 KB send
|
||||
(`network.sendBufferSize`) per connection, so 100 players is roughly 32 MB.
|
||||
Network buffers are 64 KB receive plus a configurable send buffer per connection. Send memory is
|
||||
`network.sendBufferSize` at rest and can grow to `network.sendBufferMaxSize` under load. Shared
|
||||
send-buffer tier memory is capped by `network.sendBufferGrowthBudget`, and growth is refused when
|
||||
process memory exceeds `network.memoryCeilingPercent` of available memory. The worst case is the
|
||||
base send-buffer size times the connection count, plus the shared growth budget: at the defaults,
|
||||
100 players is roughly 32 MB at rest, and the growth budget can add up to another 256 MB under
|
||||
load.
|
||||
|
||||
ModernUO runs **Workstation GC**, which is the right default for small hosts. Do not switch to
|
||||
Server GC on a 2-core box.
|
||||
|
|
@ -110,6 +115,9 @@ See the README for the full supported list. Two things are worth calling out:
|
|||
| `world.useMultithreadedSaves` | `true` | Set `false` on 2-core hosts so saves do not contend with the game loop. |
|
||||
| `pathfinding.prebakeMaps` | varies | Leave off on memory-constrained hosts; it peaks above 1 GB while baking. |
|
||||
| `network.sendBufferSize` | 256 KB | Lower it if you are memory-bound with many connections. |
|
||||
| `network.sendBufferMaxSize` | 2 MB (`2097152`) | Ceiling a single connection's send buffer can grow to under load. Lower it on memory-constrained hosts; raise it if slow clients are disconnected with "send buffer exhausted". |
|
||||
| `network.sendBufferGrowthBudget` | 256 MB (`268435456`) | Cap on the shared memory the larger send-buffer tiers may use. Lower it on memory-constrained hosts. |
|
||||
| `network.memoryCeilingPercent` | 80% | Refuse send-buffer growth once the process is above this share of available memory; 0 turns the check off. |
|
||||
| `autoArchive.*` retention | 24h/30d/12m | Reduce if disk is tight. |
|
||||
|
||||
## Am I undersized?
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue