>ac@sddlZddlZddlZddlmZddlmZddlmZejeZ dZ de fdYZ de fd YZ dS( iN(tbucket(t throttling(tstandardc Cstj}tjddd|j}tjddd|}t|}tjdtj }t d|d |d |d |d|}|j j j d |j|j j j d |j|S(Ntstarting_max_rateit start_timetmax_rateitclocktretry_event_adaptert rate_adjustort rate_clockert token_buckettthrottling_detectors before-sends needs-retry(RtClockRtCubicCalculatort current_timet TokenBuckett RateClockerRtThrottlingErrorDetectortRetryEventAdaptertClientRateLimitertmetateventstregisterton_sending_requestton_receiving_response(tclientRRR R R tlimiter((s:/usr/lib/fence-agents/bundled/botocore/retries/adaptive.pytregister_retry_handler s$        RcBs)eZdZdZdZdZRS(g@cCsI||_||_||_||_||_t|_tj|_ dS(N( t_rate_adjustort _rate_clockert _token_buckett_throttling_detectort_clocktFalset_enabledt threadingtLockt_lock(tselfRR R R R((s:/usr/lib/fence-agents/bundled/botocore/retries/adaptive.pyt__init__*s      cKs|jr|jjndS(N(R"Rtacquire(R&trequesttkwargs((s:/usr/lib/fence-agents/bundled/botocore/retries/adaptive.pyR4s c Ks|jj}|jj}|j|jj|sO|jj|}na|j sa|}nt ||j j }|jj ||}tjd|||j jt|_ t ||j||j _ WdQXdS(NsfThrottling response received, new send rate: %s measured rate: %s, token bucket capacity available: %s(RtrecordR RR%Rtis_throttling_errorRtsuccess_receivedR"tminRRterror_receivedtloggertdebugtavailable_capacitytTruet_MAX_RATE_ADJUST_SCALE(R&R*t measured_ratet timestamptnew_ratet rate_to_use((s:/usr/lib/fence-agents/bundled/botocore/retries/adaptive.pyR9s         (t__name__t __module__R4R'RR(((s:/usr/lib/fence-agents/bundled/botocore/retries/adaptive.pyR&s RcBsDeZdZdZdZeedZddZedZRS(s7Tracks the rate at which a client is sending a request.g?g?cCsb||_d|_||_tj|jj|_d|j|_d|_ t j |_ dS(Nii( R t_measured_ratet _smoothingtmathtfloorRt _last_buckett_TIME_BUCKET_RANGEt_time_bucket_scalet_countR#R$R%(R&Rt smoothingttime_bucket_range((s:/usr/lib/fence-agents/bundled/botocore/retries/adaptive.pyR'Vs    icCs|j|jj}tj||j|j}|j|7_||jkr|jt||j}||j |j d|j |_ d|_||_n|j SWdQXdS(Nii( R%R RR=R>RARBR?tfloatR<R;(R&tamountttRt current_rate((s:/usr/lib/fence-agents/bundled/botocore/retries/adaptive.pyR+`s     cCs|jS(N(R;(R&((s:/usr/lib/fence-agents/bundled/botocore/retries/adaptive.pyR5qs( R9R:t__doc__t_DEFAULT_SMOOTHINGR@R'R+tpropertyR5(((s:/usr/lib/fence-agents/bundled/botocore/retries/adaptive.pyROs (R=tloggingR#tbotocore.retriesRRRt getLoggerR9R0RtobjectRR(((s:/usr/lib/fence-agents/bundled/botocore/retries/adaptive.pyts    )