如何将InetResolver与用于Finagle HTTP Client的自定义线程池一起使用

时间:2018-12-04 19:10:21

标签: scala finagle twitter-finagle

我们有一些使用ClientBuilder逻辑创建Service实例的HTTP客户端。

详细了解herehere A few methods do not yet have one-to-one equivalents, such as ClientBuilder.retries and for these you should migrate to using MethodBuilder.之后,我们决定使用MethodBuilder逻辑创建Service。

使用方法生成器逻辑的代码大约为在Java中。

    Long connectionTimeoutMillis = ???
    Long reqTimeoutMillis = ???
    hostConnectionLimit: Long = ???
    label: String = ???
    val StatsReceiver: StatsReceiver = ???
    host = ???

    Http.Client client = Http.client()
                .withDecompression(true)
                .withHttpStats()
                .withStatsReceiver(new MetricsStatsReceiver())
                .withSessionQualifier().noFailFast()
                .withSessionQualifier().noFailureAccrual()
                .withDecompression(true)
                .withHttp2()
                .withAdmissionControl().noNackAdmissionControl()
                .withLabel(label)
                .withSession().acquisitionTimeout(Duration.fromTimeUnit(connectionTimeoutMillis, TimeUnit.MILLISECONDS))
                .withTransport().connectTimeout(Duration.fromTimeUnit(connectionTimeoutMillis, TimeUnit.MILLISECONDS))
                .withRequestTimeout(Duration.fromTimeUnit(reqTimeoutMillis, TimeUnit.MILLISECONDS))
                .withSessionPool().maxSize(hostConnectionLimit);
    Service<Request, Response> service = client.newService(host);

    Future<Response> resp = service.apply(req).within(Duration.apply(reqTimeoutMillis, TimeUnit.MILLISECONDS), finagleTimer);

升级到方法构建器逻辑后,服务器因故障here崩溃并被发现。

错误是-

    2019-04-09 08:50:43,948 ERROR [UnboundedFuturePool-256142] [Monitor.scala:247] VM error
    java.lang.OutOfMemoryError: unable to create new native thread
            at java.lang.Thread.start0(Native Method)
            at java.lang.Thread.start(Unknown Source)
            at java.util.concurrent.ThreadPoolExecutor.addWorker(Unknown Source)
            at java.util.concurrent.ThreadPoolExecutor.execute(Unknown Source)
            at java.util.concurrent.AbstractExecutorService.submit(Unknown Source)
            at com.twitter.util.ExecutorServiceFuturePool.apply(FuturePool.scala:156)
            at com.twitter.finagle.DnsResolver$$anonfun$apply$3.apply(InetResolver.scala:36)
            at com.twitter.finagle.DnsResolver$$anonfun$apply$3.apply(InetResolver.scala:35)
            at com.twitter.util.Future$$anonfun$flatMap$1.apply(Future.scala:1808)
            at com.twitter.util.Future$$anonfun$flatMap$1.apply(Future.scala:1807)
            at com.twitter.util.Promise$FutureTransformer.liftedTree1$1(Promise.scala:240)
            at com.twitter.util.Promise$FutureTransformer.k(Promise.scala:240)
            at com.twitter.util.Promise$Transformer.apply(Promise.scala:215)
            at com.twitter.util.Promise$WaitQueue.com$twitter$util$Promise$WaitQueue$$run(Promise.scala:91)
            at com.twitter.util.Promise$WaitQueue$$anon$4.run(Promise.scala:86)
            at com.twitter.concurrent.LocalScheduler$Activation.run(Scheduler.scala:198)
            at com.twitter.concurrent.LocalScheduler$Activation.submit(Scheduler.scala:157)
            at com.twitter.concurrent.LocalScheduler.submit(Scheduler.scala:274)
            at com.twitter.concurrent.Scheduler$.submit(Scheduler.scala:109)
            at com.twitter.util.Promise$WaitQueue.runInScheduler(Promise.scala:86)
            at com.twitter.util.Promise.updateIfEmpty(Promise.scala:778)
            at com.twitter.util.ExecutorServiceFuturePool$$anon$4.run(FuturePool.scala:140)
            at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
            at java.util.concurrent.FutureTask.run(Unknown Source)
            at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
            at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
            at java.lang.Thread.run(Unknown Source)

我不确定如何使用http客户端的客户线程池配置InetResolver,但没有成功。

任何人都可以提供想法,使用带有自定义线程池的InetResolver设置finagle http客户端。

我们正在使用的当前finagle版本-19.3.0

0 个答案:

没有答案