Thread pools on the JVM should usually be divided into the following three categories:
- CPU-bound
- Blocking IO
- Non-blocking IO polling
Each of these categories has a different optimal configuration and usage pattern.
Miles Sabin recently opened a pull request fixing the infamous SI-2712. First off, this is remarkable and, if merged, will make everyone's life enormously easier. This is a bug that a lot of people hit often without even realizing it, and they just assume that either they did something wrong or the compiler is broken in some weird way. It is especially common for users of scalaz or cats.
But that's not what I wanted to write about. What I want to write about is the exact semantics of Miles's fix, because it does impose some very specific assumptions about the way that type constructors work, and understanding those assumptions is the key to getting the most of it his fix.
For starters, here is the sort of thing that SI-2712 affects:
def foo[F[_], A](fa: F[A]): String = fa.toString| #!/bin/bash | |
| test -e ~/.coursier/cr || (mkdir -p ~/.coursier && wget -q -O ~/.coursier/cr https://git.io/vgvpD && chmod +x ~/.coursier/cr) | |
| CLASSPATH="$(~/.coursier/cr fetch -q -p \ | |
| \ | |
| com.typesafe.play:play-netty-server_2.11:2.5.0 \ | |
| com.typesafe.play:play_2.11:2.5.0 \ | |
| com.lihaoyi:ammonite-repl_2.11.7:0.5.2 \ | |
| \ | |
| )" java \ | |
| -Dplay.crypto.secret=foo.bar.baz \ |
| import com.ning.http.client._ | |
| import com.typesafe.scalalogging.StrictLogging | |
| import scodec.bits.ByteVector | |
| import scala.concurrent.duration._ | |
| import scalaz._ | |
| import scalaz.Scalaz._ | |
| import scalaz.concurrent.Task | |
| import scalaz.stream._ |
| import akka.stream.scaladsl.Flow | |
| import scala.concurrent.{ ExecutionContext, Future } | |
| import scalaz._ | |
| import scalaz.std.scalaFuture.futureInstance // IntelliJ lies | |
| /** | |
| * Flowz provides Akka Stream Flow like methods for monadic types. | |
| * | |
| * You can define the `M` type and the input type, and let the compiler infer the output |
| package controllers | |
| import java.util.Properties | |
| import com.typesafe.config.ConfigFactory | |
| import kafka.consumer.{Consumer, ConsumerConfig, ConsumerConnector, Whitelist} | |
| import kafka.serializer.StringDecoder | |
| import play.api.libs.iteratee.{Enumerator, Iteratee} | |
| import play.api.mvc.{Controller, WebSocket} |
| import scala.language.experimental.macros | |
| import scala.reflect.macros.whitebox | |
| class FreeMacros(val c: whitebox.Context) { | |
| import c.universe._ | |
| def smartName(name: String): String = ( | |
| name.toList match { | |
| case h :: t => h.toLower :: t | |
| case Nil => Nil |
| package nl.mdj.fpinscala | |
| import java.net.InetSocketAddress | |
| import java.nio.channels.AsynchronousChannelGroup | |
| import java.util.concurrent.atomic.AtomicInteger | |
| import scodec.bits.ByteVector | |
| import scala.annotation.tailrec | |
| import scalaz.netty.Netty |
| // This should work with Scala 2.10.4 & scalaz 7.1, core, effect and concurrent packages | |
| import scalaz.{ concurrent, Free, Functor, Monad, syntax } | |
| import concurrent.Task | |
| import Free.{freeMonad => _, _} | |
| import syntax.monad._ | |
| // Describe the set of actions - which are functors | |
| sealed trait RedisF[+A] { | |
| def map[B](fn: A => B): RedisF[B] |
| #cloud-config | |
| coreos: | |
| etcd: | |
| # generate a new token for each unique cluster from https://discovery.etcd.io/new | |
| discovery: https://discovery.etcd.io/<token> | |
| # multi-region deployments, multi-cloud deployments, and droplets without | |
| # private networking need to use $public_ipv4 | |
| addr: $private_ipv4:4001 | |
| peer-addr: $private_ipv4:7001 |