Skip to content

Commit

Permalink
Add a benchmark for contract insertion in the JSON API
Browse files Browse the repository at this point in the history
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
cocreature committed Jul 14, 2021
1 parent f6da4c0 commit 153dcb7
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

package com.daml.http.dbbackend

import scalaz.std.list._
import cats.instances.list._
import doobie.util.log.LogHandler
import com.daml.doobie.logging.Slf4jLogHandler
Expand All @@ -12,6 +11,7 @@ import com.daml.http.domain.TemplateId
import com.daml.testing.oracle, oracle.{OracleAround, User}
import org.openjdk.jmh.annotations._
import scala.concurrent.ExecutionContext
import scalaz.std.list._
import spray.json._
import spray.json.DefaultJsonProtocol._

Expand Down
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)
}
}

0 comments on commit 153dcb7

Please sign in to comment.