-
Notifications
You must be signed in to change notification settings - Fork 205
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a benchmark for contract insertion in the JSON API
Unfortunately the results seem to match up with my initial benchmark in #10234 Benchmark (batchSize) (batches) (numContracts) Mode Cnt Score Error Units InsertBenchmark.run 1000 1 1000 avgt 5 336.674 ± 42.058 ms/op InsertBenchmark.run 1000 3 1000 avgt 5 787.086 ± 223.018 ms/op InsertBenchmark.run 1000 5 1000 avgt 5 1181.041 ± 317.017 ms/op InsertBenchmark.run 1000 7 1000 avgt 5 1531.185 ± 341.060 ms/op InsertBenchmark.run 1000 9 1000 avgt 5 1945.345 ± 436.352 ms/op Score should ideally be more or less constant but it goes up very significantly as the total ACS size changes fixes #10245 changelog_begin changelog_end
- Loading branch information
1 parent
f6da4c0
commit 153dcb7
Showing
2 changed files
with
55 additions
and
1 deletion.
There are no files selected for viewing
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
54 changes: 54 additions & 0 deletions
54
ledger-service/http-json/src/bench/scala/com/daml/http/dbbackend/InsertBenchmark.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,54 @@ | ||
// Copyright (c) 2021 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package com.daml.http.dbbackend | ||
|
||
import cats.instances.list._ | ||
import com.daml.http.dbbackend.Queries.{DBContract, SurrogateTpId} | ||
import org.openjdk.jmh.annotations._ | ||
import scalaz.std.list._ | ||
import spray.json._ | ||
import spray.json.DefaultJsonProtocol._ | ||
|
||
class InsertBenchmark extends ContractDaoBenchmark { | ||
@Param(Array("1", "3", "5", "7", "9")) | ||
var batches: Int = _ | ||
|
||
@Param(Array("1000")) | ||
var numContracts: Int = _ | ||
|
||
private var contracts: List[DBContract[SurrogateTpId, JsValue, JsValue, Seq[String]]] = _ | ||
|
||
private var contractCids: List[String] = _ | ||
|
||
@Setup(Level.Trial) | ||
override def setup(): Unit = { | ||
super.setup() | ||
contracts = | ||
(1 until numContracts + 1).map { i => | ||
// Use negative cids to avoid collisions with other contracts | ||
contract(-i, "Alice") | ||
}.toList | ||
|
||
contractCids = contracts.map(_.contractId) | ||
|
||
(0 until batches).foreach { batch => | ||
insertBatch("Alice", batch * batchSize) | ||
} | ||
() | ||
} | ||
|
||
@TearDown(Level.Invocation) | ||
def dropContracts: Unit = { | ||
val deleted = dao.transact(dao.jdbcDriver.queries.deleteContracts(contractCids)).unsafeRunSync() | ||
assert(deleted == numContracts) | ||
} | ||
|
||
@Benchmark | ||
def run(): Unit = { | ||
val driver: SupportedJdbcDriver = dao.jdbcDriver | ||
import driver._ | ||
val inserted = dao.transact(driver.queries.insertContracts(contracts)).unsafeRunSync() | ||
assert(inserted == numContracts) | ||
} | ||
} |