-
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.
perf: Supprot backpressure and & auto restart transaciton listener (#42)
* perf: supprot Backpressure and & auto restart transaciton listener * docs: netx version 0.2.0 to 0.2.1 * perf: boundElastic 과 parallel 사용을 수정한다
- Loading branch information
Showing
12 changed files
with
91 additions
and
52 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
14 changes: 13 additions & 1 deletion
14
src/main/kotlin/org/rooftop/netx/engine/AbstractTransactionListener.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 |
---|---|---|
@@ -1,22 +1,34 @@ | ||
package org.rooftop.netx.engine | ||
|
||
import org.rooftop.netx.idl.Transaction | ||
import reactor.core.publisher.BufferOverflowStrategy | ||
import reactor.core.publisher.Flux | ||
import reactor.core.publisher.Mono | ||
import reactor.core.scheduler.Schedulers | ||
|
||
abstract class AbstractTransactionListener( | ||
private val backpressureSize: Int, | ||
private val transactionDispatcher: AbstractTransactionDispatcher, | ||
) { | ||
|
||
fun subscribeStream() { | ||
receive() | ||
.publishOn(Schedulers.boundedElastic()) | ||
.onBackpressureBuffer(backpressureSize, BufferOverflowStrategy.DROP_LATEST) | ||
.flatMap { (transaction, messageId) -> | ||
transactionDispatcher.dispatch(transaction, messageId) | ||
.map { transaction to messageId } | ||
.onErrorResume { Mono.empty() } | ||
} | ||
.subscribeOn(Schedulers.parallel()) | ||
.restartWhenTerminated() | ||
.subscribe() | ||
} | ||
|
||
protected abstract fun receive(): Flux<Pair<Transaction, String>> | ||
|
||
private fun <T> Flux<T>.restartWhenTerminated(): Flux<T> { | ||
return this.doOnTerminate { | ||
subscribeStream() | ||
} | ||
} | ||
} |
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
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
29 changes: 19 additions & 10 deletions
29
src/test/kotlin/org/rooftop/netx/client/TransactionReceiveStorage.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
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
Oops, something went wrong.