Skip to content

Instantly share code, notes, and snippets.

View djspiewak's full-sized avatar

Daniel Spiewak djspiewak

View GitHub Profile
[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

What follows are some of my (very) rough thoughts on what we can and should do with respect to CPS transformation in Scala at the language level. I'll try to start with some motivation behind my thinking, as well as some rambling observations on the nature of the problem space, but don't expect too much coherence here. :-)

The Problem

Async programming is hard.

Okay let's actually be more specific than that. High-performance I/O is hard. Signal multiplexing is a powerful technique for achieving high(er) performance I/O, particularly network I/O, but the tradeoff is that, in order to utilize it, the user-space programming model must allow for suspension and resumption of sequential continuations (often called "fibers" or "coroutines"). Achieving this type of programming model without significant tradeoffs in usability is what is exceptionally hard.

If that wasn't bad enough though, these problems are inextricably conflated with another set of problem spaces which are, themselves, very difficult. In

[error] java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
[error] at xsbt.DottydocRunner.run(DottydocRunner.java:65)
[error] at xsbt.ScaladocInterface.run(ScaladocInterface.java:11)
[error] at jdk.internal.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
[error] at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[error] at java.base/java.lang.reflect.Method.invoke(Method.java:566)
[error] at sbt.internal.inc.AnalyzingCompiler.invoke(AnalyzingCompiler.scala:329)
[error] at sbt.internal.inc.AnalyzingCompiler.doc(AnalyzingCompiler.scala:175)
[error] at sbt.internal.inc.AnalyzingCompiler.doc(AnalyzingCompiler.scala:133)
[error] at sbt.Doc$.$anonfun$scaladoc$1(Doc.scala:52)
/*
* Copyright 2020-2022 Typelevel
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software