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 2022/09/21 01:30:39 UTC

[GitHub] [pinot] jasperjiaguo commented on a diff in pull request #9311: Adaptive Server Selection

jasperjiaguo commented on code in PR #9311:
URL: https://github.com/apache/pinot/pull/9311#discussion_r975798700


##########
pinot-broker/src/main/java/org/apache/pinot/broker/routing/adaptiveserverselector/AdaptiveServerSelector.java:
##########
@@ -0,0 +1,55 @@
+/**
+ * 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.routing.adaptiveserverselector;
+
+import java.util.List;
+import org.apache.commons.lang3.tuple.Pair;
+
+
+/**
+ * The {@code AdaptiveServerSelector} intelligently selects the best available server for a segment during query
+ * processing. The decision is made based on stats recorded for each server during query processing.
+ */
+public interface AdaptiveServerSelector {
+
+  /**
+   * Picks the best server to route a query from the list of candidate servers.
+   *
+   * @param serverCandidates Candidate servers from which the best server should be chosen.
+   * @return server identifier
+   */
+  String select(List<String> serverCandidates);
+
+  /**
+   * Returns the ranking of servers ordered from best to worst.
+   *
+   * @return List of servers ranked from best to worst.
+   */
+  List<String> fetchServerRanking();

Review Comment:
   Should we rename it to `fetchFullServerRanking` for more clarity?



##########
pinot-broker/src/main/java/org/apache/pinot/broker/routing/adaptiveserverselector/HybridSelector.java:
##########
@@ -0,0 +1,99 @@
+/**
+ * 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.routing.adaptiveserverselector;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Random;
+import org.apache.commons.lang3.tuple.Pair;
+import org.apache.pinot.core.transport.server.routing.stats.ServerRoutingStatsManager;
+
+
+/**
+ * The {@code HybridSelector} is an AdaptiveServerSelector implementation that picks the best server based on the
+ * following parameters:
+ * 1. Num of in-flight requests (A)
+ * 2. EMA of in-flight requests (B)
+ * 3. EMA of latencies (C)
+ * This selector implementation is based on the ideas suggested in the paper -
+ * https://www.usenix.org/system/files/conference/nsdi15/nsdi15-paper-suresh.pdf
+ *
+ * The C3 server score for each server is calculated as follows. The server with the lowest C3 score is picked.
+ *       C3serverScore = Math.pow(A+B, N) * C
+ * N -> Configurable exponent with default value of 3.
+ */
+public class HybridSelector implements AdaptiveServerSelector {
+  private final ServerRoutingStatsManager _serverRoutingStatsManager;
+  private final Random _random;
+
+  public HybridSelector(ServerRoutingStatsManager serverRoutingStatsManager) {
+    _serverRoutingStatsManager = serverRoutingStatsManager;
+    _random = new Random();
+  }
+
+  @Override
+  public String select(List<String> serverCandidates) {
+    String selectedServer = null;
+    Double minValue = Double.MAX_VALUE;
+
+    // TODO: If two or more servers have the same score, break the tie intelligently.
+    for (String server : serverCandidates) {
+      Double score = _serverRoutingStatsManager.fetchC3ScoreForServer(server);
+
+      // No stats for this server. That means this server hasn't received any queries yet.
+      if (score == null) {
+        int randIdx = _random.nextInt(serverCandidates.size());

Review Comment:
   (nit) How about if we simply pick the server that has `score == null`? This gives more determinism and is less likely to create thundering herd problem, because the next call will also pick a null (if any). The current solution is fine for not too large `serverCandidates.size()`. The expectation of initializing all servers is `size*\sum_{j=1...size} 1/j` (see [this](https://math.stackexchange.com/questions/379525/probability-distribution-in-the-coupon-collectors-problem)). My only concern is that if the serverCandidates.size() could get large for balanced assignment, and we become unfortunate with random numbers.



-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org

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