Sentinel Flow Control Component: Quick Start, Rules, Annotations, and Internal Mechanisms
This article introduces Alibaba Sentinel, an open‑source flow‑control framework for distributed services, covering Maven integration, dashboard setup, configuration of flow, degrade and hotspot rules, the @SentinelResource annotation, XCloud Sentinel starter usage, and a deep dive into its slot‑chain architecture and sliding‑window algorithm.
Sentinel is an open‑source traffic‑control component released by Alibaba in 2018, widely adopted by more than 80 enterprises to ensure microservice stability.
Quick start : Add the Maven dependency <dependency> <groupId>com.alibaba.csp</groupId> <artifactId>sentinel-core</artifactId> <version>1.8.0</version> </dependency> Run the dashboard with java -jar ./sentinel-dashboard-1.8.0.jar and access it at http://localhost:8080/#/dashboard/home . Configure the service in application.yml to point to the dashboard and expose management endpoints.
Flow‑control rules are defined per resource (default is the request path). Rules can limit QPS or thread count, be scoped to a specific caller, and support three control modes: direct, association, and chain. The effect can be fast‑fail, warm‑up, or queue‑waiting.
Degrade (circuit‑breaker) rules include slow‑request‑ratio, error‑ratio, and error‑count thresholds, each with configurable statistical windows and recovery behavior.
Hotspot rules allow different QPS limits based on parameter values, taking precedence over generic flow rules.
@SentinelResource annotation defines a resource name and optional block‑handler, fallback, defaultFallback, and exceptionsToIgnore settings, enabling fine‑grained control and custom error handling.
XCloud Sentinel integration uses the starter cn.xdf.xcloud:xcloud-starter-sentinel with YAML configuration for default URL block handling, flow rules, and degrade rules, and can be combined with Apollo for hot‑loading.
Sentinel internal principle : each resource creates an Entry linked to a slot chain. Slots such as NodeSelectorSlot , ClusterBuilderSlot , StatisticSlot , FlowSlot , DegradeSlot , etc., perform path collection, statistics, rate limiting, and circuit breaking. The chain is built in DefaultProcessorSlotChain and cached in a volatile map.
Sliding‑window algorithm used by Sentinel employs two 500 ms windows for per‑second limits and 60 one‑second windows for per‑minute limits, implemented with ArrayMetric . The window slides forward as time progresses, discarding expired buckets and updating counts.
Reference links: Sentinel official site, a CSDN article comparing Hystrix and Sentinel, and the XCloud Sentinel repository.
New Oriental Technology
Practical internet development experience, tech sharing, knowledge consolidation, and forward-thinking insights.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.