class_docstr: Dynamic token bucket
class_docstr_tok: ["Dynamic","token","bucket"]
code: def consume(self, take_amount: int, avg_rate: float, burst_size: int):
      now = time.time()
      inc = (now - self._last_consume_time) * avg_rate
      current_amount = min(inc + self._amount, burst_size)
      if take_amount > current_amount:
          return False
      self._amount, self._last_consume_time = (
          current_amount - take_amount,
          now,
      )
      return True
  
file_path: BentoML/grpc-client/bentoml/_internal/utils/alg.py
imports: from __future__ import annotations
  import time
  import typing
label_desc: Use image node_id 2 for calling the TokenBucket obj's underlying member method code with example usage: obj.consume(take_amount, avg_rate, burst_size) and returns: True, False