Miscellaneous update
Signed-off-by: Eric Zhao <sczyh16@gmail.com>
This commit is contained in:
parent
49097fa45c
commit
94aea568f6
|
|
@ -88,8 +88,8 @@ public class CtSph implements Sph {
|
||||||
ProcessorSlot<Object> chain = lookProcessChain(resourceWrapper);
|
ProcessorSlot<Object> chain = lookProcessChain(resourceWrapper);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Means processor size exceeds {@link Constants.MAX_ENTRY_SIZE}, no
|
* Means processor cache size exceeds {@link Constants.MAX_SLOT_CHAIN_SIZE}, so no
|
||||||
* rule checking will do.
|
* rule checking will be done.
|
||||||
*/
|
*/
|
||||||
if (chain == null) {
|
if (chain == null) {
|
||||||
return new CtEntry(resourceWrapper, null, context);
|
return new CtEntry(resourceWrapper, null, context);
|
||||||
|
|
@ -102,7 +102,7 @@ public class CtSph implements Sph {
|
||||||
e.exit(count, args);
|
e.exit(count, args);
|
||||||
throw e1;
|
throw e1;
|
||||||
} catch (Throwable e1) {
|
} catch (Throwable e1) {
|
||||||
RecordLog.info("sentinel unexpected exception", e1);
|
RecordLog.info("Sentinel unexpected exception", e1);
|
||||||
}
|
}
|
||||||
return e;
|
return e;
|
||||||
}
|
}
|
||||||
|
|
@ -134,8 +134,7 @@ public class CtSph implements Sph {
|
||||||
}
|
}
|
||||||
|
|
||||||
chain = Env.slotsChainbuilder.build();
|
chain = Env.slotsChainbuilder.build();
|
||||||
HashMap<ResourceWrapper, ProcessorSlotChain> newMap
|
Map<ResourceWrapper, ProcessorSlotChain> newMap = new HashMap<ResourceWrapper, ProcessorSlotChain>(
|
||||||
= new HashMap<ResourceWrapper, ProcessorSlotChain>(
|
|
||||||
chainMap.size() + 1);
|
chainMap.size() + 1);
|
||||||
newMap.putAll(chainMap);
|
newMap.putAll(chainMap);
|
||||||
newMap.put(resourceWrapper, chain);
|
newMap.put(resourceWrapper, chain);
|
||||||
|
|
|
||||||
|
|
@ -53,13 +53,23 @@ public class FlowRule extends AbstractRule {
|
||||||
*/
|
*/
|
||||||
private int grade = RuleConstant.FLOW_GRADE_QPS;
|
private int grade = RuleConstant.FLOW_GRADE_QPS;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Flow control threshold count.
|
||||||
|
*/
|
||||||
private double count;
|
private double count;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 0为直接限流;1为关联限流;2为链路限流
|
* Flow control strategy based on invocation chain.
|
||||||
|
*
|
||||||
|
* {@link RuleConstant#STRATEGY_DIRECT} for direct flow control (by origin);
|
||||||
|
* {@link RuleConstant#STRATEGY_RELATE} for relevant flow control (with relevant resource);
|
||||||
|
* {@link RuleConstant#STRATEGY_CHAIN} for chain flow control (by entrance resource).
|
||||||
*/
|
*/
|
||||||
private int strategy = RuleConstant.STRATEGY_DIRECT;
|
private int strategy = RuleConstant.STRATEGY_DIRECT;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reference resource in flow control with relevant resource.
|
||||||
|
*/
|
||||||
private String refResource;
|
private String refResource;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -86,9 +86,6 @@ public class FlowRuleManager {
|
||||||
*/
|
*/
|
||||||
public static List<FlowRule> getRules() {
|
public static List<FlowRule> getRules() {
|
||||||
List<FlowRule> rules = new ArrayList<FlowRule>();
|
List<FlowRule> rules = new ArrayList<FlowRule>();
|
||||||
if (flowRules == null) {
|
|
||||||
return rules;
|
|
||||||
}
|
|
||||||
for (Map.Entry<String, List<FlowRule>> entry : flowRules.entrySet()) {
|
for (Map.Entry<String, List<FlowRule>> entry : flowRules.entrySet()) {
|
||||||
rules.addAll(entry.getValue());
|
rules.addAll(entry.getValue());
|
||||||
}
|
}
|
||||||
|
|
@ -145,7 +142,6 @@ public class FlowRuleManager {
|
||||||
|
|
||||||
public static void checkFlow(ResourceWrapper resource, Context context, DefaultNode node, int count)
|
public static void checkFlow(ResourceWrapper resource, Context context, DefaultNode node, int count)
|
||||||
throws BlockException {
|
throws BlockException {
|
||||||
if (flowRules != null) {
|
|
||||||
List<FlowRule> rules = flowRules.get(resource.getName());
|
List<FlowRule> rules = flowRules.get(resource.getName());
|
||||||
if (rules != null) {
|
if (rules != null) {
|
||||||
for (FlowRule rule : rules) {
|
for (FlowRule rule : rules) {
|
||||||
|
|
@ -155,7 +151,6 @@ public class FlowRuleManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean hasConfig(String resource) {
|
public static boolean hasConfig(String resource) {
|
||||||
return flowRules.containsKey(resource);
|
return flowRules.containsKey(resource);
|
||||||
|
|
@ -166,7 +161,6 @@ public class FlowRuleManager {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (flowRules != null) {
|
|
||||||
List<FlowRule> rules = flowRules.get(resourceName);
|
List<FlowRule> rules = flowRules.get(resourceName);
|
||||||
|
|
||||||
if (rules != null) {
|
if (rules != null) {
|
||||||
|
|
@ -176,7 +170,6 @@ public class FlowRuleManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
@ -190,7 +183,7 @@ public class FlowRuleManager {
|
||||||
flowRules.clear();
|
flowRules.clear();
|
||||||
flowRules.putAll(rules);
|
flowRules.putAll(rules);
|
||||||
}
|
}
|
||||||
RecordLog.info("receive flow config: " + flowRules);
|
RecordLog.info("[FlowRuleManager] Flow rules received: " + flowRules);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -200,7 +193,7 @@ public class FlowRuleManager {
|
||||||
flowRules.clear();
|
flowRules.clear();
|
||||||
flowRules.putAll(rules);
|
flowRules.putAll(rules);
|
||||||
}
|
}
|
||||||
RecordLog.info("load flow config: " + flowRules);
|
RecordLog.info("[FlowRuleManager] Flow rules loaded: " + flowRules);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -128,7 +128,7 @@ public class NodeSelectorSlot extends AbstractLinkedProcessorSlot<Object> {
|
||||||
/**
|
/**
|
||||||
* {@link DefaultNode}s of the same resource in different context.
|
* {@link DefaultNode}s of the same resource in different context.
|
||||||
*/
|
*/
|
||||||
private Map<String, DefaultNode> map = new HashMap<String, DefaultNode>(10);
|
private volatile Map<String, DefaultNode> map = new HashMap<String, DefaultNode>(10);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void entry(Context context, ResourceWrapper resourceWrapper, Object obj, int count, Object... args)
|
public void entry(Context context, ResourceWrapper resourceWrapper, Object obj, int count, Object... args)
|
||||||
|
|
|
||||||
|
|
@ -10,8 +10,4 @@
|
||||||
</parent>
|
</parent>
|
||||||
<artifactId>sentinel-demo-basic</artifactId>
|
<artifactId>sentinel-demo-basic</artifactId>
|
||||||
|
|
||||||
<dependencies>
|
|
||||||
|
|
||||||
</dependencies>
|
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
|
@ -42,18 +42,19 @@ public class FlowQpsDemo {
|
||||||
|
|
||||||
private static volatile boolean stop = false;
|
private static volatile boolean stop = false;
|
||||||
|
|
||||||
private static final int threadCount = 1;
|
private static final int threadCount = 32;
|
||||||
|
|
||||||
private static int seconds = 60 + 40;
|
private static int seconds = 60 + 40;
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
|
initFlowQpsRule();
|
||||||
|
|
||||||
tick();
|
tick();
|
||||||
// first make the system run on a very low condition
|
// first make the system run on a very low condition
|
||||||
simulateTraffic();
|
simulateTraffic();
|
||||||
|
|
||||||
System.out.println("===== begin to do flow control");
|
System.out.println("===== begin to do flow control");
|
||||||
System.out.println("only 20 requests per second can pass");
|
System.out.println("only 20 requests per second can pass");
|
||||||
initFlowQpsRule();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue