Skip to content

Instantly share code, notes, and snippets.

View djspiewak's full-sized avatar

Daniel Spiewak djspiewak

View GitHub Profile
/*
* There are two fundamental modes here: sequential and parallel. There is very little overlap
* in semantics between the two apart from the submission side. The whole thing is split up into
* a submission queue with impure enqueue and cancel functions which is drained by the `Worker` and an
* internal execution protocol which also involves a queue. The `Worker` encapsulates all of the
* race conditions and negotiations with impure code, while the `Executor` manages running the
* tasks with appropriate semantics. In parallel mode, we shard the `Worker`s according to the
* number of CPUs and select a random queue (in impure code) as a target. This reduces contention
* at the cost of ordering, which is not guaranteed in parallel mode. With sequential mode, there
* is only a single worker.
@State(Scope.Thread)
class FilesBenchmark {
private[this] var target: Path = _
@Setup
def setup() = {
val file = File.createTempFile("fs2-benchmarks-", "-walk")
file.delete()
file.mkdir()
[info] DispatcherSpec
[info] sequential dispatcher should
[info] await = true
[info] + reject new tasks while shutting down
[info] await = false
[info] + reject new tasks while shutting down
[info] parallel dispatcher should
[info] await = true
[info] + reject new tasks while shutting down
[info] await = false
[43/1037] shared[2.12.17].compile
[info] compiling 10 Scala sources and 1 Java source to /Users/daniel/Development/Scala/bloop/out/shared/2.12.17/compile.dest/classes ...
[info] done compiling
[77/1037] backend[2.12.17].compile
[info] compiling 58 Scala sources and 1 Java source to /Users/daniel/Development/Scala/bloop/out/backend/2.12.17/compile.dest/classes ...
[warn] one deprecation
[warn] one deprecation (since 3.0.0-RC2)
[warn] two deprecations in total; re-run with -deprecation for details
[warn] one feature warning; re-run with -feature for details
[warn] four warnings found
package sillio
import cats.syntax.all._
import scala.annotation.tailrec
import scala.concurrent.ExecutionContext
import scala.util.control.NonFatal
import java.util.concurrent.atomic.{AtomicBoolean, AtomicReference}
#!/usr/bin/env bash
echo '\documentclass{article}\begin{document}Lorem ipsum dolor sit amet\end{document}' > input.tex
pdflatex input
size=$(cat input.pdf | wc -c)
old_size=0
while [[ $old_size -lt $size ]]; do
echo '\documentclass{article}\begin{document}' > input.tex

Microservices Bench

This is intended to be a realistic benchmark for a typical production microservice. Each module builds to a Docker container which is intended to be deployed in an autoscaling cluster topology (usually Kubernetes) with mocked upstreams. All measurements are intended to be end-to-end using a scaled test harness like Gatling. In a meaningful sense, this is intended to be a more representative alternative to measurement frameworks such as TechEmpower.

Each module contains a fully independent, idiomatic, and independently-tuned implementation of the same service within a different ecosystem. Pull requests welcome! I'm not personally equally familiar with all of the different frameworks and languages represented within this repository, so if you see something that could be more optimal and/or idiomatic, please feel free to make the change! With that said, the goal is for all implementations to be roughly on the same level in terms

def raceSuccessAll[F[_], G[_], E, A](
fas: G[F[A]])(
implicit F: GenConcurrent[F, E],
G: Traverse[G])
: F[Either[Chain[E], A]] = {
val permits = fas.size.toInt
F uncancelable { poll =>
for {
def raceAll[F[_], E, A](fs: List[F[A]])(implicit F: GenConcurrent[F, E]): F[A] =
F.deferred[Outcome[F, E, A]] flatMap { d =>
F uncancelable { poll =>
val fibersF = fs traverse { fa =>
fa.guaranteeCase(d.complete(_).void).start
}
fibersF flatMap { fibers =>
poll(d.get.guarantee(fibers.parTraverse_(_.cancel)).flatMap(_.embedNever))
}

Integrated Runtime Strawman

We need to add an IORuntimeConfig parameter for a PollingSystem:

abstract class PollingSystem {
  protected[unsafe] def init(): PollingState
  protected[unsafe] def poll(state: PollingState, timeoutNanos: Long): Boolean
  protected[unsafe] def unpark(thread: Thread): Unit
  protected[unsafe] def close(state: PollingState): Unit