Browse Source

Code and javadoc refinement

Signed-off-by: Eric Zhao <sczyh16@gmail.com>
master
Eric Zhao 6 years ago
parent
commit
f2a401cdb3
2 changed files with 33 additions and 20 deletions
  1. +15
    -15
      sentinel-core/src/main/java/com/alibaba/csp/sentinel/node/StatisticNode.java
  2. +18
    -5
      sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/statistic/StatisticSlot.java

+ 15
- 15
sentinel-core/src/main/java/com/alibaba/csp/sentinel/node/StatisticNode.java View File

@@ -44,10 +44,10 @@ import com.alibaba.csp.sentinel.slots.statistic.metric.Metric;
* incoming request(QPS), block request(bq), etc. And the time-span is defined by sample count.
* </p>
* <pre>
* 0 100ms
* 0 100ms
* +-------+--→ Sliding Windows
* ^
* |
* ^
* |
* request
* </pre>
* <p>
@@ -58,29 +58,29 @@ import com.alibaba.csp.sentinel.slots.statistic.metric.Metric;
*
* <p>case 2: continuous requests</p>
* <pre>
* 0 100ms 200ms 300ms
* 0 100ms 200ms 300ms
* +-------+-------+-------+-----→ Sliding Windows
* ^
* |
* request
* ^
* |
* request
* </pre>
*
* <p>case 3: requests keeps coming, and previous buckets become invalid</p>
* <pre>
* 0 100ms 200ms 800ms 900ms 1000ms 1300ms
* 0 100ms 200ms 800ms 900ms 1000ms 1300ms
* +-------+-------+ ...... +-------+-------+ ...... +-------+-----→ Sliding Windows
* ^
* |
* request
* ^
* |
* request
* </pre>
*
* <p>The sliding window should become:</p>
* <pre>
* 300ms 800ms 900ms 1000ms 1300ms
* 300ms 800ms 900ms 1000ms 1300ms
* + ...... +-------+ ...... +-------+-----→ Sliding Windows
* ^
* |
* request
* ^
* |
* request
* </pre>
*
* @author qinan.qn


+ 18
- 5
sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/statistic/StatisticSlot.java View File

@@ -35,10 +35,10 @@ import com.alibaba.csp.sentinel.slots.block.BlockException;
* When entering this slot, we need to separately count the following
* information:
* <ul>
* <li>{@link ClusterNode}: total statistics of a cluster node of the resource id  </li>
* <li> origin node: statistics of a cluster node from different callers/origins.</li>
* <li> {@link DefaultNode}: statistics for specific resource name in the specific context.
* <li> Finally, the sum statistics of all entrances.</li>
* <li>{@link ClusterNode}: total statistics of a cluster node of the resource ID.</li>
* <li>Origin node: statistics of a cluster node from different callers/origins.</li>
* <li>{@link DefaultNode}: statistics for specific resource name in the specific context.</li>
* <li>Finally, the sum statistics of all entrances.</li>
* </ul>
* </p>
*
@@ -51,24 +51,31 @@ public class StatisticSlot extends AbstractLinkedProcessorSlot<DefaultNode> {
public void entry(Context context, ResourceWrapper resourceWrapper, DefaultNode node, int count, Object... args)
throws Throwable {
try {
// Do some checking.
fireEntry(context, resourceWrapper, node, count, args);

// Request passed, add thread count and pass count.
node.increaseThreadNum();
node.addPassRequest();

if (context.getCurEntry().getOriginNode() != null) {
// Add count for origin node.
context.getCurEntry().getOriginNode().increaseThreadNum();
context.getCurEntry().getOriginNode().addPassRequest();
}

if (resourceWrapper.getType() == EntryType.IN) {
// Add count for global inbound entry node for global statistics.
Constants.ENTRY_NODE.increaseThreadNum();
Constants.ENTRY_NODE.addPassRequest();
}

// Handle pass event with registered entry callback handlers.
for (ProcessorSlotEntryCallback<DefaultNode> handler : StatisticSlotCallbackRegistry.getEntryCallbacks()) {
handler.onPass(context, resourceWrapper, node, count, args);
}
} catch (BlockException e) {
// Blocked, set block exception to current entry.
context.getCurEntry().setError(e);

// Add block count.
@@ -78,18 +85,21 @@ public class StatisticSlot extends AbstractLinkedProcessorSlot<DefaultNode> {
}

if (resourceWrapper.getType() == EntryType.IN) {
// Add count for global inbound entry node for global statistics.
Constants.ENTRY_NODE.increaseBlockQps();
}

// Handle block event with registered entry callback handlers.
for (ProcessorSlotEntryCallback<DefaultNode> handler : StatisticSlotCallbackRegistry.getEntryCallbacks()) {
handler.onBlocked(e, context, resourceWrapper, node, count, args);
}

throw e;
} catch (Throwable e) {
// Unexpected error, set error to current entry.
context.getCurEntry().setError(e);

// Should not happen
// This should not happen.
node.increaseExceptionQps();
if (context.getCurEntry().getOriginNode() != null) {
context.getCurEntry().getOriginNode().increaseExceptionQps();
@@ -107,11 +117,13 @@ public class StatisticSlot extends AbstractLinkedProcessorSlot<DefaultNode> {
DefaultNode node = (DefaultNode)context.getCurNode();

if (context.getCurEntry().getError() == null) {
// Calculate response time (max RT is TIME_DROP_VALVE).
long rt = TimeUtil.currentTimeMillis() - context.getCurEntry().getCreateTime();
if (rt > Constants.TIME_DROP_VALVE) {
rt = Constants.TIME_DROP_VALVE;
}

// Record response time and success count.
node.rt(rt);
if (context.getCurEntry().getOriginNode() != null) {
context.getCurEntry().getOriginNode().rt(rt);
@@ -131,6 +143,7 @@ public class StatisticSlot extends AbstractLinkedProcessorSlot<DefaultNode> {
// Error may happen.
}

// Handle exit event with registered exit callback handlers.
Collection<ProcessorSlotExitCallback> exitCallbacks = StatisticSlotCallbackRegistry.getExitCallbacks();
for (ProcessorSlotExitCallback handler : exitCallbacks) {
handler.onExit(context, resourceWrapper, count, args);


Loading…
Cancel
Save