Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add degradeCutHalfOpen and fix exceptionCount bug #525

Closed
wants to merge 33 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
b06c824
add degradeCutHalfOpen
Feb 27, 2019
01fb503
add degradeCutHalfOpen
Feb 27, 2019
d5783ec
fine tuning
CalvinKirs Mar 1, 2019
aaf0e4d
fine tuning
CalvinKirs Mar 1, 2019
d952ecd
Beautiful misunderstanding~
CalvinKirs Mar 2, 2019
8431b0a
fix 异常数熔断的错误逻辑(同一个时间窗口)
CalvinKirs Mar 4, 2019
2ef285d
merge
CalvinKirs Mar 4, 2019
ff6eb12
Merge branch 'master' into master
CalvinKirs Mar 4, 2019
7fed83f
微调
CalvinKirs Mar 4, 2019
ed35c39
Merge remote-tracking branch 'origin/master'
CalvinKirs Mar 4, 2019
e544f5b
微调
CalvinKirs Mar 4, 2019
0bcc3db
微调
CalvinKirs Mar 5, 2019
bbb630b
微调
CalvinKirs Mar 5, 2019
0cff032
冗余代码删除
CalvinKirs Mar 5, 2019
81e9829
微调
CalvinKirs Mar 5, 2019
5181c65
微调
CalvinKirs Mar 5, 2019
f42c9e1
微调
CalvinKirs Mar 5, 2019
f80a2ba
微调
CalvinKirs Mar 5, 2019
b390f53
Merge branch 'master' into master
CalvinKirs Mar 5, 2019
1e91194
微调
CalvinKirs Mar 5, 2019
273819f
Merge remote-tracking branch 'origin/master'
CalvinKirs Mar 5, 2019
bb7046f
基于rt的降级修改
CalvinKirs Mar 5, 2019
9666ddc
错误修改
CalvinKirs Mar 6, 2019
9ff83a0
微调
CalvinKirs Mar 6, 2019
7e83a09
微调
CalvinKirs Mar 6, 2019
a7a0dad
基于rt这里如果半开状态下放入的流量出现异常,我们认为这个时候系统是不正常的,所以继续降级
CalvinKirs Mar 6, 2019
203e83d
Merge branch 'master' into master
CalvinKirs Mar 6, 2019
0a3d864
微调
CalvinKirs Mar 6, 2019
c12151c
Merge remote-tracking branch 'origin/master'
CalvinKirs Mar 6, 2019
970f814
Delete DegradeRule.java
CalvinKirs Mar 6, 2019
a4e06b6
微调
CalvinKirs Mar 6, 2019
3628e0a
Merge remote-tracking branch 'origin/master'
CalvinKirs Mar 6, 2019
a7dd38c
the end
CalvinKirs Mar 7, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
package com.alibaba.csp.sentinel.node;

import java.util.Map;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;

import com.alibaba.csp.sentinel.Entry;
import com.alibaba.csp.sentinel.node.metric.MetricNode;
Expand Down Expand Up @@ -126,10 +129,21 @@ public interface Node {
*/
void addPassRequest(int count);

/**
* minus exception
*/
void minusMinuteException();

void minusSecondException();
/**
* minus Rt
*/
void minusRt(int count);

/**
* Add rt and success count.
*
* @param rt response time
* @param rt response time
* @param success success count to add
*/
void addRtAndSuccess(long rt, int success);
Expand Down Expand Up @@ -164,4 +178,25 @@ public interface Node {
* Debug only.
*/
void debug();

/**
* reset lastRT
*/
void resetLastRt();

/**
* get lastRT
*/
AtomicLong getLastRt();

/**
* get last Result (true:success;false:exception)
*/
AtomicBoolean getLastResult();

/**
* get last rt(same TimeWindow) sum
*/
AtomicInteger getLastRtSum();

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;

import com.alibaba.csp.sentinel.util.TimeUtil;
import com.alibaba.csp.sentinel.node.metric.MetricNode;
Expand Down Expand Up @@ -93,7 +95,7 @@ public class StatisticNode implements Node {
* by given {@code sampleCount}.
*/
private transient volatile Metric rollingCounterInSecond = new ArrayMetric(SampleCountProperty.SAMPLE_COUNT,
IntervalProperty.INTERVAL);
IntervalProperty.INTERVAL);

/**
* Holds statistics of the recent 60 seconds. The windowLengthInMs is deliberately set to 1000 milliseconds,
Expand All @@ -110,6 +112,21 @@ public class StatisticNode implements Node {
* The last timestamp when metrics were fetched.
*/
private long lastFetchTime = -1;
/**
* record last rt(Prepare degrade rt sum and same TimeWindow)
*/
private AtomicLong lastRt = new AtomicLong(0);

/**
* record last rt(same TimeWindow) sum
*/
private AtomicInteger lastRtSum = new AtomicInteger(0);
/**
* lastResult
*
* @return
*/
private AtomicBoolean lastResult = new AtomicBoolean(true);

@Override
public Map<Long, MetricNode> metrics() {
Expand Down Expand Up @@ -137,7 +154,7 @@ private boolean isNodeInTime(MetricNode node, long currentTime) {

private boolean isValidMetricNode(MetricNode node) {
return node.getPassQps() > 0 || node.getBlockQps() > 0 || node.getSuccessQps() > 0
|| node.getExceptionQps() > 0 || node.getRt() > 0;
|| node.getExceptionQps() > 0 || node.getRt() > 0;
}

@Override
Expand Down Expand Up @@ -232,11 +249,36 @@ public void addPassRequest(int count) {
rollingCounterInMinute.addPass(count);
}

@Override
public void minusSecondException() {
rollingCounterInSecond.minusException();
}
@Override
public void minusMinuteException() {
rollingCounterInMinute.minusException();
}

@Override
public void minusRt(int count) {
rollingCounterInSecond.minusRt(lastRt.get());
rollingCounterInSecond.minusSuccess(count);
rollingCounterInMinute.minusRt(lastRt.get());
rollingCounterInMinute.minusSuccess(count);
lastRt.set(0);
}

@Override
public void addRtAndSuccess(long rt, int successCount) {
rollingCounterInSecond.addSuccess(successCount);
rollingCounterInSecond.addRT(rt);

if (rollingCounterInSecond.newTimeWindow()) {
lastRt.set(rt);
lastRtSum.set(1);
} else {
lastRt.set(rt + lastRt.get());
lastRtSum.getAndAdd(1);
}
lastResult.set(true);
rollingCounterInMinute.addSuccess(successCount);
rollingCounterInMinute.addRT(rt);
}
Expand All @@ -251,7 +293,13 @@ public void increaseBlockQps(int count) {
public void increaseExceptionQps(int count) {
rollingCounterInSecond.addException(count);
rollingCounterInMinute.addException(count);
lastResult.set(false);

}

@Override
public void resetLastRt() {
lastRt.set(0);
}

@Override
Expand All @@ -268,4 +316,20 @@ public void decreaseThreadNum() {
public void debug() {
rollingCounterInSecond.debugQps();
}

@Override
public AtomicLong getLastRt() {
return lastRt;
}

@Override
public AtomicBoolean getLastResult() {
return lastResult;
}

@Override
public AtomicInteger getLastRtSum() {
return lastRtSum;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,14 @@ public final class RuleConstant {

public static final String LIMIT_APP_DEFAULT = "default";
public static final String LIMIT_APP_OTHER = "other";
/**
* Three states of the degraded switch
*/
public static final int DEGRADE_CUT_CLOSE = 0;
public static final int DEGRADE_CUT_OPEN = 1;
public static final int DEGRADE_CUT_HALF_OPEN = 2;

public static final int DEFAULT_SAMPLE_COUNT = 2;
public static final int DEFAULT_WINDOW_INTERVAL_MS = 1000;

private RuleConstant() {}
private RuleConstant(){}
}
Loading