このページのトピック
APIレートの上限
APIエンドポイントにAPIレート制限が設定されているため、Workload Securityのパフォーマンスが低下するAPI呼び出し数が大幅に増加します。
APIコール率は、過去60秒以内にWorkload Securityが受信したAPI呼び出しの数として測定されます。レート制限を超えた場合、コールレートがすべてのレート制限を下回るまでマネージャは要求を処理しません。
呼び出しが行われ、APIレートの上限を超えた場合、応答コードは 429
で、メッセージ Too many API requests
が表示されます。
コード内のハンドル率制限エラー
APIメソッドまたはAPI関数の実行時に、環境内でAPIレートの上限を超えた場合、そのメソッドまたは関数は、メッセージ Too many API calls
とともに ApiException
をスローします。このメッセージの除外をテストし、catchされた場合は一定の時間待機してから再度スクリプトを実行するロジックをコードに含めてください。
あなたは一貫してレート制限を超えた場合は、サポートに問い合わせる。
レート上限を超えている間に行われた通話は、APIレートの計測にカウントされません。
SDKの APIUsageAPI
クラスを使用して、コールレートを決定できます。(APIレファレンス/参照情報の APIの使用法 を参照してください)。 たとえば、特定の期間に発生したすべてのAPI呼び出しを検索できます。返されたデータを解析して、合計呼び出し数をカウントします。コード429の応答数も確認できます。( Date-range searchesを参照してください。)
次の例では、APIの割合の上限を超えた場合に発生する除外またはエラーを検出します。捕捉された場合、指数バックオフアルゴリズムは、コールが再試行されるまでの遅延を計算します。リトライ回数は最大数に制限されます。
while True:
# Create a computer object and set the policy ID
computer = api.Computer()
computer.policy_id = policy_id
try:
# Modify the computer on Workload Security and store the ID of the returned computer
computer = computers_api.modify_computer(computer_ids[change_count], computer, api_version, overrides=False)
modified_computer_ids.append(computer.id)
retries = 0
# Increment the count and return if all computers are modified
change_count += 1
if change_count == len(computer_ids):
return modified_computer_ids
except api_exception as e:
if e.status == 429 and retries < MAX_RETRIES:
# The error is due to exceeding an API rate limit
retries += 1
# Calculate sleep time
exp_backoff = (2 ** (retries +3)) / 1000
print("API rate limit is exceeded. Retry in {} s.".format(exp_backoff))
time.sleep(exp_backoff)
else:
# Return all other exception causes or when max retries is exceeded
return "Exception: " + str(e)