Skip to content

Commit

Permalink
Merge branch 'alin/MR-572-CallContextManager-stats' into 'master'
Browse files Browse the repository at this point in the history
feat: [MR-572] Add response slot and memory reservation stats to `CallContextManager`

The equivalent stats are maintained by `CanisterQueues` (where they're just
some counters that cannot be validated). In `CallContextManager` we can have
direct debug_asserts to validate them against the actual counts of callbacks or
unresponded call contexts (and compute them from scratch on state loading).

And in-between rounds (or, more precisely, at the end of the round) we can
directly compare the two sets of stats (e.g. as part of the invariant check
that the scheduler performs). Plus initialize the `CanisterQueues` stats from
the `CallContextManager` stats on checkpoint loading (instead of blindly
persisting them). 

See merge request dfinity-lab/public/ic!18976
  • Loading branch information
alin-at-dfinity committed Apr 30, 2024
2 parents 174d116 + 9020de8 commit cf5e566
Show file tree
Hide file tree
Showing 5 changed files with 435 additions and 8 deletions.
13 changes: 11 additions & 2 deletions rs/execution_environment/src/canister_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2533,9 +2533,18 @@ pub fn uninstall_canister(
// Cannot respond to system tasks. Nothing to do.
}
}
}

// Mark the call context as responded to.
call_context.mark_responded();
// Mark all call contexts as responded to.
let call_context_ids = call_context_manager
.call_contexts()
.keys()
.cloned()
.collect::<Vec<_>>();
for call_context_id in call_context_ids {
call_context_manager
.mark_responded(call_context_id)
.unwrap(); // Safe to do, we only just collected the IDs above.
}
}

Expand Down
12 changes: 12 additions & 0 deletions rs/replicated_state/src/canister_state/system_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1188,6 +1188,18 @@ impl SystemState {

/// Returns the memory currently in use by the `SystemState`
/// for canister messages.
///
/// TODO(MR-572): Change this to:
///
/// ++ N0: callbacks
/// -- N1: responses in input queues
/// -- 1: if first item in task queue is a paused / aborted `Response`
/// ++ N2: requests in input queues
/// ++ N3: non-responded call contexts
/// ++ 1: if first item in task queue is an aborted `Request`
///
/// + S1: size of responses in output queues
/// + S2: size of responses in input queues
pub fn message_memory_usage(&self) -> NumBytes {
(self.queues.memory_usage() as u64).into()
}
Expand Down
Loading

0 comments on commit cf5e566

Please sign in to comment.