mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2026-08-12 01:07:46 +00:00
perf(relay): run the stored REQ replay undispatched
SmallReqFloorBenchmark showed the per-REQ floor on small results is dominated by pipeline, not the store (raw query 0.125 ms vs 0.785 ms session REQ->EOSE in-process). Half of the dispatch slice was the scheduler hop between handleReq's launch and the query coroutine: starting the job with CoroutineStart.UNDISPATCHED runs the stored replay and EOSE inline on the receiving coroutine (the reader-pool acquire doesn't suspend when a connection is free), parking only at the live tail. Measured: dispatch+frames slice 0.397 -> 0.207 ms. Commands on a connection are processed sequentially, so nothing can target the subscription before the job lands in the registry at the first suspension point. Verified: quartz relay.server suite, SmallReqFloorBenchmark, geode full test suite. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RzkoN3SJHCZWRAiadXXG4w
This commit is contained in:
+10
-1
@@ -49,6 +49,7 @@ import com.vitorpamplona.quartz.utils.Log
|
||||
import com.vitorpamplona.quartz.utils.cache.LargeCache
|
||||
import kotlinx.coroutines.CancellationException
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.CoroutineStart
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.channels.ClosedSendChannelException
|
||||
import kotlinx.coroutines.launch
|
||||
@@ -291,8 +292,16 @@ class RelaySession(
|
||||
// Policy may rewrite filters to match the user's access level.
|
||||
val filters = (result as PolicyResult.Accepted).cmd.filters
|
||||
|
||||
// UNDISPATCHED: the stored replay runs inline on this coroutine —
|
||||
// the reader-pool acquire doesn't suspend when a connection is
|
||||
// free, so EVENT frames and EOSE go out without a scheduler hop
|
||||
// (SmallReqFloorBenchmark: the hop was most of the dispatch
|
||||
// slice on small REQs). The coroutine first parks at the live
|
||||
// tail (awaitCancellation), which is when launch returns and the
|
||||
// job lands in [subscriptions]; commands on this connection are
|
||||
// processed sequentially, so nothing can target the sub earlier.
|
||||
val job =
|
||||
scope.launch {
|
||||
scope.launch(start = CoroutineStart.UNDISPATCHED) {
|
||||
try {
|
||||
if (policy.filtersOutgoingEvents) {
|
||||
// Screened path: every event is materialized so the
|
||||
|
||||
Reference in New Issue
Block a user