feat: Add flatMapConcat with parallelism support. (#1702)
This commit is contained in:
parent
eb5dc14fb0
commit
8ff1d82717
9 changed files with 730 additions and 1 deletions
|
|
@ -16,7 +16,7 @@ package org.apache.pekko.stream
|
|||
import java.util.concurrent.CountDownLatch
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
import scala.concurrent.Await
|
||||
import scala.concurrent.{ Await, Future }
|
||||
import scala.concurrent.duration._
|
||||
|
||||
import com.typesafe.config.ConfigFactory
|
||||
|
|
@ -76,6 +76,16 @@ class FlatMapConcatBenchmark {
|
|||
awaitLatch(latch)
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
@OperationsPerInvocation(OperationsPerInvocation)
|
||||
def sourceDotSingleP1(): Unit = {
|
||||
val latch = new CountDownLatch(1)
|
||||
|
||||
testSource.flatMapConcat(1, Source.single).runWith(new LatchSink(OperationsPerInvocation, latch))
|
||||
|
||||
awaitLatch(latch)
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
@OperationsPerInvocation(OperationsPerInvocation)
|
||||
def internalSingleSource(): Unit = {
|
||||
|
|
@ -88,6 +98,18 @@ class FlatMapConcatBenchmark {
|
|||
awaitLatch(latch)
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
@OperationsPerInvocation(OperationsPerInvocation)
|
||||
def internalSingleSourceP1(): Unit = {
|
||||
val latch = new CountDownLatch(1)
|
||||
|
||||
testSource
|
||||
.flatMapConcat(1, elem => new GraphStages.SingleSource(elem))
|
||||
.runWith(new LatchSink(OperationsPerInvocation, latch))
|
||||
|
||||
awaitLatch(latch)
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
@OperationsPerInvocation(OperationsPerInvocation)
|
||||
def oneElementList(): Unit = {
|
||||
|
|
@ -98,6 +120,64 @@ class FlatMapConcatBenchmark {
|
|||
awaitLatch(latch)
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
@OperationsPerInvocation(OperationsPerInvocation)
|
||||
def oneElementListP1(): Unit = {
|
||||
val latch = new CountDownLatch(1)
|
||||
|
||||
testSource.flatMapConcat(1, n => Source(n :: Nil)).runWith(new LatchSink(OperationsPerInvocation, latch))
|
||||
|
||||
awaitLatch(latch)
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
@OperationsPerInvocation(OperationsPerInvocation)
|
||||
def completedFuture(): Unit = {
|
||||
val latch = new CountDownLatch(1)
|
||||
|
||||
testSource
|
||||
.flatMapConcat(n => Source.future(Future.successful(n)))
|
||||
.runWith(new LatchSink(OperationsPerInvocation, latch))
|
||||
|
||||
awaitLatch(latch)
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
@OperationsPerInvocation(OperationsPerInvocation)
|
||||
def completedFutureP1(): Unit = {
|
||||
val latch = new CountDownLatch(1)
|
||||
|
||||
testSource
|
||||
.flatMapConcat(1, n => Source.future(Future.successful(n)))
|
||||
.runWith(new LatchSink(OperationsPerInvocation, latch))
|
||||
|
||||
awaitLatch(latch)
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
@OperationsPerInvocation(OperationsPerInvocation)
|
||||
def normalFuture(): Unit = {
|
||||
val latch = new CountDownLatch(1)
|
||||
|
||||
testSource
|
||||
.flatMapConcat(n => Source.future(Future(n)(system.dispatcher)))
|
||||
.runWith(new LatchSink(OperationsPerInvocation, latch))
|
||||
|
||||
awaitLatch(latch)
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
@OperationsPerInvocation(OperationsPerInvocation)
|
||||
def normalFutureP1(): Unit = {
|
||||
val latch = new CountDownLatch(1)
|
||||
|
||||
testSource
|
||||
.flatMapConcat(1, n => Source.future(Future(n)(system.dispatcher)))
|
||||
.runWith(new LatchSink(OperationsPerInvocation, latch))
|
||||
|
||||
awaitLatch(latch)
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
@OperationsPerInvocation(OperationsPerInvocation)
|
||||
def mapBaseline(): Unit = {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue