-
Notifications
You must be signed in to change notification settings - Fork 199
/
QueryPayloadBenchmark.scala
85 lines (71 loc) · 2.5 KB
/
QueryPayloadBenchmark.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// 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 com.daml.lf.data.ImmArray.ImmArraySeq
import com.daml.lf.data.Ref
import com.daml.lf.iface
import com.daml.http.dbbackend.Queries.SurrogateTpId
import com.daml.http.domain.{Party, TemplateId}
import com.daml.http.query.ValuePredicate
import com.daml.http.util.Logging.instanceUUIDLogCtx
import com.daml.scalautil.Statement.discard
import com.daml.scalautil.nonempty.NonEmpty
import org.openjdk.jmh.annotations._
import spray.json._
import scala.collection.compat._
class QueryPayloadBenchmark extends ContractDaoBenchmark {
@Param(Array("1", "10", "100"))
var extraParties: Int = _
@Param(Array("1", "100", "100"))
var extraPayloadValues: Int = _
private val tpid = TemplateId("-pkg-", "M", "T")
private var surrogateTpid: SurrogateTpId = _
val party = "Alice"
private[this] val dummyPackageId = Ref.PackageId.assertFromString("dummy-package-id")
private[this] val dummyId = Ref.Identifier(
dummyPackageId,
Ref.QualifiedName.assertFromString("Foo:Bar"),
)
private[this] val dummyTypeCon = iface.TypeCon(iface.TypeConName(dummyId), ImmArraySeq.empty)
val predicate = ValuePredicate.fromJsObject(
Map("v" -> JsNumber(0)),
dummyTypeCon,
Map(
dummyId -> iface.DefDataType(
ImmArraySeq.empty,
iface.Record(
ImmArraySeq(
(Ref.Name.assertFromString("v"), iface.TypePrim(iface.PrimType.Int64, ImmArraySeq()))
)
),
)
).lift,
)
def whereClause = predicate.toSqlWhereClause(dao.jdbcDriver)
@Setup(Level.Trial)
override def setup(): Unit = {
super.setup()
surrogateTpid = insertTemplate(tpid)
val parties: List[String] = party :: (0 until extraParties).map(i => s"p$i").toList
var offset = 0
parties.foreach { p =>
(0 until extraPayloadValues).foreach { v =>
insertBatch(p, surrogateTpid, offset, JsObject("v" -> JsNumber(v)))
offset += batchSize
}
}
}
@Benchmark @BenchmarkMode(Array(Mode.AverageTime))
def run(): Unit = {
implicit val sjd: SupportedJdbcDriver.TC = dao.jdbcDriver
val result = instanceUUIDLogCtx(implicit lc =>
dao
.transact(
ContractDao.selectContracts(NonEmpty.pour(Party(party)) into Set, tpid, whereClause)
)
.unsafeRunSync()
)
assert(result.size == batchSize)
}
discard(IterableOnce) // only needed for scala 2.12
}