http4s - 如何创建线程数有限的 blaze 客户端?

can*_*asp 5 scala http4s

我试图用有限数量的线程创建 blaze 客户端,如下所示:

object ReactiveCats extends IOApp {
  private val PORT = 8083
  private val DELAY_SERVICE_URL = "http://localhost:8080"
  
  // trying create client with limited number of threads
  val clientPool: ExecutorService = Executors.newFixedThreadPool(64)
  val clientExecutor: ExecutionContextExecutor = ExecutionContext.fromExecutor(clientPool)

  private val httpClient = BlazeClientBuilder[IO](clientExecutor).resource

  private val httpApp = HttpRoutes.of[IO] {
    case GET -> Root / delayMillis =>
      httpClient.use { client =>
        client
          .expect[String](s"$DELAY_SERVICE_URL/$delayMillis")
          .flatMap(response => Ok(s"ReactiveCats: $response"))
      }
  }.orNotFound

  // trying to create server on fixed thread pool
  val serverPool: ExecutorService = Executors.newFixedThreadPool(64)
  val serverExecutor: ExecutionContextExecutor = ExecutionContext.fromExecutor(serverPool)

  // start server
  override def run(args: List[String]): IO[ExitCode] =
    BlazeServerBuilder[IO](serverExecutor)
      .bindHttp(port = PORT, host = "localhost")
      .withHttpApp(httpApp)
      .serve
      .compile
      .drain
      .as(ExitCode.Success)
}
Run Code Online (Sandbox Code Playgroud)

完整代码和负载测试  

但是负载测试结果看起来像一个请求一个线程: 在此处输入图片说明

我如何限制我的 blaze 客户端的线程数?

can*_*asp 1

复制我的评论。

性能问题的答案是为 Blaze 客户端正确设置的 - 对我来说这是 .withMaxWaitQueueLimit(1024) 参数。