Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(cu): add grace window to chaining logic to allow for more performant chaining #1068

Merged
merged 1 commit into from
Nov 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion servers/cu/src/domain/lib/chainEvaluation.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,25 @@ export function chainEvaluationWith (env) {
pending: Promise.resolve()
}

const pendingForProcessBefore = findPendingForProcessBefore({ processId, timestamp: to })
/**
* There are cases where many messages, scheduled in close proximity are sent to a CU
* at one time. These requests can arrive jumbled to the CU resulting in later messages
* obtaining the lock first, spinning up eval streams.
*
* Then when earlier message (whose request
* just so happend to arrive at the CU milliseconds later) will detect no earlier pending eval stream
* to chain to, and start up it's own eval stream, thus achieving poor deduplication.
*
* To help mitigate this, we add 10 seconds to 'to', to give room for this jumble of messages.
* So this could potentially chain an earlier message eval to a later message eval, thus delaying it,
* but only by 10 seconds worth of messages, NOT actually 10 seconds. And in this case, the earlier
* message should then be in the cache, and so won't spin up another eval stream
*
* TODO: perhaps we could rearrange the pendingReadState key to place 'ordinate' in front of 'to'
* then adjust to comparing 'ordinate' first here -- thus making the buffer message based,
* and not time based. See ln.65 in readState.js
*/
const pendingForProcessBefore = findPendingForProcessBefore({ processId, timestamp: to ? to + 10000 : to })
/**
* No pending evaluation stream was found, so there is no reason to check the process
* memory cache for an entry and then to compare it to the pending evalaution stream,
Expand Down