Packages

  • package root
    Definition Classes
    root
  • package com

    Start with com.twitter.finagle.

    Definition Classes
    root
  • package twitter

    Start with com.twitter.finagle.

    Definition Classes
    com
  • package finagle

    Finagle is an extensible RPC system.

    Finagle is an extensible RPC system.

    Services are represented by class com.twitter.finagle.Service. Clients make use of com.twitter.finagle.Service objects while servers implement them.

    Finagle contains a number of protocol implementations; each of these implement Client and/or com.twitter.finagle.Server. For example, Finagle's HTTP implementation, com.twitter.finagle.Http (in package finagle-http), exposes both.

    Thus a simple HTTP server is built like this:

    import com.twitter.finagle.{Http, Service}
    import com.twitter.finagle.http.{Request, Response}
    import com.twitter.util.{Await, Future}
    
    val service = new Service[Request, Response] {
      def apply(req: Request): Future[Response] =
        Future.value(Response())
    }
    val server = Http.server.serve(":8080", service)
    Await.ready(server)

    We first define a service to which requests are dispatched. In this case, the service returns immediately with a HTTP 200 OK response, and with no content.

    This service is then served via the Http protocol on TCP port 8080. Finally we wait for the server to stop serving.

    We can now query our web server:

    % curl -D - localhost:8080
    HTTP/1.1 200 OK

    Building an HTTP client is also simple. (Note that type annotations are added for illustration.)

    import com.twitter.finagle.{Http, Service}
    import com.twitter.finagle.http.{Request, Response}
    import com.twitter.util.{Future, Return, Throw}
    
    val client: Service[Request, Response] = Http.client.newService("localhost:8080")
    val f: Future[Response] = client(Request()).respond {
      case Return(rep) =>
        printf("Got HTTP response %s\n", rep)
      case Throw(exc) =>
        printf("Got error %s\n", exc)
    }

    Http.client.newService("localhost:8080") constructs a new com.twitter.finagle.Service instance connected to localhost TCP port 8080. We then issue a HTTP/1.1 GET request to URI "/". The service returns a com.twitter.util.Future representing the result of the operation. We listen to this future, printing an appropriate message when the response arrives.

    The Finagle homepage contains useful documentation and resources for using Finagle.

    Definition Classes
    twitter
  • package loadbalancer

    This package implements client side load balancing algorithms.

    This package implements client side load balancing algorithms.

    As an end-user, see the Balancers API to create instances which can be used to configure a Finagle client with various load balancing strategies.

    As an implementor, each algorithm gets its own subdirectory and is exposed via the Balancers object. Several convenient traits are provided which factor out common behavior and can be mixed in (i.e. Balancer, DistributorT, NodeT, and Updating).

    Definition Classes
    finagle
  • package exp
    Definition Classes
    loadbalancer
  • Balancers
  • DefaultBalancerFactory
  • LoadBalancerFactory
  • defaultBalancer
  • perHostStats

object Balancers

Constructor methods for various load balancers. The methods take balancer specific parameters and return a LoadBalancerFactory that allows you to easily inject a balancer into the Finagle stack via client configuration.

Example:
  1. configuring a client with a load balancer

    $Protocol.client
      .withLoadBalancer(Balancers.aperture())
      .newClient(...)
See also

The user guide for more details.

Linear Supertypes
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. Balancers
  2. AnyRef
  3. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  4. val MaxEffort: Int

    This is a fixed number of retries, a LB are willing to make if the dead node is returned from the underlying distributor.

    This is a fixed number of retries, a LB are willing to make if the dead node is returned from the underlying distributor.

    For randomized LBs (P2C/LeastLoaded, P2C/EWMA, and Aperture) this value has an additional meaning: it determines how often the LB will be failing to pick a healthy node out of the partially-unhealthy replica set. For example, imagine that half of the replica set is down, the probably of picking two dead nodes is 0.25. If we repeat that process for 5 times, the total probability of seeing 5 dead nodes in a row, will be (0.25 ^ 5) = 0.1%. This means that if half of the cluster is down, the LB will be making a bad choice (when better choice may have been available) for 0.1% of requests.

    Please, note that this doesn't mean that 0.1% of requests will be failed by P2C operating on a half-dead cluster since there is an additional layer of requeues (see Retries module) involved above those "bad picks".

  5. def aperture(smoothWin: Duration = 5.seconds, lowLoad: Double = 0.5, highLoad: Double = 2.0, minAperture: Int = 1, maxEffort: Int = MaxEffort, rng: Rng = Rng.threadLocal): LoadBalancerFactory

    The aperture load-band balancer balances load to the smallest subset ("aperture") of services so that:

    The aperture load-band balancer balances load to the smallest subset ("aperture") of services so that:

    1. The concurrent load, measured over a window specified by smoothWin, to each service stays within the load band, delimited by lowLoad and highLoad.

    2. Services receive load proportional to the ratio of their weights.

    Unavailable services are not counted--the aperture expands as needed to cover those that are available.

    See also

    The user guide for more details.

  6. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  7. def clone(): AnyRef
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  8. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  9. def equals(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  10. def finalize(): Unit
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  11. final def getClass(): Class[_]
    Definition Classes
    AnyRef → Any
  12. def hashCode(): Int
    Definition Classes
    AnyRef → Any
  13. def heap(rng: Random = new Random): LoadBalancerFactory

    An efficient strictly least-loaded balancer that maintains an internal heap to select least-loaded endpoints.

    An efficient strictly least-loaded balancer that maintains an internal heap to select least-loaded endpoints.

    See also

    The user guide for more details.

  14. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  15. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  16. final def notify(): Unit
    Definition Classes
    AnyRef
  17. final def notifyAll(): Unit
    Definition Classes
    AnyRef
  18. def p2c(maxEffort: Int = MaxEffort, rng: Rng = Rng.threadLocal): LoadBalancerFactory

    An O(1), concurrent, least-loaded fair load balancer.

    An O(1), concurrent, least-loaded fair load balancer. This uses the ideas behind "power of 2 choices" [1].

    maxEffort

    the maximum amount of "effort" we're willing to expend on a load balancing decision without reweighing.

    rng

    The PRNG used for flipping coins. Override for deterministic tests. [1] Michael Mitzenmacher. 2001. The Power of Two Choices in Randomized Load Balancing. IEEE Trans. Parallel Distrib. Syst. 12, 10 (October 2001), 1094-1104.

  19. def p2cPeakEwma(decayTime: Duration = 10.seconds, maxEffort: Int = MaxEffort, rng: Rng = Rng.threadLocal): LoadBalancerFactory

    Like p2c but using the Peak EWMA load metric.

    Like p2c but using the Peak EWMA load metric.

    Peak EWMA uses a moving average over an endpoint's round-trip time (RTT) that is highly sensitive to peaks. This average is then weighted by the number of outstanding requests, effectively increasing our resolution per-request. It is designed to react to slow endpoints more quickly than least-loaded by penalizing them when they exhibit slow response times. This load metric operates under the assumption that a loaded endpoint takes time to recover and so it is generally safe for the advertised load to incorporate an endpoint's history. However, this assumption breaks down in the presence of long polling clients.

    decayTime

    The window of latency observations.

    maxEffort

    the maximum amount of "effort" we're willing to expend on a load balancing decision without reweighing.

    rng

    The PRNG used for flipping coins. Override for deterministic tests.

    See also

    The user guide for more details.

  20. def roundRobin(maxEffort: Int = MaxEffort): LoadBalancerFactory

    A simple round robin balancer that chooses the next backend in the list for each request.

    A simple round robin balancer that chooses the next backend in the list for each request.

    WARNING: Unlike other balancers available in finagle, this does not take latency into account and will happily direct load to slow or oversubscribed services. We recommend using one of the other load balancers for typical production use.

    maxEffort

    the maximum amount of "effort" we're willing to expend on a load balancing decision without reweighing.

  21. final def synchronized[T0](arg0: ⇒ T0): T0
    Definition Classes
    AnyRef
  22. def toString(): String
    Definition Classes
    AnyRef → Any
  23. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  24. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  25. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )

Inherited from AnyRef

Inherited from Any

Ungrouped