tick: game steps read, clone and commit character rows through the store on the tick goroutine (about 12 ms a tick at 105 players)

未关闭
#3,099 3 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
5/5
预计耗时
一周以上
新手友好度
18/100
Issue 类型
重构
描述清晰度
基本清楚
活跃度
活跃
技术栈
go

调研方向

Start from Ticker.runScheduledTick and Ticker.runDivision to see which game steps call store.ReadState through enterworld.Deps.Read and Deps.runCharacterUpdate, then follow the commit path (commitCheckedLocked, commitTxLocked, upsertTimedTx). Done means one shared read per character per tick, deferred updates where possible, a 100-player benchmark, and a live capture under 3 ms per tick. This needs store and tick-loop knowledge, so it is not a first task.

由索引模型根据 Issue 内容生成。

描述

area: server enhancement priority: high status: gated

Live capture 2026-11-10 20:03Z on release 1dd0e9948 with 105 sessions attached (sro-tickbudget capture, loopback profiler): 954 ticks, 61.1 ms per tick (phase:total, exact from tick_zones), against the 10 ms target of #2150. CPU numbers below are the 30 s profile over the 301 ticks its bracketing snapshots count, stacks through Ticker.runScheduledTick or Ticker.runDivision only. At 18:00Z with 29 players the same server showed p99 60 ms; at 105 players p50 is 60 ms and p99 120 ms: these costs grow with players.

What costs

The action hook is 19.9 ms of the tick, and most of its CPU is the store, reached from game steps on the tick goroutine:

Work on the tick goroutine ms per tick
store.ReadState (through enterworld.Deps.Read) 7.1
character updates (Deps.runCharacterUpdate) 5.1
commits inside those updates (commitCheckedLocked, commitTxLocked; upsertTimedTx 3.9) 5.3
character clones (Character.snapshotWith, cloneCharacterFiltered) 3.3

Who reads (share of the 7.1 ms): characterSnapshotCast 28%, companionPresentations 14%, questMarkerTick 11%, PopulationPlayers 9%, WorldSnapshotInto 8%, characterSnapshotCombatAdmitted 6%, monsterRewardRoster 5%, then a long tail. Who writes: Deps.Update is 70% of the update time (immediate), UpdateDeferred 18%, UpdateManyDeferred 8%.

The same character is read and cloned several times inside one tick by different steps, and an immediate Update pays a commit inside the tick. #2032 (ReadState 8% of tick CPU) and #2141 closed, and the cost is back at this load. The async writer of #2944 (SRO_STORE_ASYNC_COMMIT) is merged and off on the live shard.

Done when

  • One read per character per tick: the steps of one tick share a snapshot instead of each calling ReadState; a write in the tick invalidates it. The invariant is written where the cache lives.
  • Tick steps use the deferred update path unless a step proves it needs the row committed before the next step; each remaining immediate Update on the tick path is listed with its reason.
  • A benchmark at 100 synthetic players pins the store's share of the action hook, and the allocation budget test covers the clones.
  • A live capture after release shows ReadState plus character updates under 3 ms per tick at about 100 players.
  • Separate owner decision, not part of the code: whether the live shard turns SRO_STORE_ASYNC_COMMIT on. Record the live numbers that argue for or against it here.

Part of #2150.

主要语言
Go
星标
97
派生
61
平均合并
4 小时 14 分钟
30 天内合并 PR
913

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

opensro-dev/opensro 的其他 Issue

查看 opensro-dev/opensro 的全部 Issue

相似的 Issue

更多 Go Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。