forked from digital-asset/daml
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
AsyncQueryConstantAcs scenario (digital-asset#7054)
changelog_begin changelog_end
- Loading branch information
Showing
5 changed files
with
143 additions
and
36 deletions.
There are no files selected for viewing
60 changes: 60 additions & 0 deletions
60
...ice/http-json-perf/src/main/scala/com/daml/http/perf/scenario/AsyncQueryConstantAcs.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// Copyright (c) 2020 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package com.daml.http.perf.scenario | ||
|
||
import io.gatling.core.Predef._ | ||
import io.gatling.http.Predef._ | ||
import io.gatling.http.check.ws.WsTextFrameCheck | ||
|
||
import scala.concurrent.duration._ | ||
|
||
@SuppressWarnings(Array("org.wartremover.warts.NonUnitStatements")) | ||
class AsyncQueryConstantAcs | ||
extends Simulation | ||
with SimulationConfig | ||
with HasRandomAmount | ||
with HasCreateRequest { | ||
|
||
private val wantedAcsSize = 5000 | ||
|
||
private val waitForResponse: FiniteDuration = 5.seconds | ||
|
||
private val numberOfRuns = 100 | ||
|
||
private val queryRequest = | ||
"""{"templateIds": ["Iou:Iou"], "query": {"amount": {"%gt": 1.0}}}""" | ||
|
||
val messageCheck: WsTextFrameCheck = ws | ||
.checkTextMessage("messageCheck") | ||
.check(jsonPath("$.offset").find.notExists) | ||
.check(jsonPath("$.events[*].created").findAll) | ||
|
||
private def query(runId: Int) = { | ||
val wsName = s"websocket$runId" | ||
ws("Connect websocket", wsName) | ||
.connect("/v1/stream/query") | ||
.subprotocol(s"jwt.token.$aliceJwt, daml.ws.auth") | ||
.onConnected( | ||
exec( | ||
ws(s"Send Query Request and wait for response: $waitForResponse", wsName) | ||
.sendText(queryRequest) | ||
.await(waitForResponse)(Vector.fill(5)(messageCheck): _*) | ||
) | ||
) | ||
} | ||
|
||
private val asyncQueryScenario = scenario(s"AsyncQueryConstantAcs, numberOfRuns: $numberOfRuns") | ||
.doWhile(_ => acsQueue.size() < wantedAcsSize) { | ||
pause(1.second) | ||
} | ||
.exec( | ||
1.to(numberOfRuns).map(runId => exec(query(runId))) | ||
) | ||
|
||
setUp( | ||
fillAcsScenario(wantedAcsSize).inject(atOnceUsers(1)), | ||
asyncQueryScenario.inject(atOnceUsers(1)), | ||
).protocols(httpProtocol) | ||
|
||
} |
28 changes: 28 additions & 0 deletions
28
ledger-service/http-json-perf/src/main/scala/com/daml/http/perf/scenario/Checks.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Copyright (c) 2020 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package com.daml.http.perf.scenario | ||
|
||
import io.gatling.commons.validation | ||
import io.gatling.core.Predef._ | ||
import io.gatling.core.check.{Check, CheckResult} | ||
|
||
object Checks { | ||
|
||
def printResponseCheck[R]: Check[R] = new PrintResponseCheck[R] | ||
|
||
/** | ||
* Useful for debugging. | ||
* | ||
* @tparam R response type | ||
*/ | ||
private class PrintResponseCheck[R] extends Check[R] { | ||
override def check( | ||
response: R, | ||
session: Session, | ||
preparedCache: java.util.Map[Any, Any]): validation.Validation[CheckResult] = { | ||
println(s"Response: $response") | ||
validation.Success(CheckResult(None, None)) | ||
} | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
...-service/http-json-perf/src/main/scala/com/daml/http/perf/scenario/HasCreateRequest.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Copyright (c) 2020 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package com.daml.http.perf.scenario | ||
|
||
import java.util.concurrent.{BlockingQueue, LinkedBlockingQueue} | ||
|
||
import io.gatling.core.Predef._ | ||
import io.gatling.core.structure.ScenarioBuilder | ||
import io.gatling.http.Predef._ | ||
import io.gatling.http.request.builder.HttpRequestBuilder | ||
|
||
private[scenario] trait HasCreateRequest { | ||
this: HasRandomAmount => | ||
|
||
lazy val acsQueue: BlockingQueue[String] = new LinkedBlockingQueue[String]() | ||
|
||
lazy val createRequestAndCollectContractId: HttpRequestBuilder = | ||
http("CreateCommand") | ||
.post("/v1/create") | ||
.body(StringBody("""{ | ||
"templateId": "Iou:Iou", | ||
"payload": { | ||
"issuer": "Alice", | ||
"owner": "Alice", | ||
"currency": "USD", | ||
"amount": "${amount}", | ||
"observers": [] | ||
} | ||
}""")) | ||
.check( | ||
status.is(200), | ||
jsonPath("$.result.contractId").transform(x => acsQueue.put(x)) | ||
) | ||
|
||
def fillAcsScenario(size: Int): ScenarioBuilder = | ||
scenario(s"FillAcsScenario, size: $size") | ||
.doWhile(_ => acsQueue.size() < size) { | ||
feed(Iterator.continually(Map("amount" -> randomAmount()))) | ||
.exec(createRequestAndCollectContractId.silent) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters