You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pinot.apache.org by GitBox <gi...@apache.org> on 2020/08/27 18:05:18 UTC

[GitHub] [incubator-pinot] mcvsubbu commented on a change in pull request #5922: Add max qps bucket count

mcvsubbu commented on a change in pull request #5922:
URL: https://github.com/apache/incubator-pinot/pull/5922#discussion_r478597673



##########
File path: pinot-broker/src/main/java/org/apache/pinot/broker/queryquota/StatefulHitCounter.java
##########
@@ -0,0 +1,73 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pinot.broker.queryquota;
+
+import com.google.common.annotations.VisibleForTesting;
+
+/**
+ * A stateful version of hit counter. Similar to the default hit counter, it maintains a list of buckets.
+ * Whereas it maintains an extra variable called _lastAccessTimestamp which tracks the last access time.
+ * If the stateful hit counter gets queried, it firstly compares the current timestamp and the last access timestamp,
+ * calculating the start index and end index among the buckets. Then, it traverses through all the valid candidate buckets.
+ * If the current timestamp has exceeded the current time range of all the buckets, this hit counter will use
+ * the current timestamp minus the default time queried time range to calculate the start time index.
+ */
+public class StatefulHitCounter extends HitCounter {
+  private long _maxTimeRangeMs;
+  private long _defaultQueriedTimeRangeMs;
+  private long _lastAccessTimestamp;

Review comment:
       should be volatile

##########
File path: pinot-broker/src/main/java/org/apache/pinot/broker/queryquota/StatefulHitCounter.java
##########
@@ -0,0 +1,73 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pinot.broker.queryquota;
+
+import com.google.common.annotations.VisibleForTesting;
+
+/**
+ * A stateful version of hit counter. Similar to the default hit counter, it maintains a list of buckets.
+ * Whereas it maintains an extra variable called _lastAccessTimestamp which tracks the last access time.
+ * If the stateful hit counter gets queried, it firstly compares the current timestamp and the last access timestamp,
+ * calculating the start index and end index among the buckets. Then, it traverses through all the valid candidate buckets.
+ * If the current timestamp has exceeded the current time range of all the buckets, this hit counter will use
+ * the current timestamp minus the default time queried time range to calculate the start time index.
+ */
+public class StatefulHitCounter extends HitCounter {
+  private long _maxTimeRangeMs;

Review comment:
       final

##########
File path: pinot-broker/src/main/java/org/apache/pinot/broker/queryquota/QueryQuotaEntity.java
##########
@@ -24,15 +24,17 @@
 public class QueryQuotaEntity {
 
   private RateLimiter _rateLimiter;
-  private HitCounter _hitCounter;
+  private HitCounter _hitCounterInSecond;

Review comment:
       ```suggestion
     private HitCounter _qpsTracker;
   ```

##########
File path: pinot-broker/src/main/java/org/apache/pinot/broker/queryquota/StatefulHitCounter.java
##########
@@ -0,0 +1,73 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pinot.broker.queryquota;
+
+import com.google.common.annotations.VisibleForTesting;
+
+/**
+ * A stateful version of hit counter. Similar to the default hit counter, it maintains a list of buckets.
+ * Whereas it maintains an extra variable called _lastAccessTimestamp which tracks the last access time.
+ * If the stateful hit counter gets queried, it firstly compares the current timestamp and the last access timestamp,
+ * calculating the start index and end index among the buckets. Then, it traverses through all the valid candidate buckets.
+ * If the current timestamp has exceeded the current time range of all the buckets, this hit counter will use
+ * the current timestamp minus the default time queried time range to calculate the start time index.
+ */
+public class StatefulHitCounter extends HitCounter {
+  private long _maxTimeRangeMs;
+  private long _defaultQueriedTimeRangeMs;
+  private long _lastAccessTimestamp;
+
+  public StatefulHitCounter(int timeRangeInSeconds, int bucketCount, int defaultQueriedTimeRangeInSeconds) {

Review comment:
       ```suggestion
     public StatefulHitCounter(int queriedTimeRangeInSeconds) {
   ```
   Derive the other two locally. So, the timeRange we maintain could be `2*queriedTimeRangeInSeconds` or even `1.5` times . the bucket count is also something that could be decided by the statefulHitCounter.

##########
File path: pinot-broker/src/main/java/org/apache/pinot/broker/queryquota/StatefulHitCounter.java
##########
@@ -0,0 +1,73 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pinot.broker.queryquota;
+
+import com.google.common.annotations.VisibleForTesting;
+
+/**
+ * A stateful version of hit counter. Similar to the default hit counter, it maintains a list of buckets.
+ * Whereas it maintains an extra variable called _lastAccessTimestamp which tracks the last access time.
+ * If the stateful hit counter gets queried, it firstly compares the current timestamp and the last access timestamp,
+ * calculating the start index and end index among the buckets. Then, it traverses through all the valid candidate buckets.
+ * If the current timestamp has exceeded the current time range of all the buckets, this hit counter will use
+ * the current timestamp minus the default time queried time range to calculate the start time index.
+ */
+public class StatefulHitCounter extends HitCounter {
+  private long _maxTimeRangeMs;
+  private long _defaultQueriedTimeRangeMs;
+  private long _lastAccessTimestamp;
+
+  public StatefulHitCounter(int timeRangeInSeconds, int bucketCount, int defaultQueriedTimeRangeInSeconds) {

Review comment:
       Is `StatefulHitCounter` the right name? Should we call it maxHitRteTracker, since that is more specific?

##########
File path: pinot-common/src/main/java/org/apache/pinot/common/metrics/BrokerGauge.java
##########
@@ -27,6 +27,7 @@
  */
 public enum BrokerGauge implements AbstractMetrics.Gauge {
   QUERY_QUOTA_CAPACITY_UTILIZATION_RATE("tables", false),
+  MAX_QPS_IN_ONE_MINUTE("tables", false),

Review comment:
       `MAX_QPS_SINCE_LAST_CALL` or better, `MAX_BURST_QPS`?

##########
File path: pinot-broker/src/main/java/org/apache/pinot/broker/queryquota/StatefulHitCounter.java
##########
@@ -0,0 +1,73 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pinot.broker.queryquota;
+
+import com.google.common.annotations.VisibleForTesting;
+
+/**
+ * A stateful version of hit counter. Similar to the default hit counter, it maintains a list of buckets.
+ * Whereas it maintains an extra variable called _lastAccessTimestamp which tracks the last access time.
+ * If the stateful hit counter gets queried, it firstly compares the current timestamp and the last access timestamp,
+ * calculating the start index and end index among the buckets. Then, it traverses through all the valid candidate buckets.
+ * If the current timestamp has exceeded the current time range of all the buckets, this hit counter will use
+ * the current timestamp minus the default time queried time range to calculate the start time index.
+ */
+public class StatefulHitCounter extends HitCounter {
+  private long _maxTimeRangeMs;
+  private long _defaultQueriedTimeRangeMs;
+  private long _lastAccessTimestamp;
+
+  public StatefulHitCounter(int timeRangeInSeconds, int bucketCount, int defaultQueriedTimeRangeInSeconds) {
+    super(timeRangeInSeconds, bucketCount);
+    _maxTimeRangeMs = timeRangeInSeconds * 1000L;
+    _defaultQueriedTimeRangeMs = defaultQueriedTimeRangeInSeconds * 1000L;
+  }
+
+  /**
+   * Get the maximum count among the buckets
+   */
+  public int getMaxCountPerBucket() {
+    return getMaxCountPerBucket(System.currentTimeMillis());
+  }
+
+  @VisibleForTesting
+  int getMaxCountPerBucket(long timestamp) {

Review comment:
       ```suggestion
     int getMaxCountPerBucket(long now) {
   ```
   More intuitive name I think

##########
File path: pinot-broker/src/main/java/org/apache/pinot/broker/queryquota/StatefulHitCounter.java
##########
@@ -0,0 +1,73 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pinot.broker.queryquota;
+
+import com.google.common.annotations.VisibleForTesting;
+
+/**
+ * A stateful version of hit counter. Similar to the default hit counter, it maintains a list of buckets.
+ * Whereas it maintains an extra variable called _lastAccessTimestamp which tracks the last access time.
+ * If the stateful hit counter gets queried, it firstly compares the current timestamp and the last access timestamp,
+ * calculating the start index and end index among the buckets. Then, it traverses through all the valid candidate buckets.
+ * If the current timestamp has exceeded the current time range of all the buckets, this hit counter will use
+ * the current timestamp minus the default time queried time range to calculate the start time index.
+ */
+public class StatefulHitCounter extends HitCounter {
+  private long _maxTimeRangeMs;
+  private long _defaultQueriedTimeRangeMs;
+  private long _lastAccessTimestamp;
+
+  public StatefulHitCounter(int timeRangeInSeconds, int bucketCount, int defaultQueriedTimeRangeInSeconds) {
+    super(timeRangeInSeconds, bucketCount);
+    _maxTimeRangeMs = timeRangeInSeconds * 1000L;
+    _defaultQueriedTimeRangeMs = defaultQueriedTimeRangeInSeconds * 1000L;
+  }
+
+  /**
+   * Get the maximum count among the buckets
+   */
+  public int getMaxCountPerBucket() {
+    return getMaxCountPerBucket(System.currentTimeMillis());
+  }
+
+  @VisibleForTesting
+  int getMaxCountPerBucket(long timestamp) {
+    // If the hit counter didn't get queried for more than _maxTimeRangeMs
+    if (timestamp - _lastAccessTimestamp > _maxTimeRangeMs) {
+      _lastAccessTimestamp = timestamp - _defaultQueriedTimeRangeMs;
+    }
+    long startTimeUnits = _lastAccessTimestamp / _timeBucketWidthMs;
+    int startIndex = (int) (startTimeUnits % _bucketCount);
+
+    long numTimeUnits = timestamp / _timeBucketWidthMs;
+    int endIndex = (int) (numTimeUnits % _bucketCount);
+
+    int maxCount = 0;
+    // Since the start index was accessed last time, there is no need to query its bucket this time.

Review comment:
       ```suggestion
       // Since the end index was accessed last time, there is no need to query its bucket this time.
   ```
   We are skipping the endIndex in the loop below, right?

##########
File path: pinot-broker/src/main/java/org/apache/pinot/broker/queryquota/QueryQuotaEntity.java
##########
@@ -24,15 +24,17 @@
 public class QueryQuotaEntity {
 
   private RateLimiter _rateLimiter;
-  private HitCounter _hitCounter;
+  private HitCounter _hitCounterInSecond;
+  private StatefulHitCounter _hitCounterInMinute;

Review comment:
       ```suggestion
     private StatefulHitCounter _maxQpsTracker;
   ```

##########
File path: pinot-broker/src/main/java/org/apache/pinot/broker/queryquota/StatefulHitCounter.java
##########
@@ -0,0 +1,73 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pinot.broker.queryquota;
+
+import com.google.common.annotations.VisibleForTesting;
+
+/**
+ * A stateful version of hit counter. Similar to the default hit counter, it maintains a list of buckets.
+ * Whereas it maintains an extra variable called _lastAccessTimestamp which tracks the last access time.
+ * If the stateful hit counter gets queried, it firstly compares the current timestamp and the last access timestamp,
+ * calculating the start index and end index among the buckets. Then, it traverses through all the valid candidate buckets.
+ * If the current timestamp has exceeded the current time range of all the buckets, this hit counter will use
+ * the current timestamp minus the default time queried time range to calculate the start time index.
+ */
+public class StatefulHitCounter extends HitCounter {
+  private long _maxTimeRangeMs;
+  private long _defaultQueriedTimeRangeMs;

Review comment:
       final




----------------------------------------------------------------
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:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org