Skip to content

Instantly share code, notes, and snippets.

@pacman899
pacman899 / FinchServer.scala
Last active July 15, 2020 16:33
using Twitter server with cats
object FinchServer {
def serve[F[_]](s: Service[Request, Response], config: RestServerConfig)(implicit F: Concurrent[F]): F[Unit] = {
F.cancelable { _ =>
val twitterServer: TwitterServer = new TwitterServer() {
val server: ListeningServer = Http.server
.withMaxRequestSize(config.maxRequestSize.megabytes)
.withAdmissionControl
.concurrencyLimit(
maxConcurrentRequests = config.maxConcurrentRequests,
maxWaiters = config.maxWaiters

Thread Pools

Thread pools on the JVM should usually be divided into the following three categories:

  1. CPU-bound
  2. Blocking IO
  3. Non-blocking IO polling

Each of these categories has a different optimal configuration and usage pattern.