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

Setting up JMH for PartiQL #427

Merged
merged 6 commits into from
Sep 28, 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
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,22 @@ This will build the reference interpreter and test framework, then run all unit
- `docs/user` documentation for developers embedding the interpreter in an application.
- `docs/dev` documentation for developers of the interpreter library.
- `lang` contains the source code of the library containing the interpreter.
- `lang/jmh` contains the JMH benchmarks for PartiQL.
- `cli` contains the source code of the command-line interface and interactive prompt. (CLI/REPL)
- `testframework` contains the source code of the integration test framework.
- `integration-test/test-scripts` contains the test scripts executed by the test framework as part of the
Gradle build.
- `integration-test/test-scripts-ignored` contains test scripts which cannot be executed during the Gradle build.

### Running JMH benchmarks

To run JMH benchmarks located in `lang/jmh`, build the entire project first and then run
the following command:

```
$./gradlew jmh
```

### Examples

See the [examples](examples) project in this repository for examples covering
Expand Down
1 change: 0 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ plugins {
id 'org.jetbrains.kotlin.jvm' version '1.3.11' apply false
// https://arturbosch.github.io/detekt/groovydsl.html
id 'io.gitlab.arturbosch.detekt' version '1.4.0' apply false

}

allprojects {
Expand Down
7 changes: 6 additions & 1 deletion lang/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ plugins {
id 'org.jetbrains.dokka' version '0.9.18'
id 'org.jetbrains.kotlin.jvm'
id 'signing'
id 'me.champeau.gradle.jmh' version '0.5.3'
}

tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
Expand Down Expand Up @@ -56,6 +57,10 @@ dependencies {
testImplementation 'org.junit.jupiter:junit-jupiter-params:5.7.0'
}

sourceSets {
jmh.kotlin.srcDirs = ["jmh"]
}

task generatePigDomains {
group = "code generation"

Expand Down Expand Up @@ -165,4 +170,4 @@ jacocoTestReport {
csv.enabled false
html.destination file("${buildDir}/reports/jacoco/html")
}
}
}
94 changes: 94 additions & 0 deletions lang/jmh/org/partiql/jmh/PartiQLBenchmark.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
package org.partiql.jmh

import com.amazon.ion.system.IonSystemBuilder
import org.openjdk.jmh.annotations.Benchmark
import org.openjdk.jmh.annotations.BenchmarkMode
import org.openjdk.jmh.annotations.Mode
import org.openjdk.jmh.annotations.Scope
import org.openjdk.jmh.annotations.State
import org.openjdk.jmh.infra.Blackhole
import org.partiql.lang.CompilerPipeline
import org.partiql.lang.eval.EvaluationSession
import org.partiql.lang.syntax.SqlParser


/**
* These are the sample benchmarks to demonstrate how JMH benchmarks in PartiQL should be set up.
* Refer this [JMH tutorial](http://tutorials.jenkov.com/java-performance/jmh.html) for more information on [Benchmark]s,
* [BenchmarkMode]s, etc.
*/
open class PartiQLBenchmark {
@State(Scope.Thread)
open class MyState {
val ion = IonSystemBuilder.standard().build()
val parser = SqlParser(ion)
val pipeline = CompilerPipeline.standard(ion)

val data = """
{
'hr': {
'employeesNestScalars': <<
{
'id': 3,
'name': 'Bob Smith',
'title': null,
'projects': [
'AWS Redshift Spectrum querying',
'AWS Redshift security',
'AWS Aurora security'
]
},
{
'id': 4,
'name': 'Susan Smith',
'title': 'Dev Mgr',
'projects': []
},
{
'id': 6,
'name': 'Jane Smith',
'title': 'Software Eng 2',
'projects': [ 'AWS Redshift security' ]
}
>>
}
}
""".trimIndent()
val bindings = pipeline.compile(parser.parseExprNode(data)).eval(EvaluationSession.standard()).bindings
val session = EvaluationSession.build { globals(bindings) }

val query = "SELECT * FROM hr.employeesNestScalars"
val exprNode = parser.parseExprNode(query)
val expression = pipeline.compile(exprNode)
}

/**
* Example PartiQL benchmark for parsing a query
*/
@Benchmark
@BenchmarkMode(Mode.AverageTime)
fun testPartiQLParser(state: MyState, blackhole: Blackhole) {
val expr = state.parser.parseExprNode(state.query)
blackhole.consume(expr)
}

/**
* Example PartiQL benchmark for compiling a query
*/
@Benchmark
@BenchmarkMode(Mode.AverageTime)
fun testPartiQLCompiler(state: MyState, blackhole: Blackhole) {
val exprValue = state.pipeline.compile(state.exprNode)
blackhole.consume(exprValue)
}

/**
* Example PartiQL benchmark for evaluating a query
*/
@Benchmark
@BenchmarkMode(Mode.AverageTime)
fun testPartiQLEvaluator(state: MyState, blackhole: Blackhole) {
val exprValue = state.expression.eval(state.session)
blackhole.consume(exprValue)
}
}
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ rootProject.name = 'PartiQL'
include('lang',
'cli',
'examples',
'testscript',
'testscript',
'pts')