cxzl25 commented on code in PR #5662:
URL: https://github.com/apache/kyuubi/pull/5662#discussion_r1582078092
##########
kyuubi-server/src/main/scala/org/apache/kyuubi/engine/EngineRef.scala:
##########
@@ -366,4 +374,48 @@ private[kyuubi] class EngineRef(
}
}
}
+
+ private def getAdaptivePoolId(poolSize: Int): Int = {
+ val sessionThreshold = conf.get(ENGINE_POOL_ADAPTIVE_SESSION_THRESHOLD)
+ val metricsSpace =
+
s"/metrics/${serverSpace}_${KYUUBI_VERSION}_${shareLevel}_$engineType/$sessionUser"
+ DiscoveryClientProvider.withDiscoveryClient(conf) { client =>
+ tryWithLock(client) {
+ if (client.pathNonExists(metricsSpace)) {
+ client.create(metricsSpace, "PERSISTENT")
+ }
+ }
+ val metrics = client.getChildren(metricsSpace)
+ if (metrics.isEmpty) {
+ return Random.nextInt(poolSize)
+ } else {
+ engineType match {
+ case SPARK_SQL =>
+ val engineMetricsMap = metrics.map { p =>
+ objectMapper.readValue(
+ new String(client.getData(s"$metricsSpace/$p")),
+ classOf[Map[String, Int]])
+ }
+ if (engineMetricsMap.isEmpty) {
+ return Random.nextInt(poolSize)
+ } else {
+ val candidate = engineMetricsMap.filter(_.contains("poolID"))
+ .minBy { map =>
+ (
+ map.getOrElse("openSessionCount", sessionThreshold),
Review Comment:
```suggestion
map.getOrElse("openSessionCount", 0),
```
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]