|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | + * or more contributor license agreements. See the NOTICE file |
| 4 | + * distributed with this work for additional information |
| 5 | + * regarding copyright ownership. The ASF licenses this file |
| 6 | + * to you under the Apache License, Version 2.0 (the |
| 7 | + * "License"); you may not use this file except in compliance |
| 8 | + * with the License. You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, |
| 13 | + * software distributed under the License is distributed on an |
| 14 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | + * KIND, either express or implied. See the License for the |
| 16 | + * specific language governing permissions and limitations |
| 17 | + * under the License. |
| 18 | + */ |
| 19 | + |
| 20 | +package org.apache.polaris.benchmarks.simulations |
| 21 | + |
| 22 | +import io.gatling.core.Predef._ |
| 23 | +import io.gatling.core.structure.ScenarioBuilder |
| 24 | +import io.gatling.http.Predef.http |
| 25 | +import org.apache.polaris.benchmarks.actions.{ |
| 26 | + AuthenticationActions, |
| 27 | + NamespaceActions, |
| 28 | + TableActions, |
| 29 | + ViewActions |
| 30 | +} |
| 31 | +import org.apache.polaris.benchmarks.parameters.BenchmarkConfig.config |
| 32 | +import org.apache.polaris.benchmarks.parameters.{ |
| 33 | + ConnectionParameters, |
| 34 | + DatasetParameters, |
| 35 | + WorkloadParameters |
| 36 | +} |
| 37 | +import org.apache.polaris.benchmarks.util.CircularIterator |
| 38 | +import org.slf4j.LoggerFactory |
| 39 | + |
| 40 | +import java.util.concurrent.atomic.{AtomicBoolean, AtomicReference} |
| 41 | +import scala.concurrent.duration._ |
| 42 | + |
| 43 | +class CreateCommits extends Simulation { |
| 44 | + private val logger = LoggerFactory.getLogger(getClass) |
| 45 | + |
| 46 | + // -------------------------------------------------------------------------------- |
| 47 | + // Load parameters |
| 48 | + // -------------------------------------------------------------------------------- |
| 49 | + val cp: ConnectionParameters = config.connectionParameters |
| 50 | + val dp: DatasetParameters = config.datasetParameters |
| 51 | + val wp: WorkloadParameters = config.workloadParameters |
| 52 | + |
| 53 | + // -------------------------------------------------------------------------------- |
| 54 | + // Helper values |
| 55 | + // -------------------------------------------------------------------------------- |
| 56 | + private val accessToken: AtomicReference[String] = new AtomicReference() |
| 57 | + private val shouldRefreshToken: AtomicBoolean = new AtomicBoolean(true) |
| 58 | + |
| 59 | + private val authActions = AuthenticationActions(cp, accessToken) |
| 60 | + private val tableActions = TableActions(dp, wp, accessToken) |
| 61 | + private val viewActions = ViewActions(dp, wp, accessToken) |
| 62 | + |
| 63 | + // -------------------------------------------------------------------------------- |
| 64 | + // Authentication related workloads: |
| 65 | + // * Authenticate and store the access token for later use every minute |
| 66 | + // * Wait for an OAuth token to be available |
| 67 | + // * Stop the token refresh loop |
| 68 | + // -------------------------------------------------------------------------------- |
| 69 | + val continuouslyRefreshOauthToken: ScenarioBuilder = |
| 70 | + scenario("Authenticate every minute using the Iceberg REST API") |
| 71 | + .asLongAs(_ => shouldRefreshToken.get())( |
| 72 | + feed(authActions.feeder()) |
| 73 | + .exec(authActions.authenticateAndSaveAccessToken) |
| 74 | + .pause(1.minute) |
| 75 | + ) |
| 76 | + |
| 77 | + val waitForAuthentication: ScenarioBuilder = |
| 78 | + scenario("Wait for the authentication token to be available") |
| 79 | + .asLongAs(_ => accessToken.get() == null)( |
| 80 | + pause(1.second) |
| 81 | + ) |
| 82 | + |
| 83 | + val stopRefreshingToken: ScenarioBuilder = |
| 84 | + scenario("Stop refreshing the authentication token") |
| 85 | + .exec { session => |
| 86 | + shouldRefreshToken.set(false) |
| 87 | + session |
| 88 | + } |
| 89 | + |
| 90 | + // -------------------------------------------------------------------------------- |
| 91 | + // Read and write workloads: |
| 92 | + // * Create table commits by updating table properties |
| 93 | + // * Read namespaces, tables and views |
| 94 | + // -------------------------------------------------------------------------------- |
| 95 | + val tableUpdateScenario: ScenarioBuilder = |
| 96 | + scenario("Create table commits by updating properties") |
| 97 | + .exec(authActions.restoreAccessTokenInSession) |
| 98 | + .feed(tableActions.propertyUpdateFeeder()) |
| 99 | + .exec(tableActions.updateTable) |
| 100 | + |
| 101 | + // -------------------------------------------------------------------------------- |
| 102 | + // Read and write workloads: |
| 103 | + // * Create table commits by updating table properties |
| 104 | + // * Read namespaces, tables and views |
| 105 | + // -------------------------------------------------------------------------------- |
| 106 | + val viewUpdateScenario: ScenarioBuilder = |
| 107 | + scenario("Create view commits by updating properties") |
| 108 | + .exec(authActions.restoreAccessTokenInSession) |
| 109 | + .feed(viewActions.propertyUpdateFeeder()) |
| 110 | + .exec(viewActions.updateView) |
| 111 | + |
| 112 | + private val httpProtocol = http |
| 113 | + .baseUrl(cp.baseUrl) |
| 114 | + .acceptHeader("application/json") |
| 115 | + .contentTypeHeader("application/json") |
| 116 | + |
| 117 | + private val tableCommitsThroughput = wp.createCommits.tableCommitsThroughput |
| 118 | + private val viewCommitsThroughput = wp.createCommits.viewCommitsThroughput |
| 119 | + private val durationInMinutes = wp.createCommits.durationInMinutes |
| 120 | + setUp( |
| 121 | + continuouslyRefreshOauthToken.inject(atOnceUsers(1)).protocols(httpProtocol), |
| 122 | + waitForAuthentication |
| 123 | + .inject(atOnceUsers(1)) |
| 124 | + .andThen( |
| 125 | + tableUpdateScenario |
| 126 | + .inject( |
| 127 | + constantUsersPerSec(tableCommitsThroughput).during(durationInMinutes.minutes) |
| 128 | + ) |
| 129 | + .protocols(httpProtocol), |
| 130 | + viewUpdateScenario |
| 131 | + .inject( |
| 132 | + constantUsersPerSec(viewCommitsThroughput).during(durationInMinutes.minutes) |
| 133 | + ) |
| 134 | + .protocols(httpProtocol) |
| 135 | + ) |
| 136 | + .andThen(stopRefreshingToken.inject(atOnceUsers(1)).protocols(httpProtocol)) |
| 137 | + ) |
| 138 | +} |
0 commit comments