Class ThrottlingInvoker


  • public class ThrottlingInvoker
    extends Object
    Utility that implements a basic form of Additive Increase, Multiplicative Decrease for handling retries and backoff against a dependency that is experience congestion. For best results share one instance of this class across as many callers of the same shared resource. If you give each calling thread or entity its own instance the logic will still work but may take a bit longer (couple extra calls) to detect the congestion and converge. This utility works best when all callers use it, otherwise callers that do not use this logic will get a larger % of the available call capacity because the other callers will back off when they see congestion and get starved out by the greedy caller
    • Method Detail

      • newDefaultBuilder

        public static ThrottlingInvoker.Builder newDefaultBuilder​(ThrottlingInvoker.ExceptionFilter filter,
                                                                  Map<String,​String> configOptions)
        Produces a Builder with default values set allowing you to override only specific defaults.
        Parameters:
        filter - The exception filter to apply to any exception when attemtping to identify congestion.
        Returns:
        The new Builder with default values.
      • invoke

        public <T> T invoke​(Callable<T> callable)
                     throws TimeoutException
        Attempts to invoke the callable while applying our congestion control logic.
        Type Parameters:
        T - The return type of the Callable
        Parameters:
        callable - The callable to invoke.
        Returns:
        The value returned by the Callable.
        Throws:
        TimeoutException
      • invoke

        public <T> T invoke​(Callable<T> callable,
                            long timeoutMillis)
                     throws TimeoutException
        Attempts to invoke the callable while applying our congestion control logic.
        Type Parameters:
        T - The return type of the Callable
        Parameters:
        callable - The callable to invoke.
        timeoutMillis - The max number of milliseconds we should spend retrying if congestion prevents us from making a successful call.
        Returns:
        The value returned by the Callable, null if we exceeded the timeout.
        Throws:
        TimeoutException
      • setBlockSpiller

        public void setBlockSpiller​(BlockSpiller spiller)
        Throttling Invoker can decide to propogate the congestion events to Athena if your Lambda has not generated any data yet. To do this ThrottlingInvoker needs access to your BlockSpiller so that it can see if any data was spilled. Once data is spilled you can not longer throw FederationThrottleException to Athena or the query may fail in order to ensure consistency.
        Parameters:
        spiller - The BlockSpiller to monitor for spill events.