Skip to content

Instantly share code, notes, and snippets.

View aludwiko's full-sized avatar

Andrzej Ludwikowski aludwiko

View GitHub Profile
Source(1 to 10)
 .via(nonLinearFlow)
 .withAttributes(ActorAttributes.supervisionStrategy(Supervision.resumingDecider))
 .runForeach(println)
val dangerousFlow = Flow[Int].map {
  case 5 => Failure(new RuntimeException(“BOOM!”))
  case x => Try(x)
}
val safeFlow = Flow[Int].map(Try(_))
val bcast = builder.add(Broadcast[Int](2))
val zip = builder.add(Zip[Try[Int], Try[Int]])
Source(1 to 10)
 .via(nonLinearFlow)
 .collect {
  case (Success(a), Success(b)) => (a, b)
 }
 .runForeach(println)
Source(1 to 10)
 .map(toKafkaRecord)
 .via(Producer.flow(producerSettings))
 .runForeach(i => println(s"${i.message.passThrough} sent to kafka"))
Source(1 to 10)
 .flatMapConcat { i =>
  Source.single(i)
  .map(toKafkaRecord)
  .via(Producer.flow(producerSettings))
 }
 .runForeach(i => println(s"${i.message.passThrough} sent to kafka"))
Source(1 to 10)
.map(_ / 0)
.runWith(Sink.ignore)
@aludwiko
aludwiko / DropWizardTest.scala
Last active January 30, 2018 15:16
Dropwizard Metrics
object DropWizardTest extends App {
val random = Random
val times =
//normal behavior
(1 to 100000).map(_ => random.nextInt(100)) ++
//standard peacks
(1 to 100).map(_ => 1000) ++
//very high peacks
(1 to 10).map(_ => 10000)
@aludwiko
aludwiko / results.txt
Created January 22, 2018 09:52
Dropwizzard Metrics results
-----------1
75: 75.000000
95: 95.000000
99: 98.000000
99.9: 1000.000000
max: 1000
-----------2
75: 75.000000
95: 94.000000
99: 98.000000
def printHdrHistogram(times: Seq[Int]) = {
val histogram = new Histogram(1000000, 0)
times.map(time => histogram.recordValue(time))
histogram.outputPercentileDistribution(System.out, 1, 1.0)
}
Value Percentile TotalCount 1/(1-Percentile)
0 0.000000000000 970 1.00
63 0.500000000000 64196 2.00
127 0.750000000000 100000 4.00
127 0.875000000000 100000 8.00
127 0.937500000000 100000 16.00
127 0.968750000000 100000 32.00
127 0.984375000000 100000 64.00
127 0.992187500000 100000 128.00
127 0.996093750000 100000 256.00