-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev-dependent-on-snapshots'
- Loading branch information
Showing
17 changed files
with
783 additions
and
153 deletions.
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
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
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 |
---|---|---|
@@ -1,6 +1,13 @@ | ||
import com.huanshankeji.CommonDependencies | ||
import com.huanshankeji.CommonGradleClasspathDependencies | ||
import com.huanshankeji.CommonVersions | ||
|
||
val projectVersion = "0.2.1-SNAPSHOT" | ||
val commonVersions = CommonVersions(kotlin = "1.8.21") | ||
val projectVersion = "0.3.0-SNAPSHOT" | ||
|
||
val commonVersions = CommonVersions() | ||
val commonDependencies = CommonDependencies(commonVersions) | ||
val commonGradleClasspathDependencies = CommonGradleClasspathDependencies(commonVersions) | ||
|
||
object DependencyVersions { | ||
val exposedAdtMapping = "0.1.0" | ||
} |
Binary file not shown.
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
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
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
11 changes: 11 additions & 0 deletions
11
lib/src/benchmarks/kotlin/com/huanshankeji/exposed/benchmark/AbstractBenchmark.kt
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,11 @@ | ||
package com.huanshankeji.exposed.benchmark | ||
|
||
import kotlinx.benchmark.Measurement | ||
import kotlinx.benchmark.Scope | ||
import kotlinx.benchmark.State | ||
import kotlinx.benchmark.Warmup | ||
|
||
@State(Scope.Benchmark) | ||
@Warmup(time = 1, iterations = 2) | ||
@Measurement(time = 1, iterations = 2) | ||
abstract class AbstractBenchmark |
13 changes: 13 additions & 0 deletions
13
lib/src/benchmarks/kotlin/com/huanshankeji/exposed/benchmark/EmptyBenchmark.kt
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,13 @@ | ||
package com.huanshankeji.exposed.benchmark | ||
|
||
import kotlinx.benchmark.Benchmark | ||
import kotlinx.benchmark.Scope | ||
import kotlinx.benchmark.State | ||
|
||
@State(Scope.Benchmark) | ||
class EmptyBenchmark : AbstractBenchmark() { | ||
// for comparison | ||
@Benchmark | ||
fun empty() { | ||
} | ||
} |
99 changes: 99 additions & 0 deletions
99
...rc/benchmarks/kotlin/com/huanshankeji/exposed/benchmark/PreparedSqlGenerationBenchmark.kt
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,99 @@ | ||
package com.huanshankeji.exposed.benchmark | ||
|
||
import com.huanshankeji.exposed.benchmark.table.VarcharTable | ||
import com.huanshankeji.exposed.deleteAllStatement | ||
import com.huanshankeji.exposed.deleteWhereStatement | ||
import com.huanshankeji.exposed.insertStatement | ||
import com.huanshankeji.exposed.updateStatement | ||
import kotlinx.benchmark.* | ||
import kotlinx.coroutines.* | ||
import org.jetbrains.exposed.sql.* | ||
import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq | ||
import org.jetbrains.exposed.sql.statements.Statement | ||
import org.jetbrains.exposed.sql.transactions.transaction | ||
|
||
@State(Scope.Benchmark) | ||
class PreparedSqlGenerationBenchmark : WithContainerizedDatabaseBenchmark() { | ||
enum class StatementEnum(val statement: Statement<*>) { | ||
SelectAll(VarcharTable.selectAll()), | ||
SelectWhere(VarcharTable.select(VarcharTable.id eq 0L)), | ||
Insert(VarcharTable.insertStatement { it[varcharColumn] = "string" }), | ||
Update(VarcharTable.updateStatement({ VarcharTable.id eq 0L }) { | ||
it[varcharColumn] = "string" | ||
}), | ||
DeleteAll(VarcharTable.deleteAllStatement()), | ||
DeleteStatement(VarcharTable.deleteWhereStatement { VarcharTable.id eq 0L }) | ||
} | ||
|
||
@Param("SelectAll", "SelectWhere", "Insert", "Update", "DeleteAll", "DeleteStatement") | ||
lateinit var statementEnum: StatementEnum | ||
val statement get() = statementEnum.statement | ||
|
||
/* | ||
var transaction: Transaction? = null | ||
val releaseTransactionMutex = Mutex(true) | ||
@OptIn(DelicateCoroutinesApi::class) | ||
val context = newSingleThreadContext("keep transaction alive") | ||
override fun setUp() { | ||
// for debugging purposes | ||
fun println(x:Int) = println("break point $x") | ||
super.setUp() | ||
println(1) | ||
runBlocking { | ||
println(2) | ||
val setTransactionMutex = Mutex(true) | ||
println(3) | ||
CoroutineScope(context).launch { | ||
// doesn't work because the transaction is stored into the current thread's `ThreadLocal` for `arguments()` to use | ||
newSuspendedTransaction (db = database) { | ||
println(4) | ||
transaction = this | ||
println(5) | ||
setTransactionMutex.unlock() | ||
println(6) | ||
releaseTransactionMutex.lock() | ||
println(7) | ||
} | ||
} | ||
println(8) | ||
setTransactionMutex.lock() | ||
println(9) | ||
} | ||
println(10) | ||
} | ||
override fun tearDown() { | ||
transaction = null | ||
releaseTransactionMutex.unlock() | ||
println("isActive: " + context.isActive) | ||
context.cancel() | ||
super.tearDown() | ||
} | ||
*/ | ||
|
||
companion object { | ||
const val `1M` = 1000_000 | ||
} | ||
|
||
@Benchmark | ||
fun prepareSQL1M() { | ||
transaction(database) { | ||
repeat(`1M`) { | ||
statement.prepareSQL(this) | ||
} | ||
} | ||
} | ||
|
||
@Benchmark | ||
fun arguments1M() { | ||
transaction(database) { | ||
repeat(`1M`) { | ||
statement.arguments() | ||
} | ||
} | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
lib/src/benchmarks/kotlin/com/huanshankeji/exposed/benchmark/StatementBenchmark.kt
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,41 @@ | ||
package com.huanshankeji.exposed.benchmark | ||
|
||
import com.huanshankeji.exposed.benchmark.table.EmptyTable | ||
import com.huanshankeji.exposed.benchmark.table.VarcharTable | ||
import com.huanshankeji.exposed.deleteAllStatement | ||
import com.huanshankeji.exposed.deleteWhereStatement | ||
import com.huanshankeji.exposed.insertStatement | ||
import com.huanshankeji.exposed.updateStatement | ||
import kotlinx.benchmark.Benchmark | ||
import kotlinx.benchmark.Param | ||
import kotlinx.benchmark.Scope | ||
import kotlinx.benchmark.State | ||
import org.jetbrains.exposed.sql.Op | ||
import org.jetbrains.exposed.sql.Table | ||
import org.jetbrains.exposed.sql.selectAll | ||
|
||
@State(Scope.Benchmark) | ||
class StatementBenchmark : AbstractBenchmark() { | ||
enum class TableEnum(val table: Table) { | ||
EmptyTableEnum(EmptyTable), VarcharTableEnum(VarcharTable) | ||
} | ||
|
||
@Param("EmptyTableEnum", "VarcharTableEnum") | ||
lateinit var tableEnum: TableEnum | ||
val table get() = tableEnum.table | ||
|
||
@Benchmark | ||
fun createSelectStatement() = table.selectAll() | ||
|
||
@Benchmark | ||
fun createInsertStatement() = table.insertStatement {} | ||
|
||
@Benchmark | ||
fun createUpdateStatement() = table.updateStatement(null) {} | ||
|
||
@Benchmark | ||
fun deleteAllStatement() = table.deleteAllStatement() | ||
|
||
@Benchmark | ||
fun deleteWhereStatement() = table.deleteWhereStatement { Op.TRUE } | ||
} |
69 changes: 69 additions & 0 deletions
69
lib/src/benchmarks/kotlin/com/huanshankeji/exposed/benchmark/TransactionBenchmark.kt
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,69 @@ | ||
package com.huanshankeji.exposed.benchmark | ||
|
||
import com.huanshankeji.kotlinx.coroutine.awaitAny | ||
import kotlinx.benchmark.Benchmark | ||
import kotlinx.benchmark.Scope | ||
import kotlinx.benchmark.State | ||
import kotlinx.coroutines.* | ||
import org.jetbrains.exposed.sql.transactions.experimental.newSuspendedTransaction | ||
import org.jetbrains.exposed.sql.transactions.experimental.suspendedTransactionAsync | ||
import org.jetbrains.exposed.sql.transactions.transaction | ||
import kotlin.concurrent.thread | ||
|
||
@State(Scope.Benchmark) | ||
class TransactionBenchmark : WithContainerizedDatabaseBenchmark() { | ||
@Benchmark | ||
fun transaction() { | ||
transaction(database) {} | ||
} | ||
|
||
companion object { | ||
const val `10K` = 10_000 | ||
} | ||
|
||
@Benchmark | ||
fun _10KTransactions() { | ||
repeat(`10K`) { transaction(database) {} } | ||
} | ||
|
||
private suspend fun awaitAsync10KTransactions() = | ||
coroutineScope { | ||
List(`10K`) { async { transaction(database) {} } }.awaitAll() | ||
} | ||
|
||
@Benchmark | ||
fun singleThreadConcurrent10KTransactions() = runBlocking { | ||
awaitAsync10KTransactions() | ||
} | ||
|
||
|
||
@Benchmark | ||
fun multiThreadConcurrent10KTransactions() = runBlocking { | ||
withContext(Dispatchers.Default) { | ||
awaitAsync10KTransactions() | ||
} | ||
} | ||
|
||
|
||
@Benchmark | ||
fun _10KSuspendedTransactions() = runBlocking { | ||
repeat(`10K`) { newSuspendedTransaction(db = database) {} } | ||
} | ||
|
||
@Benchmark | ||
fun _10KSuspendedTransactionAsyncs() = runBlocking { | ||
List(`10K`) { suspendedTransactionAsync(db = database) {} }.awaitAny() | ||
} | ||
|
||
@Benchmark | ||
fun multiThreadMultiConnectionEach10KLocalTransactions() { | ||
List(Runtime.getRuntime().availableProcessors()) { | ||
thread { | ||
val database = databaseConnect() | ||
repeat(`10K`) { transaction(database) {} } | ||
} | ||
}.forEach { | ||
it.join() | ||
} | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
...enchmarks/kotlin/com/huanshankeji/exposed/benchmark/WithContainerizedDatabaseBenchmark.kt
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,33 @@ | ||
package com.huanshankeji.exposed.benchmark | ||
|
||
import com.huanshankeji.exposedvertxsqlclient.ConnectionConfig | ||
import com.huanshankeji.exposedvertxsqlclient.exposedDatabaseConnectPostgreSql | ||
import kotlinx.benchmark.Scope | ||
import kotlinx.benchmark.Setup | ||
import kotlinx.benchmark.State | ||
import kotlinx.benchmark.TearDown | ||
import org.jetbrains.exposed.sql.Database | ||
import org.testcontainers.containers.PostgreSQLContainer | ||
import org.testcontainers.utility.DockerImageName | ||
|
||
@State(Scope.Benchmark) | ||
class WithContainerizedDatabaseBenchmark : AbstractBenchmark() { | ||
val postgreSQLContainer = PostgreSQLContainer(DockerImageName.parse("postgres:latest")) | ||
lateinit var database: Database | ||
|
||
fun databaseConnect() = | ||
exposedDatabaseConnectPostgreSql(with(postgreSQLContainer) { | ||
ConnectionConfig.Socket(host, firstMappedPort, username, password, databaseName) | ||
}) | ||
|
||
@Setup | ||
fun setUp() { | ||
postgreSQLContainer.start() | ||
database = databaseConnect() | ||
} | ||
|
||
@TearDown | ||
fun tearDown() { | ||
postgreSQLContainer.stop() | ||
} | ||
} |
Oops, something went wrong.