Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a benchmark for contract insertion in the JSON API #10272

Merged
merged 2 commits into from
Jul 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,53 @@
// 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 @BenchmarkMode(Array(Mode.AverageTime))
def run(): Unit = {
val driver: SupportedJdbcDriver = dao.jdbcDriver
import driver._
val inserted = dao.transact(driver.queries.insertContracts(contracts)).unsafeRunSync()
assert(inserted == numContracts)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class QueryBenchmark extends ContractDaoBenchmark {
()
}

@Benchmark
@Benchmark @BenchmarkMode(Array(Mode.AverageTime))
def run(): Unit = {
implicit val driver: SupportedJdbcDriver = dao.jdbcDriver
val result = dao
Expand Down