wu-sheng commented on a change in pull request #7145:
URL: https://github.com/apache/skywalking/pull/7145#discussion_r656654389



##########
File path: 
oap-server/analyzer/meter-analyzer/src/main/java/org/apache/skywalking/oap/meter/analyzer/dsl/counter/CounterWindow.java
##########
@@ -47,15 +47,27 @@
     public Tuple2<Long, Double> increase(String name, ImmutableMap<String, 
String> labels, Double value, long windowSize, long now) {
         ID id = new ID(name, labels);
         if (!windows.containsKey(id)) {
-            windows.put(id, new LinkedList<>());
+            windows.put(id, new PriorityQueue<>());
         }
+
         Queue<Tuple2<Long, Double>> window = windows.get(id);
         window.offer(Tuple.of(now, value));
-        Tuple2<Long, Double> ps = window.element();
-        if ((now - ps._1) >= windowSize) {
-            window.remove();
+
+        long waterLevel = now - windowSize;
+        Tuple2<Long, Double> peek = window.peek();
+        if (peek._1 > waterLevel) {
+            return peek;
+        }
+        Tuple2<Long, Double> result = peek;
+        while (peek._1 <= waterLevel) {
+            result = window.poll();
+            peek = window.element();
         }

Review comment:
       This logic seems correct, have you tried `Collections.binarySearch()`? 
`window` is an ordered list, right? If so, a binary search would be much faster 
than a sequential search。




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to