Sentinel Parameter Flow Control provides functionality of flow control by frequent (hot spot) parameters.
—
Advanced functionality for distributed parameter flow control across multiple instances. ParamFlowClusterConfig enables coordinated parameter limits in cluster environments, allowing flow control decisions to be made globally across all service instances.
Configures parameter flow rules for cluster mode operation with distributed coordination.
/**
* Parameter flow rule config in cluster mode
*/
public class ParamFlowClusterConfig {
public ParamFlowClusterConfig();
}Usage Example:
// Create cluster configuration for distributed parameter flow control
ParamFlowClusterConfig clusterConfig = new ParamFlowClusterConfig()
.setFlowId(12345L)
.setThresholdType(ClusterRuleConstant.FLOW_THRESHOLD_GLOBAL)
.setFallbackToLocalWhenFail(true);
// Apply to parameter flow rule
ParamFlowRule rule = new ParamFlowRule("userService")
.setParamIdx(0)
.setCount(100) // 100 QPS across entire cluster
.setClusterMode(true)
.setClusterConfig(clusterConfig);Sets a global unique identifier for the parameter flow rule in cluster mode.
/**
* Set global unique ID for cluster flow control
* @param flowId global unique identifier
* @return this config for method chaining
*/
public ParamFlowClusterConfig setFlowId(Long flowId);
/**
* Get the global unique ID
* @return flow ID
*/
public Long getFlowId();Usage Example:
// Configure unique flow ID for cluster coordination
ParamFlowClusterConfig config = new ParamFlowClusterConfig()
.setFlowId(1001L); // Unique ID across all cluster instances
// Different services can use different flow IDs
ParamFlowClusterConfig userServiceConfig = new ParamFlowClusterConfig()
.setFlowId(2001L);
ParamFlowClusterConfig productServiceConfig = new ParamFlowClusterConfig()
.setFlowId(2002L);Specifies how the threshold should be calculated across cluster instances.
/**
* Set threshold type (average by local value or global value)
* @param thresholdType the threshold calculation type
* @return this config for method chaining
*/
public ParamFlowClusterConfig setThresholdType(int thresholdType);
/**
* Get the threshold type
* @return threshold type
*/
public int getThresholdType();Usage Example:
import com.alibaba.csp.sentinel.slots.block.ClusterRuleConstant;
// Global threshold - 100 QPS across entire cluster
ParamFlowClusterConfig globalConfig = new ParamFlowClusterConfig()
.setFlowId(1001L)
.setThresholdType(ClusterRuleConstant.FLOW_THRESHOLD_GLOBAL);
// Average local threshold - 100 QPS per instance on average
ParamFlowClusterConfig avgLocalConfig = new ParamFlowClusterConfig()
.setFlowId(1002L)
.setThresholdType(ClusterRuleConstant.FLOW_THRESHOLD_AVG_LOCAL);
// Example: If you have 4 instances
// Global: Total 100 QPS shared across all 4 instances
// Average Local: Each instance can handle ~25 QPS (100/4)Configures fallback behavior when cluster coordination fails.
/**
* Set fallback behavior when cluster coordination fails
* @param fallbackToLocalWhenFail true to fallback to local rules
* @return this config for method chaining
*/
public ParamFlowClusterConfig setFallbackToLocalWhenFail(boolean fallbackToLocalWhenFail);
/**
* Check if fallback to local is enabled
* @return true if fallback is enabled
*/
public boolean isFallbackToLocalWhenFail();Usage Example:
// Enable fallback to local rules when cluster fails
ParamFlowClusterConfig resilientConfig = new ParamFlowClusterConfig()
.setFlowId(1001L)
.setFallbackToLocalWhenFail(true); // Fallback to local mode
// Disable fallback - pass all requests when cluster fails
ParamFlowClusterConfig strictConfig = new ParamFlowClusterConfig()
.setFlowId(1002L)
.setFallbackToLocalWhenFail(false); // Pass all when cluster unavailable
// Apply to rules
ParamFlowRule resilientRule = new ParamFlowRule("criticalService")
.setCount(50)
.setClusterMode(true)
.setClusterConfig(resilientConfig);Configures statistical sampling for cluster coordination performance.
/**
* Set sample count for cluster statistics
* @param sampleCount number of samples
* @return this config for method chaining
*/
public ParamFlowClusterConfig setSampleCount(int sampleCount);
/**
* Get the sample count
* @return sample count
*/
public int getSampleCount();Usage Example:
// Configure sampling for high-performance cluster coordination
ParamFlowClusterConfig config = new ParamFlowClusterConfig()
.setFlowId(1001L)
.setSampleCount(10); // Use 10 samples for statistics
// Higher sample count for more accurate statistics
ParamFlowClusterConfig preciseConfig = new ParamFlowClusterConfig()
.setFlowId(1002L)
.setSampleCount(20); // More samples, higher accuracy, more overheadSets the time interval for statistical sliding windows in cluster mode.
/**
* Set the time interval length of the statistic sliding window (in milliseconds)
* @param windowIntervalMs window interval in milliseconds
* @return this config for method chaining
*/
public ParamFlowClusterConfig setWindowIntervalMs(int windowIntervalMs);
/**
* Get the window interval
* @return window interval in milliseconds
*/
public int getWindowIntervalMs();Usage Example:
// Configure sliding window for cluster statistics
ParamFlowClusterConfig config = new ParamFlowClusterConfig()
.setFlowId(1001L)
.setWindowIntervalMs(1000); // 1-second sliding window
// Shorter window for more responsive flow control
ParamFlowClusterConfig responsiveConfig = new ParamFlowClusterConfig()
.setFlowId(1002L)
.setWindowIntervalMs(500); // 500ms window, more responsive
// Longer window for smoother flow control
ParamFlowClusterConfig smoothConfig = new ParamFlowClusterConfig()
.setFlowId(1003L)
.setWindowIntervalMs(2000); // 2-second window, smootherimport com.alibaba.csp.sentinel.slots.block.flow.param.*;
import com.alibaba.csp.sentinel.slots.block.ClusterRuleConstant;
// Configure comprehensive cluster parameter flow control
ParamFlowClusterConfig clusterConfig = new ParamFlowClusterConfig()
.setFlowId(12345L) // Unique cluster flow ID
.setThresholdType(ClusterRuleConstant.FLOW_THRESHOLD_GLOBAL) // Global threshold across cluster
.setFallbackToLocalWhenFail(true) // Fallback to local when cluster fails
.setSampleCount(10) // Use 10 samples for statistics
.setWindowIntervalMs(1000); // 1-second sliding window
// Create parameter flow rule with cluster configuration
ParamFlowRule clusterRule = new ParamFlowRule("userService")
.setParamIdx(0) // Monitor first parameter (userId)
.setCount(200) // 200 QPS across entire cluster
.setGrade(RuleConstant.FLOW_GRADE_QPS)
.setClusterMode(true) // Enable cluster mode
.setClusterConfig(clusterConfig); // Apply cluster configuration
// Exception items work in cluster mode too
ParamFlowItem vipException = ParamFlowItem.newItem("VIP_USER", 500);
clusterRule.setParamFlowItemList(Arrays.asList(vipException));
// Load the cluster rule
ParamFlowRuleManager.loadRules(Arrays.asList(clusterRule));| Aspect | Local Mode | Cluster Mode |
|---|---|---|
| Scope | Per instance | Global across cluster |
| Coordination | None | Centralized token server |
| Consistency | Instance-level | Cluster-level |
| Latency | Low | Higher (network calls) |
| Availability | High | Depends on cluster server |
| Use Case | Simple deployments | Distributed systems |
Install with Tessl CLI
npx tessl i tessl/maven-sentinel-parameter-flow-control