-
Notifications
You must be signed in to change notification settings - Fork 138
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/master' into subscription-stream…
…-control
- Loading branch information
Showing
16 changed files
with
619 additions
and
109 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
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
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 +1 @@ | ||
sbt.version=1.10.1 | ||
sbt.version=1.10.2 |
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
73 changes: 73 additions & 0 deletions
73
zio-kafka-bench/src/main/scala/zio/kafka/bench/ProducerBenchmark.scala
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 |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package zio.kafka.bench | ||
|
||
import io.github.embeddedkafka.EmbeddedKafka | ||
import org.apache.kafka.clients.producer.ProducerRecord | ||
import org.openjdk.jmh.annotations._ | ||
import zio.kafka.producer.Producer | ||
import zio.kafka.serde.Serde | ||
import zio.kafka.testkit.Kafka | ||
import zio.kafka.testkit.KafkaTestUtils.producer | ||
import zio.stream.ZStream | ||
import zio.{ Chunk, ZIO, ZLayer } | ||
|
||
import java.util.concurrent.TimeUnit | ||
|
||
@State(Scope.Benchmark) | ||
@OutputTimeUnit(TimeUnit.MILLISECONDS) | ||
class ProducerBenchmark extends ZioBenchmark[Kafka with Producer] { | ||
val topic1 = "topic1" | ||
val nrPartitions = 6 | ||
val nrMessages = 500 | ||
val kvs: List[(String, String)] = List.tabulate(nrMessages)(i => (s"key$i", s"msg$i")) | ||
val records: Chunk[ProducerRecord[String, String]] = Chunk.fromIterable(kvs.map { case (k, v) => | ||
new ProducerRecord(topic1, k, v) | ||
}) | ||
|
||
override protected def bootstrap: ZLayer[Any, Nothing, Kafka with Producer] = | ||
ZLayer.make[Kafka with Producer](Kafka.embedded, producer).orDie | ||
|
||
override def initialize: ZIO[Kafka with Producer, Throwable, Any] = for { | ||
_ <- ZIO.succeed(EmbeddedKafka.deleteTopics(List(topic1))).ignore | ||
_ <- ZIO.succeed(EmbeddedKafka.createCustomTopic(topic1, partitions = nrPartitions)) | ||
} yield () | ||
|
||
@Benchmark | ||
@BenchmarkMode(Array(Mode.AverageTime)) | ||
def produceChunkSeq(): Any = runZIO { | ||
// Produce 30 chunks sequentially | ||
Producer.produceChunk(records, Serde.string, Serde.string).repeatN(29) | ||
} | ||
|
||
@Benchmark | ||
@BenchmarkMode(Array(Mode.AverageTime)) | ||
def produceChunkPar(): Any = runZIO { | ||
// Produce 30 chunks of which 4 run in parallel | ||
ZStream | ||
.range(0, 30, 1) | ||
.mapZIOParUnordered(4) { _ => | ||
Producer.produceChunk(records, Serde.string, Serde.string) | ||
} | ||
.runDrain | ||
} | ||
|
||
@Benchmark | ||
@BenchmarkMode(Array(Mode.Throughput)) | ||
@OutputTimeUnit(TimeUnit.SECONDS) | ||
def produceSingleRecordSeq(): Any = runZIO { | ||
// Produce 50 records sequentially | ||
Producer.produce(topic1, "key", "value", Serde.string, Serde.string).repeatN(99) | ||
} | ||
|
||
@Benchmark | ||
@BenchmarkMode(Array(Mode.Throughput)) | ||
@OutputTimeUnit(TimeUnit.SECONDS) | ||
def produceSingleRecordPar(): Any = runZIO { | ||
// Produce 100 records of which 4 run in parallel | ||
ZStream | ||
.range(0, 100, 1) | ||
.mapZIOParUnordered(4) { _ => | ||
Producer.produce(topic1, "key", "value", Serde.string, Serde.string) | ||
} | ||
.runDrain | ||
} | ||
} |
Oops, something went wrong.