Skip to content

Commit

Permalink
Miscellaneous update
Browse files Browse the repository at this point in the history
Signed-off-by: Eric Zhao <[email protected]>
  • Loading branch information
sczyh30 committed Aug 15, 2018
1 parent 49097fa commit 94aea56
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ public Entry entry(ResourceWrapper resourceWrapper, int count, Object... args) t
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);
Expand All @@ -102,7 +102,7 @@ public Entry entry(ResourceWrapper resourceWrapper, int count, Object... args) t
e.exit(count, args);
throw e1;
} catch (Throwable e1) {
RecordLog.info("sentinel unexpected exception", e1);
RecordLog.info("Sentinel unexpected exception", e1);
}
return e;
}
Expand Down Expand Up @@ -134,8 +134,7 @@ private ProcessorSlot<Object> lookProcessChain(ResourceWrapper resourceWrapper)
}

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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,23 @@ public FlowRule(){
*/
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;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,6 @@ public static void register2Property(SentinelProperty<List<FlowRule>> property)
*/
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());
}
Expand Down Expand Up @@ -145,13 +142,11 @@ private static Map<String, List<FlowRule>> loadFlowConf(List<FlowRule> list) {

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());
}
}
}
Expand All @@ -166,14 +161,12 @@ public static boolean isOtherOrigin(String origin, String resourceName) {
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;
}
}
}
Expand All @@ -190,7 +183,7 @@ public void configUpdate(List<FlowRule> value) {
flowRules.clear();
flowRules.putAll(rules);
}
RecordLog.info("receive flow config: " + flowRules);
RecordLog.info("[FlowRuleManager] Flow rules received: " + flowRules);
}

@Override
Expand All @@ -200,7 +193,7 @@ public void configLoad(List<FlowRule> conf) {
flowRules.clear();
flowRules.putAll(rules);
}
RecordLog.info("load flow config: " + flowRules);
RecordLog.info("[FlowRuleManager] Flow rules loaded: " + flowRules);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 0 additions & 4 deletions sentinel-demo/sentinel-demo-basic/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,4 @@
</parent>
<artifactId>sentinel-demo-basic</artifactId>

<dependencies>

</dependencies>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -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();

}

Expand Down

0 comments on commit 94aea56

Please sign in to comment.