osd: Send queued replies before a peering calculation #199

Merged
vitalif merged 3 commits from koolkhel/vitastor:osd-reply-before-peering into master 2026-11-29 14:13:14 +03:00
Contributor

Description

Follow-up to #197. osd_t::loop() (src/osd/osd.cpp:612) runs handle_peers() first, then read_requests(), send_replies() and submit(). The completions of a pass are handled before the consumers run, so when the loop gets to osd_t::loop(), the replies to the requests that came during a calculation are already queued. If the 1 ms yield timer from #197 fired in the same pass, handle_peers() starts the next calculation first, and those replies go out only after it.

Without other load, the time after a calculation is idle and a ping is answered within it. With client I/O or LIST requests from peers, the first pass after a calculation takes longer than the 1 ms timer, so a ping waits for two calculations instead of one. With 2.5-3 s calculations (~850k objects per PG) two calculations are more than the default osd_ping_timeout (5 s).

The change: continue_pg_peering() sends the queued replies and submits right before calc_object_states(). That covers both of its callers: handle_peers(), and continue_pg(), which calculates a re-peered PG at once (a re-peer keeps the lists of the peers that stay) from a completion callback, such as a lock reply or an etcd event, before the loop gets to osd_t::loop() at all. Passes without a calculation keep a single submit, so a busy OSD doesn't pay a second io_uring_enter per pass.

The test needed two hooks: the mock messenger's empty send_replies() calls an optional mock_send_replies_hook, and osd_test_fixture_t passes the mock ring's submit callback to an on_submit member.

Found: by a benchmark, not seen in a run. A single-threaded loop on the real ring_loop_t + epoll_manager_t answers pings while it runs 11 calculations of 600k-object EC 8+2 PGs (~0.8 s each) and serves a client that keeps 1024 ops in flight at 10 us of loop CPU each.

Tested:

  • test_peering_sends_replies_before_calc (osd_test): a send queued by the first send_replies() reaches the ring while the PG is still peering, for a calculation that repeer_pgs() starts through continue_pg(), and for one that handle_peers() starts when the yield timer fires. It fails on master.
  • osd_test and test_pg_chaos (100 seeds) pass.
  • The benchmark above (median of 3 runs, -O3 -g, i7-12700H):
load longest ping wait, master with this change 11 calculations, master / with this change
pings only 934 ms 936 ms 8951 / 8958 ms
client, 1024 ops in flight 1828 ms 943 ms 9034 / 9039 ms
client and 10 LIST requests of 600k entries 1891 ms 959 ms 9805 / 9824 ms

Contributor Name

Yury Luneff (MIND Software LLC, https://mindsw.io)

CLA

### Description Follow-up to #197. `osd_t::loop()` (src/osd/osd.cpp:612) runs `handle_peers()` first, then `read_requests()`, `send_replies()` and `submit()`. The completions of a pass are handled before the consumers run, so when the loop gets to `osd_t::loop()`, the replies to the requests that came during a calculation are already queued. If the 1 ms yield timer from #197 fired in the same pass, `handle_peers()` starts the next calculation first, and those replies go out only after it. Without other load, the time after a calculation is idle and a ping is answered within it. With client I/O or LIST requests from peers, the first pass after a calculation takes longer than the 1 ms timer, so a ping waits for two calculations instead of one. With 2.5-3 s calculations (~850k objects per PG) two calculations are more than the default osd_ping_timeout (5 s). The change: `continue_pg_peering()` sends the queued replies and submits right before `calc_object_states()`. That covers both of its callers: `handle_peers()`, and `continue_pg()`, which calculates a re-peered PG at once (a re-peer keeps the lists of the peers that stay) from a completion callback, such as a lock reply or an etcd event, before the loop gets to `osd_t::loop()` at all. Passes without a calculation keep a single submit, so a busy OSD doesn't pay a second `io_uring_enter` per pass. The test needed two hooks: the mock messenger's empty `send_replies()` calls an optional `mock_send_replies_hook`, and `osd_test_fixture_t` passes the mock ring's submit callback to an `on_submit` member. Found: by a benchmark, not seen in a run. A single-threaded loop on the real ring_loop_t + epoll_manager_t answers pings while it runs 11 calculations of 600k-object EC 8+2 PGs (~0.8 s each) and serves a client that keeps 1024 ops in flight at 10 us of loop CPU each. Tested: - test_peering_sends_replies_before_calc (osd_test): a send queued by the first send_replies() reaches the ring while the PG is still peering, for a calculation that `repeer_pgs()` starts through `continue_pg()`, and for one that `handle_peers()` starts when the yield timer fires. It fails on master. - osd_test and test_pg_chaos (100 seeds) pass. - The benchmark above (median of 3 runs, -O3 -g, i7-12700H): | load | longest ping wait, master | with this change | 11 calculations, master / with this change | |---|---:|---:|---:| | pings only | 934 ms | 936 ms | 8951 / 8958 ms | | client, 1024 ops in flight | 1828 ms | 943 ms | 9034 / 9039 ms | | client and 10 LIST requests of 600k entries | 1891 ms | 959 ms | 9805 / 9824 ms | ### Contributor Name Yury Luneff (MIND Software LLC, https://mindsw.io) ### CLA - [x] I accept Vitastor CLA agreement: https://git.yourcmc.ru/vitalif/vitastor/src/branch/master/CLA-en.md
koolkhel added 1 commit 2026-11-28 11:43:30 +03:00
osd_t::loop() ran handle_peers() before send_replies(). When the peering
yield timer fired in a pass that also handled incoming requests, their
replies were queued in that pass but sent only after the next PG
calculation, so under load a ping waited for two calculations instead
of one. Send the queued replies and submit before handle_peers().
koolkhel added 1 commit 2026-11-28 16:22:14 +03:00
The early send_replies() and submit() in osd_t::loop() cost a second
io_uring_enter in every busy pass that also queues new receives. Do
them only while OSD_PEERING_PGS is set: handle_peers() can start a calc
only then.
koolkhel added 1 commit 2026-11-28 18:20:05 +03:00
continue_pg() calculates a re-peered PG, which keeps the lists of the
peers that stay, from a completion callback (a lock reply, an etcd
event), so loop() reached its early flush only after the calc, and the
replies queued earlier in that pass waited for it. Send them in
continue_pg_peering() right before the calc instead: that covers both
paths and needs no peering_state check in loop().
vitalif merged commit 08e00c9300 into master 2026-11-29 14:13:14 +03:00
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: vitalif/vitastor#199
No description provided.