Skip to content

Instantly share code, notes, and snippets.

View djspiewak's full-sized avatar

Daniel Spiewak djspiewak

View GitHub Profile
#!/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

Getting Started in Scala

This is my attempt to give Scala newcomers a quick-and-easy rundown to the prerequisite steps they need to a) try Scala, and b) get a standard project up and running on their machine. I'm not going to talk about the language at all; there are plenty of better resources a google search away. This is just focused on the prerequisite tooling and machine setup. I will not be assuming you have any background in JVM languages. So if you're coming from Python, Ruby, JavaScript, Haskell, or anywhere…  I hope to present the information you need without assuming anything.

Disclaimer It has been over a decade since I was new to Scala, and when I was new to Scala, I was coming from a Java and Ruby background. This has probably caused me to unknowingly make some assumptions. Please feel free to call me out in comments/tweets!

One assumption I'm knowingly making is that you're on a Unix-like platform. Sorry, Windows users.

Getting the JVM

[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
// sbt-git workarounds (TODO upstream into sbt-tl)
inThisBuild {
git.uncommittedSignifier := Some("-SNAPSHOT")
git.formattedShaVersion := {
val Description = """^.*-(\d+)-[a-zA-Z0-9]+$""".r
val suffix = git.makeUncommittedSignifierSuffix(git.gitUncommittedChanges.value, git.uncommittedSignifier.value)
val description = Try("git describe --tags --match v*".!!.trim).toOption
@djspiewak
djspiewak / Main.java
Created November 10, 2020 22:00 — forked from RaasAhsan/Main.java
minimized ARM memory barrier violation
import java.util.concurrent.atomic.*;
import java.util.concurrent.*;
public class Main {
private static ExecutorService executor = Executors.newFixedThreadPool(2);
private static int iterations = 10000000;
public static class Runner {
// writes to canceled happen before a CAS on suspended
// reads on canceled happen after a CAS on suspended