Class: Google::Apis::ServiceuserV1::Quota

Inherits:
Object
  • Object
show all
Includes:
Core::Hashable, Core::JsonObjectSupport
Defined in:
generated/google/apis/serviceuser_v1/classes.rb,
generated/google/apis/serviceuser_v1/representations.rb,
generated/google/apis/serviceuser_v1/representations.rb

Overview

Quota configuration helps to achieve fairness and budgeting in service usage.

  • Fairness is achieved through the use of short-term quota limits that are usually defined over a time window of several seconds or minutes. When such a limit is applied, for example at the user level, it ensures that no single user will monopolize the service or a given customer's allocated portion of it.
  • Budgeting is achieved through the use of long-term quota limits that are usually defined over a time window of one or more days. These limits help client application developers predict the usage and help budgeting. Quota enforcement uses a simple token-based algorithm for resource sharing. The quota configuration structure is as follows:
  • QuotaLimit defines a single enforceable limit with a specified token amount that can be consumed over a specific duration and applies to a particular entity, like a project or an end user. If the limit applies to a user, each user making the request will get the specified number of tokens to consume. When the tokens run out, the requests from that user will be blocked until the duration elapses and the next duration window starts.
  • QuotaGroup groups a set of quota limits.
  • QuotaRule maps a method to a set of quota groups. This allows sharing of quota groups across methods as well as one method consuming tokens from more than one quota group. When a group contains multiple limits, requests to a method consuming tokens from that group must satisfy all the limits in that group. Example: quota: groups:
  • name: ReadGroup description: Read requests limits:
  • name: ProjectQps default_limit: 10000 duration: 100s limit_by: CLIENT_PROJECT
  • name: UserQps default_limit: 200 duration: 100s limit_by: USER
  • name: WriteGroup description: Write requests limits:
  • name: ProjectQps default_limit: 1000 max_limit: 2000 duration: 100s limit_by: CLIENT_PROJECT
  • name: UserQps default_limit: 200 max_limit: 400 duration: 100s limit_by: USER rules:
  • selector: "*" groups:
  • group: ReadGroup
  • selector: google.calendar.Calendar.Update groups:
  • group: WriteGroup cost: 2
  • selector: google.calendar.Calendar.Delete groups:
  • group: WriteGroup Here, the configuration defines two quota groups: ReadGroup and WriteGroup, each defining its own per-second and per-second-per-user limits. Note that One Platform enforces per-second limits averaged over 100 second window. The rules map ReadGroup for all methods, except for Update and Delete. These two methods consume from WriteGroup, with Update method consuming at twice the rate as Delete method. Multiple quota groups can be specified for a method. The quota limits in all of those groups will be enforced. Example: quota: groups:
  • name: WriteGroup description: Write requests limits:
  • name: ProjectQps default_limit: 1000 max_limit: 1000 duration: 100s limit_by: CLIENT_PROJECT
  • name: UserQps default_limit: 200 max_limit: 400 duration: 100s limit_by: USER
  • name: StorageGroup description: Storage requests limits:
  • name: StorageQuota default_limit: 1000 duration: 0 limit_by: USER rules:
  • selector: google.calendar.Calendar.Create groups:
  • group: StorageGroup
  • group: WriteGroup
  • selector: google.calendar.Calendar.Delete groups:
  • group: StorageGroup In the above example, the Create and Delete methods manage the user's storage space. In addition, Create method uses WriteGroup to manage the requests. In this case, requests to Create method need to satisfy all quota limits defined in both quota groups. One can disable quota for selected method(s) identified by the selector by setting disable_quota to true. For example, rules:
  • selector: "*" group:
  • group ReadGroup
  • selector: google.calendar.Calendar.Select disable_quota: true We are deprecating the group based quota configuration described above, and moving to use metric based quota configuration described below. The quota configuration works this way:
  • The service configuration defines a set of metrics.
  • For API calls, the quota.metric_rules maps methods to metrics with corresponding costs.
  • The quota.limits defines limits on the metrics, which will be used for quota checks at runtime. An example quota configuration in yaml format: quota: limits:
  • name: apiReadQpsPerProjectPerUser metric: library.googleapis.com/read_calls unit: "1/min/project/user" # per-user limit for consumer projects values: STANDARD: 1000
  • name: apiWriteQpsPerProject metric: library.googleapis.com/write_calls unit: "1/min/project" # rate limit for consumer projects values: STANDARD: 10000
  • name: borrowedCountPerOrganization metric: library.googleapis.com/borrowed_count is_precise: true unit: "1/organization" # allocation limit for organizations values: LOW: 200 STANDARD: 1000 HIGH: 10000
  • name: borrowedCountPerOrganizationPerRegion metric: library.googleapis.com/borrowed_count unit: "1/organization/region" is_precise: true values: LOW: 20 STANDARD: 200 HIGH: 2000 VERY_HIGH: 5000 LOW/us-central1: 50 STANDARD/us-central1: 500 HIGH/us-central1: 4000 VERY_HIGH/us-central1: 5000 # The metric rules bind all methods to the read_calls metric, # except for the UpdateBook and DeleteBook methods. These two methods # are mapped to the write_calls metric, with the UpdateBook method # consuming at twice rate as the DeleteBook method. metric_rules:
  • selector: "*" metric_costs: library.googleapis.com/read_calls: 1
  • selector: google.example.library.v1.LibraryService.UpdateBook metric_costs: library.googleapis.com/write_calls: 2
  • selector: google.example.library.v1.LibraryService.DeleteBook metric_costs: library.googleapis.com/write_calls: 1 Corresponding Metric definition: metrics:
  • name: library.googleapis.com/read_calls display_name: Read requests metric_kind: DELTA value_type: INT64
  • name: library.googleapis.com/write_calls display_name: Write requests metric_kind: DELTA value_type: INT64
  • name: library.googleapis.com/borrowed_count display_name: Borrowed books metric_kind: DELTA value_type: INT64

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Core::JsonObjectSupport

#to_json

Methods included from Core::Hashable

process_value, #to_h

Constructor Details

#initialize(**args) ⇒ Quota

Returns a new instance of Quota



2809
2810
2811
# File 'generated/google/apis/serviceuser_v1/classes.rb', line 2809

def initialize(**args)
   update!(**args)
end

Instance Attribute Details

#limitsArray<Google::Apis::ServiceuserV1::QuotaLimit>

List of QuotaLimit definitions for the service. Used by metric-based quotas only. Corresponds to the JSON property limits



2800
2801
2802
# File 'generated/google/apis/serviceuser_v1/classes.rb', line 2800

def limits
  @limits
end

#metric_rulesArray<Google::Apis::ServiceuserV1::MetricRule>

List of MetricRule definitions, each one mapping a selected method to one or more metrics. Used by metric-based quotas only. Corresponds to the JSON property metricRules



2807
2808
2809
# File 'generated/google/apis/serviceuser_v1/classes.rb', line 2807

def metric_rules
  @metric_rules
end

Instance Method Details

#update!(**args) ⇒ Object

Update properties of this object



2814
2815
2816
2817
# File 'generated/google/apis/serviceuser_v1/classes.rb', line 2814

def update!(**args)
  @limits = args[:limits] if args.key?(:limits)
  @metric_rules = args[:metric_rules] if args.key?(:metric_rules)
end