dimas-b commented on code in PR #2:
URL: https://github.com/apache/polaris-tools/pull/2#discussion_r2023483895


##########
benchmarks/build.gradle.kts:
##########
@@ -0,0 +1,29 @@
+plugins {
+    scala
+    id("io.gatling.gradle") version "3.13.5.2"
+    id("com.diffplug.spotless") version "7.0.2"
+}
+
+description = "Polaris Iceberg REST API performance tests"
+
+tasks.withType<ScalaCompile> {
+    scalaCompileOptions.forkOptions.apply {
+        jvmArgs = listOf("-Xss100m") // Scala compiler may require a larger 
stack size when compiling Gatling simulations
+    }
+}
+
+dependencies {
+    gatling("com.typesafe.play:play-json_2.13:2.9.4")

Review Comment:
   nit: do we want to use `toml` files like the main Polaris repo?



##########
benchmarks/src/gatling/scala/org/apache/polaris/benchmarks/NAryTreeBuilder.scala:
##########
@@ -0,0 +1,105 @@
+/*
+ * 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.polaris.benchmarks
+
+/**
+ * Builds a complete N-ary tree structure for organizing namespaces in 
synthetic datasets.
+ *
+ * This builder is used to create a hierarchical namespace structure where 
each non-leaf namespace
+ * has exactly `nsWidth` child namespaces. The tree structure is used to 
organize tables and views
+ * in a deterministic way. Tables and views are placed in the leaf namespaces 
of the tree.
+ *
+ * @param nsWidth The number of children each non-leaf namespace will have (N)
+ * @param nsDepth The total depth of the tree, including the root namespace
+ */
+case class NAryTreeBuilder(nsWidth: Int, nsDepth: Int) {
+
+  /**
+   * Computes the path from the root node to the given ordinal.
+   *
+   * @param ordinal the ordinal of the node
+   * @param acc the accumulator for the path
+   * @return the path from the root node (included) to the given ordinal 
(included)
+   */
+  @scala.annotation.tailrec
+  final def pathToRoot(ordinal: Int, acc: List[Int] = Nil): List[Int] =
+    if (ordinal == 0) {
+      ordinal :: acc
+    } else {
+      val parent = (ordinal - 1) / nsWidth
+      pathToRoot(parent, ordinal :: acc)
+    }
+
+  /**
+   * Calculates the depth of a node in the n-ary tree based on its ordinal.
+   *
+   * @param ordinal The ordinal of the node.
+   * @return The depth of the node in the tree.
+   */
+  def depthOf(ordinal: Int): Int = {
+    if (ordinal == 0) return 0
+    if (nsWidth == 1) return ordinal
+
+    // Using the formula: floor(log_n((x * (n-1)) + 1))
+    val numerator = (ordinal * (nsWidth - 1)) + 1
+    (math.log(numerator) / math.log(nsWidth)).floor.toInt
+  }
+
+  /**
+   * Calculate the total number of nodes in a complete n-ary tree.
+   *
+   * @return The total number of nodes in the tree.
+   */
+  val numberOfNodes: Int = {
+    print(s"Computing number of nodes for n-ary tree with width $nsWidth and 
depth $nsDepth...")

Review Comment:
   Why `print` here?



##########
benchmarks/src/gatling/scala/org/apache/polaris/benchmarks/actions/AuthenticationActions.scala:
##########
@@ -0,0 +1,100 @@
+/*
+ * 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.polaris.benchmarks.actions
+
+import io.gatling.core.Predef._
+import io.gatling.core.feeder.Feeder
+import io.gatling.core.structure.ChainBuilder
+import io.gatling.http.Predef._
+import org.apache.polaris.benchmarks.RetryOnHttpCodes.{
+  retryOnHttpStatus,
+  HttpRequestBuilderWithStatusSave
+}
+import org.apache.polaris.benchmarks.parameters.ConnectionParameters
+import org.slf4j.LoggerFactory
+
+import java.util.concurrent.atomic.AtomicReference
+
+/**
+ * Actions for performance testing authentication operations. This class 
provides methods to
+ * authenticate and manage access tokens for API requests.
+ *
+ * @param cp Connection parameters containing client credentials
+ * @param accessToken Reference to the authentication token shared across 
actions
+ * @param maxRetries Maximum number of retry attempts for failed operations
+ * @param retryableHttpCodes HTTP status codes that should trigger a retry
+ */
+case class AuthenticationActions(

Review Comment:
   At some point Polaris will support external IdP (AFAIK), so auto-refresh 
hooks may not cover all cases.



##########
benchmarks/src/gatling/scala/org/apache/polaris/benchmarks/util/CircularIterator.scala:
##########
@@ -0,0 +1,52 @@
+/*
+ * 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.polaris.benchmarks.util
+
+import scala.util.Random
+
+class CircularIterator[T](builder: () => Iterator[T]) extends Iterator[T] {
+  private var currentIterator: Iterator[T] = builder()
+
+  override def hasNext: Boolean = true
+
+  override def next(): T = synchronized {
+    if (!currentIterator.hasNext) {
+      currentIterator = builder()
+    }
+    currentIterator.next()
+  }
+}
+
+class BufferedRandomIterator[T](underlying: CircularIterator[T], bufferSize: 
Int)
+    extends Iterator[T] {
+  private var buffer: Iterator[T] = populateAndShuffle()
+
+  private def populateAndShuffle(): Iterator[T] =
+    Random.shuffle((1 to bufferSize).map(_ => 
underlying.next()).toList).iterator

Review Comment:
   +1 to supporting seeds, but we ca probably add that later.



##########
benchmarks/src/gatling/resources/gatling.conf:
##########
@@ -0,0 +1,10 @@
+gatling {
+  charting {
+    indicators {
+      percentile1 = 25
+      percentile2 = 50
+      percentile3 = 75

Review Comment:
   IQR :tada: ;)



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

Reply via email to