@@ -40,7 +40,7 @@ class PrefixCachingMetrics:
4040
4141 def __init__ (self , interval : int = 1000 ):
4242 self .interval = interval
43- # The current aggregated query total and hit .
43+ # The current aggregated values .
4444 self .aggregated_requests = 0
4545 self .aggregated_query_total = 0
4646 self .aggregated_query_hit = 0
@@ -56,20 +56,21 @@ def observe(self, stats: PrefixCacheStats):
5656 When there are more than `interval` requests, the oldest set of
5757 requestsare removed from the metrics.
5858
59- Stats:
60- reset: Whether reset_prefix_cache was invoked.
61- requests: The number of requests in this update.
62- queries: The number of queries in these requests.
63- hits: The number of hits in these requests.
59+ Args:
60+ stats: The prefix cache stats.
6461 """
62+ # reset_prefix_cache was invoked before the current update.
63+ # Reset the metrics before aggregating the current stats.
6564 if stats .reset :
6665 self .reset ()
6766
67+ # Update the metrics.
6868 self .query_queue .append ((stats .requests , stats .queries , stats .hits ))
6969 self .aggregated_requests += stats .requests
7070 self .aggregated_query_total += stats .queries
7171 self .aggregated_query_hit += stats .hits
7272
73+ # Remove the oldest stats if the number of requests exceeds.
7374 if self .aggregated_requests > self .interval :
7475 old_requests , old_queries , old_hits = self .query_queue .popleft ()
7576 self .aggregated_requests -= old_requests
0 commit comments