Ver código fonte

Miscellaneous update

Signed-off-by: Eric Zhao <sczyh16@gmail.com>
master
Eric Zhao 6 anos atrás
pai
commit
94aea568f6
6 arquivos alterados com 31 adições e 32 exclusões
  1. +4
    -5
      sentinel-core/src/main/java/com/alibaba/csp/sentinel/CtSph.java
  2. +11
    -1
      sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/flow/FlowRule.java
  3. +12
    -19
      sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/flow/FlowRuleManager.java
  4. +1
    -1
      sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/nodeselector/NodeSelectorSlot.java
  5. +0
    -4
      sentinel-demo/sentinel-demo-basic/pom.xml
  6. +3
    -2
      sentinel-demo/sentinel-demo-basic/src/main/java/com/alibaba/csp/sentinel/demo/flow/FlowQpsDemo.java

+ 4
- 5
sentinel-core/src/main/java/com/alibaba/csp/sentinel/CtSph.java Ver arquivo

@@ -88,8 +88,8 @@ public class CtSph implements Sph {
ProcessorSlot<Object> chain = lookProcessChain(resourceWrapper);

/*
* Means processor size exceeds {@link Constants.MAX_ENTRY_SIZE}, no
* rule checking will do.
* Means processor cache size exceeds {@link Constants.MAX_SLOT_CHAIN_SIZE}, so no
* rule checking will be done.
*/
if (chain == null) {
return new CtEntry(resourceWrapper, null, context);
@@ -102,7 +102,7 @@ public class CtSph implements Sph {
e.exit(count, args);
throw e1;
} catch (Throwable e1) {
RecordLog.info("sentinel unexpected exception", e1);
RecordLog.info("Sentinel unexpected exception", e1);
}
return e;
}
@@ -134,8 +134,7 @@ public class CtSph implements Sph {
}

chain = Env.slotsChainbuilder.build();
HashMap<ResourceWrapper, ProcessorSlotChain> newMap
= new HashMap<ResourceWrapper, ProcessorSlotChain>(
Map<ResourceWrapper, ProcessorSlotChain> newMap = new HashMap<ResourceWrapper, ProcessorSlotChain>(
chainMap.size() + 1);
newMap.putAll(chainMap);
newMap.put(resourceWrapper, chain);


+ 11
- 1
sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/flow/FlowRule.java Ver arquivo

@@ -53,13 +53,23 @@ public class FlowRule extends AbstractRule {
*/
private int grade = RuleConstant.FLOW_GRADE_QPS;

/**
* Flow control threshold 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;

/**
* Reference resource in flow control with relevant resource.
*/
private String refResource;

/**


+ 12
- 19
sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/flow/FlowRuleManager.java Ver arquivo

@@ -86,9 +86,6 @@ public class FlowRuleManager {
*/
public static List<FlowRule> getRules() {
List<FlowRule> rules = new ArrayList<FlowRule>();
if (flowRules == null) {
return rules;
}
for (Map.Entry<String, List<FlowRule>> entry : flowRules.entrySet()) {
rules.addAll(entry.getValue());
}
@@ -145,13 +142,11 @@ public class FlowRuleManager {

public static void checkFlow(ResourceWrapper resource, Context context, DefaultNode node, int count)
throws BlockException {
if (flowRules != null) {
List<FlowRule> rules = flowRules.get(resource.getName());
if (rules != null) {
for (FlowRule rule : rules) {
if (!rule.passCheck(context, node, count)) {
throw new FlowException(rule.getLimitApp());
}
List<FlowRule> rules = flowRules.get(resource.getName());
if (rules != null) {
for (FlowRule rule : rules) {
if (!rule.passCheck(context, node, count)) {
throw new FlowException(rule.getLimitApp());
}
}
}
@@ -166,14 +161,12 @@ public class FlowRuleManager {
return false;
}

if (flowRules != null) {
List<FlowRule> rules = flowRules.get(resourceName);
List<FlowRule> rules = flowRules.get(resourceName);

if (rules != null) {
for (FlowRule rule : rules) {
if (origin.equals(rule.getLimitApp())) {
return false;
}
if (rules != null) {
for (FlowRule rule : rules) {
if (origin.equals(rule.getLimitApp())) {
return false;
}
}
}
@@ -190,7 +183,7 @@ public class FlowRuleManager {
flowRules.clear();
flowRules.putAll(rules);
}
RecordLog.info("receive flow config: " + flowRules);
RecordLog.info("[FlowRuleManager] Flow rules received: " + flowRules);
}

@Override
@@ -200,7 +193,7 @@ public class FlowRuleManager {
flowRules.clear();
flowRules.putAll(rules);
}
RecordLog.info("load flow config: " + flowRules);
RecordLog.info("[FlowRuleManager] Flow rules loaded: " + flowRules);
}

}


+ 1
- 1
sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/nodeselector/NodeSelectorSlot.java Ver arquivo

@@ -128,7 +128,7 @@ public class NodeSelectorSlot extends AbstractLinkedProcessorSlot<Object> {
/**
* {@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
public void entry(Context context, ResourceWrapper resourceWrapper, Object obj, int count, Object... args)


+ 0
- 4
sentinel-demo/sentinel-demo-basic/pom.xml Ver arquivo

@@ -10,8 +10,4 @@
</parent>
<artifactId>sentinel-demo-basic</artifactId>

<dependencies>
</dependencies>

</project>

+ 3
- 2
sentinel-demo/sentinel-demo-basic/src/main/java/com/alibaba/csp/sentinel/demo/flow/FlowQpsDemo.java Ver arquivo

@@ -42,18 +42,19 @@ public class FlowQpsDemo {

private static volatile boolean stop = false;

private static final int threadCount = 1;
private static final int threadCount = 32;

private static int seconds = 60 + 40;

public static void main(String[] args) throws Exception {
initFlowQpsRule();

tick();
// first make the system run on a very low condition
simulateTraffic();

System.out.println("===== begin to do flow control");
System.out.println("only 20 requests per second can pass");
initFlowQpsRule();

}



Carregando…
Cancelar
Salvar