Class/Object

com.twitter.finagle.thriftmux

MethodBuilder

Related Docs: object MethodBuilder | package thriftmux

Permalink

class MethodBuilder extends BaseMethodBuilder[MethodBuilder]

MethodBuilder is a collection of APIs for client configuration at a higher level than the Finagle 6 APIs while improving upon the deprecated ClientBuilder. MethodBuilder provides:

All of these can be customized per method (or endpoint) while sharing a single underlying Finagle client. Concretely, a single service might offer both getOneTweet as well as deleteTweets, whilst each having wildly different characteristics. The get is idempotent and has a tight latency distribution while the delete is not idempotent and has a wide latency distribution. If users want different configurations, without MethodBuilder they must create separate Finagle clients for each grouping. While long-lived clients in Finagle are not expensive, they are not free. They create duplicate metrics and waste heap, file descriptors, and CPU.

Example

Given an example IDL:

exception AnException {
  1: i32 errorCode
}

service SomeService {
  i32 TheMethod(
    1: i32 input
  ) throws (
    1: AnException ex1,
  )
}

This gives you a Service that has timeouts and retries on AnException when the errorCode is 0:

import com.twitter.conversions.DurationOps._
import com.twitter.finagle.ThriftMux
import com.twitter.finagle.service.{ReqRep, ResponseClass}
import com.twitter.util.Throw

val client: ThriftMux.Client = ???
val svc: Service[TheMethod.Args, TheMethod.SuccessType] =
  client.methodBuilder("inet!example.com:5555")
    .withTimeoutPerRequest(50.milliseconds)
    .withTimeoutTotal(100.milliseconds)
    .withRetryForClassifier {
      case ReqRep(_, Throw(AnException(errCode))) if errCode == 0 =>
        ResponseClass.RetryableFailure
    }
    .newServiceIface("the_method")
    .theMethod

Timeouts

Defaults to using the StackClient's configuration.

An example of setting a per-request timeout of 50 milliseconds and a total timeout of 100 milliseconds:

import com.twitter.conversions.DurationOps._
import com.twitter.finagle.thriftmux.MethodBuilder

val builder: MethodBuilder = ???
builder
  .withTimeoutPerRequest(50.milliseconds)
  .withTimeoutTotal(100.milliseconds)

Retries

Retries are intended to help clients improve success rate by trying failed requests additional times. Care must be taken by developers to only retry when it is known to be safe to issue the request multiple times. This is because the client cannot always be sure what the backend service has done. An example of a request that is safe to retry would be a read-only request.

Defaults to using the client's ResponseClassifier to retry failures marked as retryable. See withRetryForClassifier for details.

An example of configuring classifiers for ChannelClosed and Timeout exceptions:

import com.twitter.finagle.service.ResponseClassifier._
import com.twitter.finagle.thriftmux.MethodBuilder

val builder: MethodBuilder = ???
builder
  .withRetryForClassifier(RetryOnChannelClosed.orElse(RetryOnTimeout))

A com.twitter.finagle.service.RetryBudget is used to prevent retries from overwhelming the backend service. The budget is shared across clients created from an initial MethodBuilder. As such, even if the retry rules deem the request retryable, it may not be retried if there is insufficient budget.

Finagle will automatically retry failures that are known to be safe to retry via com.twitter.finagle.service.RequeueFilter. This includes WriteExceptions and retryable nacks. As these should have already been retried, we avoid retrying them again by ignoring them at this layer.

Additional information regarding retries can be found in the user guide.

The classifier is also used to determine the logical success metrics of the method. Logical here means after any retries are run. For example should a request result in retryable failure on the first attempt, but succeed upon retry, this is exposed through metrics as a success. Logical success rate metrics are scoped to "clnt/your_client_label/method_name/logical" and get "success" and "requests" counters along with a "request_latency_ms" stat.

Unsuccessful requests are logged at com.twitter.logging.Level.DEBUG level. Further details, including the request and response, are available at TRACE level.

See also

The user guide.

com.twitter.finagle.ThriftMux.Client.methodBuilder to construct instances.

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

Instance Constructors

  1. new MethodBuilder(thriftMuxClient: ThriftMux.Client, mb: client.MethodBuilder[ThriftClientRequest, Array[Byte]])

    Permalink

Value Members

  1. final def !=(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  4. final def asInstanceOf[T0]: T0

    Permalink
    Definition Classes
    Any
  5. def clone(): AnyRef

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @HotSpotIntrinsicCandidate() @throws( ... )
  6. final def eq(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  7. def equals(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  8. final def getClass(): Class[_]

    Permalink
    Definition Classes
    AnyRef → Any
    Annotations
    @HotSpotIntrinsicCandidate()
  9. def hashCode(): Int

    Permalink
    Definition Classes
    AnyRef → Any
    Annotations
    @HotSpotIntrinsicCandidate()
  10. def idempotent(maxExtraLoad: Tunable[Double]): MethodBuilder

    Permalink

    <invalid inheritdoc annotation>

    <invalid inheritdoc annotation>

    This additionally causes Thrift Exceptions to be retried.

    Definition Classes
    MethodBuilder → BaseMethodBuilder
  11. def idempotent(maxExtraLoad: Double): MethodBuilder

    Permalink

    <invalid inheritdoc annotation>

    <invalid inheritdoc annotation>

    This additionally causes Thrift Exceptions to be retried.

    Definition Classes
    MethodBuilder → BaseMethodBuilder
  12. final def isInstanceOf[T0]: Boolean

    Permalink
    Definition Classes
    Any
  13. def label: String

    Permalink

    Configured client label.

    Configured client label. The label is used to assign a label to the underlying Thrift client. The label is used to display stats, etc.

    See also

    https://twitter.github.io/finagle/guide/Clients.html#clients

    com.twitter.finagle.Client

  14. final def ne(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  15. def nonIdempotent: MethodBuilder

    Permalink
    Definition Classes
    MethodBuilder → BaseMethodBuilder
  16. final def notify(): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @HotSpotIntrinsicCandidate()
  17. final def notifyAll(): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @HotSpotIntrinsicCandidate()
  18. def servicePerEndpoint[ServicePerEndpoint <: Filterable[ServicePerEndpoint]](implicit builder: ServicePerEndpointBuilder[ServicePerEndpoint]): ServicePerEndpoint

    Permalink

    Construct a ServicePerEndpoint to be used for the client.

  19. def servicePerEndpoint[ServicePerEndpoint <: Filterable[ServicePerEndpoint]](methodName: String)(implicit builder: ServicePerEndpointBuilder[ServicePerEndpoint]): ServicePerEndpoint

    Permalink

    Construct a ServicePerEndpoint to be used for the methodName function.

    Construct a ServicePerEndpoint to be used for the methodName function.

    methodName

    used for scoping metrics (e.g. "clnt/your_client_label/method_name").

  20. final def synchronized[T0](arg0: ⇒ T0): T0

    Permalink
    Definition Classes
    AnyRef
  21. def toString(): String

    Permalink
    Definition Classes
    AnyRef → Any
  22. final def wait(arg0: Long, arg1: Int): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  23. final def wait(arg0: Long): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  24. final def wait(): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  25. def withRetryDisabled: MethodBuilder

    Permalink
    Definition Classes
    MethodBuilder → BaseMethodBuilder
  26. def withRetryForClassifier(classifier: ResponseClassifier): MethodBuilder

    Permalink
    Definition Classes
    MethodBuilder → BaseMethodBuilder
  27. def withTimeoutPerRequest(howLong: Tunable[Duration]): MethodBuilder

    Permalink
    Definition Classes
    MethodBuilder → BaseMethodBuilder
  28. def withTimeoutPerRequest(howLong: Duration): MethodBuilder

    Permalink
    Definition Classes
    MethodBuilder → BaseMethodBuilder
  29. def withTimeoutTotal(howLong: Tunable[Duration]): MethodBuilder

    Permalink
    Definition Classes
    MethodBuilder → BaseMethodBuilder
  30. def withTimeoutTotal(howLong: Duration): MethodBuilder

    Permalink
    Definition Classes
    MethodBuilder → BaseMethodBuilder

Deprecated Value Members

  1. def finalize(): Unit

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @Deprecated @deprecated @throws( classOf[java.lang.Throwable] )
    Deprecated

    (Since version ) see corresponding Javadoc for more information.

  2. def newServiceIface[ServiceIface <: Filterable[ServiceIface]](methodName: String)(implicit builder: ServiceIfaceBuilder[ServiceIface]): ServiceIface

    Permalink

    Construct a ServiceIface to be used for the methodName function.

    Construct a ServiceIface to be used for the methodName function.

    methodName

    used for scoping metrics (e.g. "clnt/your_client_label/method_name").

    Annotations
    @deprecated
    Deprecated

    (Since version 2017-11-29) Use servicePerEndpoint

Inherited from AnyRef

Inherited from Any

Ungrouped