scalatcpfinagletwitter-finagle

How to limit the connections number Finagle creates?


I use Finalge https://twitter.github.io/finagle/ to test the timeout case like this:

  1. Server side: in the RPC definition, Just sleep 10 secs and return.
  2. Client side: call RPC function using within like within(50.milliseconds) onSuccess { ... } onFailure { ... }
  3. Many clients: use about 100 clients to call the RPC function at the same time

The result is that all the RPCs are timeout of course. But, when I use netstat to check the connection I find that there are 100 ESTABLISHED connection. The question is can I limit the connections number Finagle create ?


Solution

  • Yes, you can use

    hostConnectionLimit(10)
    

    in your ClientBuilder to limit the connections to each host. "Host" here refers to the server side boxes.

    Source code here.