Skip to content

Commit

Permalink
improve connection pool management
Browse files Browse the repository at this point in the history
  • Loading branch information
vendelieu committed Dec 15, 2024
1 parent 1779db0 commit 881bd0d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 17 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ dependencies {

# Benchmark

There is a benchmark comparing popular library solutions (more is better):
There is
a [benchmark](https://github.com/vendelieu/re.this/tree/master/benchmarks/src/main/kotlin/eu/vendeli/rethis/benchmarks)
comparing popular library solutions (more is better):

```javascript
main summary:
Expand All @@ -42,8 +44,8 @@ KredsBenchmark.kredsGet thrpt 4 953107.876 ± 474436.565 ops/s
KredsBenchmark.kredsSet thrpt 4 860740.621 ± 219859.604 ops/s
LettuceBenchmark.lettuceGet thrpt 5 590292.775 ± 3079960.658 ops/s
LettuceBenchmark.lettuceSet thrpt 5 686790.196 ± 2646041.580 ops/s
RethisBenchmark.rethisGet thrpt 5 1494973.261 ± 680369.613 ops/s
RethisBenchmark.rethisSet thrpt 5 1558386.548 ± 1374920.575 ops/s
RethisBenchmark.rethisGet thrpt 5 1376783.555 ± 680369.613 ops/s
RethisBenchmark.rethisSet thrpt 5 1487596.743 ± 487192.094 ops/s
```

# Usage
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package eu.vendeli.rethis.types.core

import eu.vendeli.rethis.ReThis
import eu.vendeli.rethis.utils.*
import eu.vendeli.rethis.utils.coLaunch
import eu.vendeli.rethis.utils.readRedisMessage
import eu.vendeli.rethis.utils.sendRequest
import eu.vendeli.rethis.utils.writeRedisValue
import io.ktor.network.selector.*
import io.ktor.network.sockets.*
import io.ktor.network.tls.*
import io.ktor.util.logging.*
import io.ktor.utils.io.*
import io.ktor.utils.io.core.*
import kotlinx.coroutines.*
import kotlinx.coroutines.channels.Channel
import kotlinx.io.Buffer
Expand Down Expand Up @@ -64,17 +65,6 @@ internal class ConnectionPool(
return conn
}

@OptIn(InternalAPI::class)
private suspend fun reset(conn: Connection) {
conn.input.takeIf { it.availableForRead > 0 }?.also {
logger.warn("Discarding ${it.availableForRead} bytes from input stream")
}?.discard()

conn.output.takeIf { it.writeBuffer.size > 0 }?.writeBuffer?.also {
logger.warn("Discarding ${it.size} bytes from output stream")
}?.flush()
}

@Suppress("OPT_IN_USAGE")
fun prepare() = GlobalScope.launch {
logger.info("Filling ConnectionPool with connections")
Expand Down

0 comments on commit 881bd0d

Please sign in to comment.