File tree 1 file changed +13
-1
lines changed
src/darwin/Framework/CHIP
1 file changed +13
-1
lines changed Original file line number Diff line number Diff line change @@ -308,6 +308,13 @@ - (BOOL)isEqual:(id)object
308
308
// happen more often than once every 10 minutes.
309
309
#define MTRDEVICE_MIN_RESUBSCRIBE_DUE_TO_READ_INTERVAL_SECONDS (10 * 60 )
310
310
311
+ // Weight of new data in determining subscription latencies. To avoid random
312
+ // outliers causing too much noise in the value, treat an existing value (if
313
+ // any) as having 2/3 weight and the new value as having 1/3 weight. These
314
+ // weights are subject to change, if it's determined that different ones give
315
+ // better behavior.
316
+ #define MTRDEVICE_SUBSCRIPTION_LATENCY_NEW_VALUE_WEIGHT (1.0 / 3.0 )
317
+
311
318
@interface MTRDevice ()
312
319
@property (nonatomic , readonly ) os_unfair_lock lock; // protects the caches and device state
313
320
// protects against concurrent time updates by guarding timeUpdateScheduled flag which manages time updates scheduling,
@@ -1014,7 +1021,12 @@ - (void)_handleSubscriptionEstablished
1014
1021
// We want time interval from initialSubscribeStart to now, not the other
1015
1022
// way around.
1016
1023
NSTimeInterval subscriptionLatency = -[initialSubscribeStart timeIntervalSinceNow ];
1017
- _estimatedSubscriptionLatency = @(subscriptionLatency);
1024
+ if (_estimatedSubscriptionLatency == nil ) {
1025
+ _estimatedSubscriptionLatency = @(subscriptionLatency);
1026
+ } else {
1027
+ NSTimeInterval newSubscriptionLatencyEstimate = MTRDEVICE_SUBSCRIPTION_LATENCY_NEW_VALUE_WEIGHT * subscriptionLatency + (1 - MTRDEVICE_SUBSCRIPTION_LATENCY_NEW_VALUE_WEIGHT) * _estimatedSubscriptionLatency.doubleValue ;
1028
+ _estimatedSubscriptionLatency = @(newSubscriptionLatencyEstimate);
1029
+ }
1018
1030
[self _storePersistedDeviceData ];
1019
1031
}
1020
1032
You can’t perform that action at this time.
0 commit comments