Merge branch 'performance/db-connection-pool'
This commit is contained in:
commit
a324f636da
1
.gitignore
vendored
1
.gitignore
vendored
@ -118,3 +118,4 @@ dist
|
|||||||
|
|
||||||
# Service worker
|
# Service worker
|
||||||
sw.*
|
sw.*
|
||||||
|
*.private.env.json
|
||||||
|
|||||||
@ -1,10 +1,10 @@
|
|||||||
# Register a new user
|
# Register a new user
|
||||||
POST http://localhost:8081/login
|
POST http://localhost:8081/user/login
|
||||||
Content-Type: application/json
|
Content-Type: application/json
|
||||||
|
|
||||||
{
|
{
|
||||||
"username": "hubert",
|
"username": "{{username}}",
|
||||||
"password": "test"
|
"password": "{{password}}"
|
||||||
}
|
}
|
||||||
|
|
||||||
> {%
|
> {%
|
||||||
@ -23,32 +23,3 @@ client.test("Request executed successfully", function() {
|
|||||||
client.assert(response.status === 200, "Response status is not 200");
|
client.assert(response.status === 200, "Response status is not 200");
|
||||||
});
|
});
|
||||||
%}
|
%}
|
||||||
|
|
||||||
### Create a note
|
|
||||||
POST http://localhost:8081/notes/tortue
|
|
||||||
Content-Type: application/json
|
|
||||||
Authorization: Bearer {{token}}
|
|
||||||
|
|
||||||
{
|
|
||||||
"tags": [
|
|
||||||
"Dev",
|
|
||||||
"Server"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
> {%
|
|
||||||
client.test("Request executed successfully", function() {
|
|
||||||
client.assert(response.status === 201, "Response status is not 200");
|
|
||||||
});
|
|
||||||
%}
|
|
||||||
|
|
||||||
### Read a note
|
|
||||||
GET http://localhost:8081/notes/babar
|
|
||||||
Content-Type: application/json
|
|
||||||
Authorization: Bearer {{token}}
|
|
||||||
|
|
||||||
> {%
|
|
||||||
client.test("Request executed successfully", function() {
|
|
||||||
client.assert(response.status === 200, "Response status is not 200");
|
|
||||||
});
|
|
||||||
%}
|
|
||||||
|
|||||||
20
api/pom.xml
20
api/pom.xml
@ -49,6 +49,16 @@
|
|||||||
<enabled>true</enabled>
|
<enabled>true</enabled>
|
||||||
</snapshots>
|
</snapshots>
|
||||||
</repository>
|
</repository>
|
||||||
|
<repository>
|
||||||
|
<id>jitpack</id>
|
||||||
|
<url>https://jitpack.io</url>
|
||||||
|
<releases>
|
||||||
|
<enabled>true</enabled>
|
||||||
|
</releases>
|
||||||
|
<snapshots>
|
||||||
|
<enabled>true</enabled>
|
||||||
|
</snapshots>
|
||||||
|
</repository>
|
||||||
</repositories>
|
</repositories>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
@ -118,6 +128,11 @@
|
|||||||
<artifactId>ktorm-support-mysql</artifactId>
|
<artifactId>ktorm-support-mysql</artifactId>
|
||||||
<version>${ktorm_version}</version>
|
<version>${ktorm_version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.github.hekeki</groupId>
|
||||||
|
<artifactId>huckleberry</artifactId>
|
||||||
|
<version>0.0.2-beta</version>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.flywaydb</groupId>
|
<groupId>org.flywaydb</groupId>
|
||||||
<artifactId>flyway-core</artifactId>
|
<artifactId>flyway-core</artifactId>
|
||||||
@ -128,6 +143,11 @@
|
|||||||
<artifactId>jbcrypt</artifactId>
|
<artifactId>jbcrypt</artifactId>
|
||||||
<version>${jbcrypt_version}</version>
|
<version>${jbcrypt_version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.zaxxer</groupId>
|
||||||
|
<artifactId>HikariCP</artifactId>
|
||||||
|
<version>3.4.2</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
<build>
|
<build>
|
||||||
<sourceDirectory>${project.basedir}/src</sourceDirectory>
|
<sourceDirectory>${project.basedir}/src</sourceDirectory>
|
||||||
|
|||||||
@ -4,7 +4,7 @@
|
|||||||
<pattern>%d{YYYY-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
|
<pattern>%d{YYYY-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
|
||||||
</encoder>
|
</encoder>
|
||||||
</appender>
|
</appender>
|
||||||
<root level="trace">
|
<root level="INFO">
|
||||||
<appender-ref ref="STDOUT"/>
|
<appender-ref ref="STDOUT"/>
|
||||||
</root>
|
</root>
|
||||||
<logger name="org.eclipse.jetty" level="INFO"/>
|
<logger name="org.eclipse.jetty" level="INFO"/>
|
||||||
|
|||||||
@ -1,11 +1,12 @@
|
|||||||
package be.vandewalleh.features
|
package be.vandewalleh.features
|
||||||
|
|
||||||
import be.vandewalleh.auth.SimpleJWT
|
import be.vandewalleh.auth.SimpleJWT
|
||||||
|
import com.zaxxer.hikari.HikariConfig
|
||||||
|
import com.zaxxer.hikari.HikariDataSource
|
||||||
import io.ktor.application.*
|
import io.ktor.application.*
|
||||||
import org.kodein.di.Kodein
|
import org.kodein.di.Kodein
|
||||||
import org.kodein.di.generic.bind
|
import org.kodein.di.generic.bind
|
||||||
import org.kodein.di.generic.instance
|
import org.kodein.di.generic.instance
|
||||||
import org.mariadb.jdbc.MariaDbDataSource
|
|
||||||
import javax.sql.DataSource
|
import javax.sql.DataSource
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -18,15 +19,14 @@ fun Application.configurationFeature() {
|
|||||||
val host = property("database.host").getString()
|
val host = property("database.host").getString()
|
||||||
val port = property("database.port").getString()
|
val port = property("database.port").getString()
|
||||||
val name = property("database.name").getString()
|
val name = property("database.name").getString()
|
||||||
val user = property("database.user").getString()
|
|
||||||
val password = property("database.password").getString()
|
|
||||||
|
|
||||||
val url = "jdbc:mariadb://$host:$port/$name"
|
val hikariConfig = HikariConfig().apply {
|
||||||
|
jdbcUrl = "jdbc:mariadb://$host:$port/$name"
|
||||||
MariaDbDataSource(url).apply {
|
username = this@with.property("database.user").getString()
|
||||||
this.user = user
|
password = this@with.property("database.password").getString()
|
||||||
setPassword(password)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
HikariDataSource(hikariConfig)
|
||||||
}
|
}
|
||||||
|
|
||||||
val simpleJwt = SimpleJWT(environment.config.property("jwt.secret").getString())
|
val simpleJwt = SimpleJWT(environment.config.property("jwt.secret").getString())
|
||||||
|
|||||||
50
api/test/NotesRetrievePerformanceTest.kt
Normal file
50
api/test/NotesRetrievePerformanceTest.kt
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
import be.vandewalleh.services.NotesService
|
||||||
|
import be.vandewalleh.services.UserService
|
||||||
|
import com.hekeki.huckleberry.Benchmark
|
||||||
|
import com.hekeki.huckleberry.BenchmarkRunner
|
||||||
|
import com.hekeki.huckleberry.BenchmarkTest
|
||||||
|
import com.hekeki.huckleberry.TimeUnit
|
||||||
|
import com.zaxxer.hikari.HikariConfig
|
||||||
|
import com.zaxxer.hikari.HikariDataSource
|
||||||
|
import me.liuwj.ktorm.database.*
|
||||||
|
import org.junit.jupiter.api.Assertions.*
|
||||||
|
import org.junit.jupiter.api.Test
|
||||||
|
import org.kodein.di.Kodein
|
||||||
|
import org.kodein.di.generic.bind
|
||||||
|
import org.kodein.di.generic.instance
|
||||||
|
import org.kodein.di.generic.singleton
|
||||||
|
|
||||||
|
|
||||||
|
val hikariConfig = HikariConfig().apply {
|
||||||
|
jdbcUrl = "jdbc:mariadb://localhost:3306/Notes"
|
||||||
|
username = "test"
|
||||||
|
password = "test"
|
||||||
|
}
|
||||||
|
|
||||||
|
val dataSource = HikariDataSource(hikariConfig)
|
||||||
|
|
||||||
|
val db = Database.Companion.connect(dataSource)
|
||||||
|
|
||||||
|
val kodein = Kodein {
|
||||||
|
bind<Database>() with singleton { db }
|
||||||
|
bind<UserService>() with singleton { UserService(this.kodein) }
|
||||||
|
bind<NotesService>() with singleton { NotesService(this.kodein) }
|
||||||
|
}
|
||||||
|
|
||||||
|
val notesService by kodein.instance<NotesService>()
|
||||||
|
|
||||||
|
@Benchmark(threads = 1, iterations = 30, warmup = true, warmupIterations = 1000, timeUnit = TimeUnit.MILLIS)
|
||||||
|
class RetrieveNotesBenchmarkTest : BenchmarkTest {
|
||||||
|
|
||||||
|
override fun execute() {
|
||||||
|
notesService.getNotes(15)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun compute() {
|
||||||
|
val benchmarkResult = BenchmarkRunner(RetrieveNotesBenchmarkTest::class.java).run()
|
||||||
|
assertTrue(benchmarkResult.median(2, TimeUnit.MILLIS))
|
||||||
|
assertTrue(benchmarkResult.maxTime(4, TimeUnit.MILLIS))
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user