Understanding the Initial Access Count for SDS Exception Rate Limiting
The initial access count (exceptionRateStart) in Didi’s SDS (Service Degradation System) serves as a statistical volume threshold that prevents exception-rate downgrade decisions until a minimum number of requests has been observed, safeguarding against noisy or premature degradations caused by statistically insignificant sample sizes.
The didi/sds repository implements sophisticated circuit-breaking and degradation logic for high-traffic distributed systems. Within its exception-rate limiting mechanism, the initial access count plays a critical role in ensuring that downgrade triggers only activate once sufficient traffic volume guarantees statistical reliability.
How the Initial Access Count Guards Against Noisy Degradation
The exceptionRateStart field in SdsStrategy defines the minimum request volume required before the system evaluates exception rates. According to the source code in ExceptionRateStrategyExecutor.java, the executor performs an early-return check that bypasses exception-rate calculations when the visit count remains below this threshold.
if (strategy.getExceptionRateStart() == null || strategy.getExceptionRateStart() < 0 ||
strategy.getExceptionRateThreshold() == null || strategy.getExceptionRateThreshold() < 0 ||
strategy.getExceptionRateThreshold() > 100 ||
strategy.getExceptionRateStart() >= checkData.getVisitCount()) {
// Not enough traffic – skip exception‑rate check
return true;
}
When strategy.getExceptionRateStart() >= checkData.getVisitCount() evaluates to true, the method returns true, indicating that the check passed and no downgrade occurs, even if the actual exception rate would otherwise exceed the threshold. This prevents scenarios where a single failure in ten requests (10% exception rate) triggers unnecessary degradation.
Configuring the Initial Access Count
You can configure this safeguard via JSON configuration, programmatic API, or the SDS admin interface.
JSON Strategy Configuration
Define the threshold in your strategy definition:
{
"point": "orderCreate",
"exceptionRateThreshold": 15,
"exceptionRateStart": 1000
}
This configuration ensures that SDS calculates exception rates only after collecting data from 1,000 requests, and triggers degradation only when the exception rate exceeds 15%.
Programmatic Configuration
Instantiate and register the strategy directly in Java:
SdsStrategy strategy = new SdsStrategy();
strategy.setPoint("orderCreate");
strategy.setExceptionRateThreshold(15); // 15 %
strategy.setExceptionRateStart(1000L); // require 1 000 requests first
SdsClient.getInstance().registerStrategy(strategy);
Runtime Execution Flow
During request processing, SDS collects visit statistics in CheckData. The executor compares the current visitCount against exceptionRateStart:
CheckData data = SdsClient.getInstance().getCheckData("orderCreate");
// If total visits < exceptionRateStart, the executor short‑circuits:
if (strategy.getExceptionRateStart() >= data.getVisitCount()) {
// No exception‑rate downgrade, even if a few exceptions occurred
return;
}
Key Source Files and Components
The initial access count mechanism spans multiple components across the SDS client and admin modules:
SdsStrategy.java(sds-client/src/main/java/com/didiglobal/sds/client/bean/SdsStrategy.java): Defines theexceptionRateStartfield and other strategy parameters.ExceptionRateStrategyExecutor.java(sds-client/src/main/java/com/didiglobal/sds/client/strategy/executor/ExceptionRateStrategyExecutor.java): Implements the volume threshold validation and short-circuit logic.PointStrategyDO.java(sds-admin/src/main/java/com/didiglobal/sds/admin/dao/bean/PointStrategyDO.java): Persists theexceptionRateStartvalue in the administrative database.PointStrategyRequest.java(sds-admin/src/main/java/com/didiglobal/sds/admin/controller/request/PointStrategyRequest.java): Receives the threshold configuration from admin UI requests.
Summary
- The initial access count (
exceptionRateStart) prevents premature exception-rate limiting by requiring a minimum sample size before evaluation. - When visit counts fall below this threshold,
ExceptionRateStrategyExecutorautomatically returnstrue, allowing requests to proceed without downgrade checks. - Configuration supports both declarative JSON/YAML definitions and programmatic Java APIs.
- This safeguard ensures statistically significant data before triggering service degradation decisions in high-traffic environments.
Frequently Asked Questions
What happens if the visit count is below the initial access threshold?
When checkData.getVisitCount() is less than exceptionRateStart, the ExceptionRateStrategyExecutor returns true immediately, treating the check as passed. This means the request proceeds normally without exception-rate downgrade evaluation, regardless of the current error rate.
How does exceptionRateStart differ from exceptionRateThreshold?
exceptionRateStart defines the minimum number of requests required before calculating exception rates (statistical volume), while exceptionRateThreshold specifies the percentage of failed requests (0-100) that triggers degradation once sufficient volume exists.
Where is the initial access count validated in the SDS codebase?
The validation logic resides in ExceptionRateStrategyExecutor.java within the sds-client module. This executor compares the strategy's exceptionRateStart value against the runtime visitCount from CheckData before performing any exception-rate calculations.
Can the initial access count be set to zero to disable the safeguard?
Yes, setting exceptionRateStart to 0 or null effectively disables the volume threshold, causing SDS to evaluate exception rates immediately. However, this risks noisy degradation decisions during low-traffic periods or service startup phases.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →