pvary commented on a change in pull request #660: HIVE-21823: New metrics to
get the average queue length / free executor number for a given time window
URL: https://github.com/apache/hive/pull/660#discussion_r291505729
##########
File path:
llap-server/src/java/org/apache/hadoop/hive/llap/metrics/LlapDaemonExecutorMetrics.java
##########
@@ -397,4 +425,106 @@ public JvmMetrics getJvmMetrics() {
public String getName() {
return name;
}
+
+ /**
+ * Generate time aware average for data points.
+ * For example if we have 3s when the queue size is 1, and 1s when the queue
size is 2 then the
+ * calculated average should be (3*1+1*2)/4 = 1.25.
+ */
+ @VisibleForTesting
+ static class TimedAverageMetrics {
+ private final int windowDataSize;
+ private final long windowTimeSize;
+ private final Data[] data;
+ private int nextPos = 0;
+
+ /**
+ * Creates and initializes the metrics object.
+ * @param windowDataSize The maximum number of samples stored
+ * @param windowTimeSize The time window used to generate the average in
nanoseconds
+ */
+ TimedAverageMetrics(int windowDataSize, long windowTimeSize) {
+ this(windowDataSize, windowTimeSize, System.nanoTime());
+ }
+
+ @VisibleForTesting
+ TimedAverageMetrics(int windowDataSize, long windowTimeSize,
+ long defaultTime) {
+ assert(windowDataSize > 0);
+ this.windowDataSize = windowDataSize;
+ this.windowTimeSize = windowTimeSize;
+ this.data = new Data[windowDataSize];
+ Arrays.setAll(data, i -> new Data(defaultTime, 0L));
+ }
+
+ /**
+ * Adds a new sample value to the metrics.
+ * @param value The new sample value
+ */
+ public synchronized void add(long value) {
+ add(System.nanoTime(), value);
+ }
+
+ /**
+ * Calculates the average for the last windowTimeSize window.
+ * @return The average
+ */
+ public synchronized long value() {
+ return value(System.nanoTime());
+ }
+
+ @VisibleForTesting
+ void add(long time, long value) {
+ data[nextPos].nanoTime = time;
+ data[nextPos].value = value;
+ nextPos++;
Review comment:
As discussed offline run some tests:
Test case:
- 1m with a for loop iterations averaged out
- Adding 20k items
- Querying a value which uses 15k items
Results:
- With sync:
- Full: 0.155/0.152/0.152 ms - both adding and querying
- Add: 0.134/0.133/0.133
- Query: 0.016/0.016/0.017
- Without sync:
- Full: 0.113/0.108/0.108
- Add: 0.099/0.091/0.091
- Query: 0.017/0.016/0.016
So this means that synchronization adds an extra 2 nanosecond to a 4.7
nanosecond to the add new data point task. I think even though this is relative
high overhead, but this is small in absolute numbers. So I think we should not
complicate this part of the code more
----------------------------------------------------------------
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]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]