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