Class: Google::Cloud::Debugger::RequestQuotaManager
- Inherits:
 - 
      Object
      
        
- Object
 - Google::Cloud::Debugger::RequestQuotaManager
 
 
- Defined in:
 - lib/google/cloud/debugger/request_quota_manager.rb
 
Overview
RequestQuotaManager
Tracking object used by debugger agent to manage quota in request-based applications. This class tracks the amount of time and number of breakpoints to evaluation in a single session.
The debugger agent doesn't have use a quota manager by default, which means it will evaluate all breakpoints encountered and takes as much time as needed. This class is utilized by Middleware class to limit latency overhead when used in Rack-based applications.
Constant Summary collapse
- DEFAULT_TIME_QUOTA =
          
Default Total time allowed to consume, in seconds
 0.05- DEFAULT_COUNT_QUOTA =
          
Default max number of breakpoints to evaluate
 10
Instance Attribute Summary collapse
- 
  
    
      #count_quota  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    
The count quota for this manager.
 - 
  
    
      #count_used  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    
The count quota used.
 - 
  
    
      #time_quota  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    
The time quota for this manager.
 - 
  
    
      #time_used  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    
The time quota used.
 
Instance Method Summary collapse
- 
  
    
      #consume(time: 0)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
Notify the quota manager some resource has been consumed.
 - 
  
    
      #initialize(time_quota: DEFAULT_TIME_QUOTA, count_quota: DEFAULT_COUNT_QUOTA)  ⇒ RequestQuotaManager 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    
Construct a new RequestQuotaManager instance.
 - 
  
    
      #more?  ⇒ Boolean 
    
    
  
  
  
  
  
  
  
  
  
    
Check if there's more quota left.
 - 
  
    
      #reset  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
Reset all the quota usage.
 
Constructor Details
#initialize(time_quota: DEFAULT_TIME_QUOTA, count_quota: DEFAULT_COUNT_QUOTA) ⇒ RequestQuotaManager
Construct a new RequestQuotaManager instance
      60 61 62 63 64 65 66  | 
    
      # File 'lib/google/cloud/debugger/request_quota_manager.rb', line 60 def initialize time_quota: DEFAULT_TIME_QUOTA, count_quota: DEFAULT_COUNT_QUOTA @time_quota = time_quota @time_used = 0 @count_quota = count_quota @count_used = 0 end  | 
  
Instance Attribute Details
#count_quota ⇒ Object
The count quota for this manager
      45 46 47  | 
    
      # File 'lib/google/cloud/debugger/request_quota_manager.rb', line 45 def count_quota @count_quota end  | 
  
#count_used ⇒ Object
The count quota used
      53 54 55  | 
    
      # File 'lib/google/cloud/debugger/request_quota_manager.rb', line 53 def count_used @count_used end  | 
  
#time_quota ⇒ Object
The time quota for this manager
      41 42 43  | 
    
      # File 'lib/google/cloud/debugger/request_quota_manager.rb', line 41 def time_quota @time_quota end  | 
  
#time_used ⇒ Object
The time quota used
      49 50 51  | 
    
      # File 'lib/google/cloud/debugger/request_quota_manager.rb', line 49 def time_used @time_used end  | 
  
Instance Method Details
#consume(time: 0) ⇒ Object
Notify the quota manager some resource has been consumed. Each time called increases the count quota usage.
      88 89 90 91  | 
    
      # File 'lib/google/cloud/debugger/request_quota_manager.rb', line 88 def consume time: 0 @time_used += time @count_used += 1 end  | 
  
#more? ⇒ Boolean
Check if there's more quota left.
      72 73 74  | 
    
      # File 'lib/google/cloud/debugger/request_quota_manager.rb', line 72 def more? (time_used < time_quota) && (count_used < count_quota) end  | 
  
#reset ⇒ Object
Reset all the quota usage.
      78 79 80 81  | 
    
      # File 'lib/google/cloud/debugger/request_quota_manager.rb', line 78 def reset @time_used = 0 @count_used = 0 end  |