Flaky tenant retry tuning
A tenant that returns intermittent 503s under peak load wants more retry attempts and
a wall-clock cap, so one bad request cannot pin the whole job. The retry knobs and the
wall-clock deadline are all flat SVIClient keyword arguments. A config=SVIConfig(...)
is the complete configuration: passing a flat keyword next to it raises
SVIConfigurationError, so put every setting in the config or none of them.
import sasvi
client = sasvi.SVIClient(
auth=auth,
config=sasvi.SVIConfig(
base_url="https://viya.example.com",
max_retries=6, # more attempts than the default 3
retry_backoff_seconds=0.5, # base; doubles each attempt
retry_statuses=frozenset({408, 429, 502, 503, 504}),
request_deadline_seconds=20.0, # whole-call budget
log_http=True,
log_slow_request_seconds=2.0, # log a WARNING above 2 s
),
)
Attempts back off exponentially, retry_backoff_seconds * 2 ** attempt, with jitter.
So max_retries=6 means 7 attempts and 6 sleeps of 0.5 s, 1 s, 2 s, 4 s, 8 s and
16 s: 31.5 s of backoff before jitter, and each sleep is then scaled by 0.5x to 1.5x.
request_deadline_seconds=20.0 bounds the whole call instead. Attempts are capped at
the budget left when they start, no retry begins after it, and the call raises
DeadlineExceededError.
Status set tuning
408 Request Timeout and 429 Too Many Requests are safe to retry on idempotent
methods, and the default retry_methods already excludes POST and PATCH.
500 Internal Server Error is in the default set. If your tenant returns 500 for
real validation failures, drop it so you fail fast:
client = sasvi.SVIClient(
base_url=base_url,
auth=auth,
retry_statuses=frozenset({408, 429, 502, 503, 504}), # no 500
)
Per-call opt-out
To bypass the retry policy for one call, swap clients:
no_retry = sasvi.SVIClient(
base_url=base_url,
auth=auth,
max_retries=0,
)
result = no_retry.alerts.get(alert_id=alert_id)
Catching the deadline
DeadlineExceededError is a TransientError, so one except covers both the
timeout and the retried failures underneath it:
from sasvi import errors
try:
client.documents.bulk_upsert(docs)
except errors.TransientError as exc:
log.error("Tenant timed out under retry: %s", exc)
Go further
- Performance guide. Connection pooling, deadlines, batching.
- Config API reference. The full
SVIConfigretry reference. - Troubleshooting. Symptom to cause for
TransientError.