Skip to content

Commit 09a8c0f

Browse files
dev: workers.count
1 parent fe472f1 commit 09a8c0f

File tree

2 files changed

+24
-11
lines changed

2 files changed

+24
-11
lines changed

jdbc/spring-test-db/src/main/kotlin/tech/ydb/testdb/TestDbApplication.kt

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,14 @@ package tech.ydb.testdb
33
import jakarta.persistence.EntityManager
44
import org.slf4j.LoggerFactory
55
import org.springframework.beans.factory.annotation.Autowired
6+
import org.springframework.beans.factory.annotation.Value
67
import org.springframework.boot.CommandLineRunner
78
import org.springframework.boot.autoconfigure.SpringBootApplication
89
import org.springframework.boot.runApplication
910
import java.time.Instant
11+
import java.util.concurrent.ExecutorService
12+
import java.util.concurrent.Executors
13+
import kotlin.concurrent.thread
1014

1115
/**
1216
* @author Kirill Kurdyukov
@@ -20,21 +24,28 @@ class TestDbApplication : CommandLineRunner {
2024
@Autowired
2125
lateinit var entityManager: EntityManager
2226

27+
@Value("\${workers.count}")
28+
var workersCount: Int = 0
29+
2330
override fun run(vararg args: String?) {
2431
val testString = String(ByteArray(1024) { 'a'.code.toByte() })
2532

26-
var sink = 0
27-
val t0 = System.nanoTime()
28-
val end = t0 + 10_000_000_000L
29-
var count = 0
30-
while (System.nanoTime() < end) {
31-
sink += getFixedString(testString).length
32-
count++
33+
repeat(workersCount) {
34+
thread {
35+
var sink = 0
36+
val t0 = System.nanoTime()
37+
val end = t0 + 10_000_000_000L
38+
var count = 0
39+
while (System.nanoTime() < end) {
40+
sink += getFixedString(testString).length
41+
count++
42+
}
43+
val elapsed = System.nanoTime() - t0
44+
val avgMs = elapsed.toDouble() / count / 1_000_000.0
45+
val opsPerSec = count * 1e9 / elapsed
46+
log.info("WorkerNum {}, avg={} ms/op, throughput={} ops/s", it, avgMs, opsPerSec)
47+
}
3348
}
34-
val elapsed = System.nanoTime() - t0
35-
val avgMs = elapsed.toDouble() / count / 1_000_000.0
36-
val opsPerSec = count * 1e9 / elapsed
37-
log.info("avg={} ms/op, throughput={} ops/s", avgMs, opsPerSec)
3849
}
3950

4051
fun getFixedString(s: String): String {

jdbc/spring-test-db/src/main/resources/application.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@ spring.jpa.properties.hibernate.dialect=tech.ydb.hibernate.dialect.YdbDialect
22

33
spring.datasource.driver-class-name=tech.ydb.jdbc.YdbDriver
44
spring.datasource.url=jdbc:ydb:grpc://localhost:2136/local
5+
6+
workers.count=100

0 commit comments

Comments
 (0)