@@ -3,6 +3,7 @@ use ic_error_types::{ErrorCode, RejectCode};
3
3
use ic_interfaces:: execution_environment:: {
4
4
IngressHistoryError , IngressHistoryReader , IngressHistoryWriter ,
5
5
} ;
6
+ use ic_interfaces:: time_source:: system_time_now;
6
7
use ic_interfaces_state_manager:: { StateManagerError , StateReader } ;
7
8
use ic_logger:: { fatal, ReplicaLogger } ;
8
9
use ic_metrics:: { buckets:: decimal_buckets, MetricsRegistry } ;
@@ -82,6 +83,9 @@ pub struct IngressHistoryWriterImpl {
82
83
// Wrapped in a RwLock for interior mutability, otherwise &self in methods
83
84
// has to be &mut self.
84
85
received_time : RwLock < HashMap < MessageId , TransitionStartTime > > ,
86
+ message_state_transition_received_duration_seconds : Histogram ,
87
+ message_state_transition_processing_duration_seconds : Histogram ,
88
+ message_state_transition_received_to_processing_duration_seconds : Histogram ,
85
89
message_state_transition_completed_ic_duration_seconds : Histogram ,
86
90
message_state_transition_completed_wall_clock_duration_seconds : Histogram ,
87
91
message_state_transition_failed_ic_duration_seconds : HistogramVec ,
@@ -102,6 +106,24 @@ impl IngressHistoryWriterImpl {
102
106
config,
103
107
log,
104
108
received_time : RwLock :: new ( HashMap :: new ( ) ) ,
109
+ message_state_transition_received_duration_seconds : metrics_registry. histogram (
110
+ "message_state_transition_received_duration_seconds" ,
111
+ "Time taken by messages to get from block maker into ingress queue" ,
112
+ // 10ms, 20ms, 50ms, ..., 100s, 200s, 500s
113
+ decimal_buckets ( -2 , 2 ) ,
114
+ ) ,
115
+ message_state_transition_processing_duration_seconds : metrics_registry. histogram (
116
+ "message_state_transition_processing_duration_seconds" ,
117
+ "Time taken by messages to get from block maker to execution" ,
118
+ // 10ms, 20ms, 50ms, ..., 100s, 200s, 500s
119
+ decimal_buckets ( -2 , 2 ) ,
120
+ ) ,
121
+ message_state_transition_received_to_processing_duration_seconds : metrics_registry. histogram (
122
+ "message_state_transition_received_to_processing_duration_seconds" ,
123
+ "Time spent by messages between induction and execution" ,
124
+ // 10ms, 20ms, 50ms, ..., 100s, 200s, 500s
125
+ decimal_buckets ( -2 , 2 ) ,
126
+ ) ,
105
127
message_state_transition_completed_ic_duration_seconds : metrics_registry. histogram (
106
128
"message_state_transition_completed_ic_duration_seconds" ,
107
129
"The IC time taken for a message to transition from the Received state to Completed state" ,
@@ -164,8 +186,60 @@ impl IngressHistoryWriter for IngressHistoryWriterImpl {
164
186
status
165
187
) ;
166
188
}
189
+
167
190
use IngressState :: * ;
168
191
use IngressStatus :: * ;
192
+
193
+ // Computes the duration elapsed since the time when a message was included into
194
+ // a block (approximated by block time); and since its induction.
195
+ let message_latencies_seconds = |message_id| {
196
+ let received_time = self . received_time . read ( ) . unwrap ( ) ;
197
+ received_time. get ( message_id) . map ( |timer| {
198
+ (
199
+ system_time_now ( )
200
+ . saturating_duration_since ( timer. ic_time )
201
+ . as_secs_f64 ( ) ,
202
+ Instant :: now ( )
203
+ . saturating_duration_since ( timer. system_time )
204
+ . as_secs_f64 ( ) ,
205
+ )
206
+ } )
207
+ } ;
208
+ // Latency instrumentation.
209
+ match ( & current_status, & status) {
210
+ // Newly received message: observe its induction latency.
211
+ (
212
+ Unknown ,
213
+ Known {
214
+ state : Received , ..
215
+ } ,
216
+ ) => {
217
+ if let Some ( ( seconds_since_block_made, _) ) = message_latencies_seconds ( & message_id)
218
+ {
219
+ self . message_state_transition_received_duration_seconds
220
+ . observe ( seconds_since_block_made) ;
221
+ }
222
+ }
223
+
224
+ // Message popped from ingress queue: observe its processing latency.
225
+ (
226
+ Known {
227
+ state : Received , ..
228
+ } ,
229
+ Known { state, .. } ,
230
+ ) if state != & Received => {
231
+ if let Some ( ( seconds_since_block_made, seconds_since_induction) ) =
232
+ message_latencies_seconds ( & message_id)
233
+ {
234
+ self . message_state_transition_processing_duration_seconds
235
+ . observe ( seconds_since_block_made) ;
236
+ self . message_state_transition_received_to_processing_duration_seconds
237
+ . observe ( seconds_since_induction) ;
238
+ }
239
+ }
240
+ _ => { }
241
+ }
242
+
169
243
match & status {
170
244
Known {
171
245
state : Received , ..
0 commit comments