Skip to content

Commit fc4aa5c

Browse files
author
wujiuye
committed
修复每秒平均数为0的问题
1 parent 3eaa417 commit fc4aa5c

File tree

4 files changed

+10
-4
lines changed

4 files changed

+10
-4
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,3 +155,9 @@ public class Main{
155155
}
156156
}
157157
```
158+
159+
### A&Q
160+
161+
* 1、平均请求数的统计有问题?
162+
平均请求数的计算:如果统计一分钟的qps,那么平均就是当前成功请求数/60秒。\
163+
所以要准确的话,前一分钟是准确的,当前分钟是不准确的。

src/main/java/com/wujiuye/flow/SecondFlower.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public SecondFlower() {
1818

1919
@Override
2020
protected long getWindowInterval(long windowInterval) {
21-
return windowInterval;
21+
return windowInterval / 1000;
2222
}
2323

2424
}

src/main/java/com/wujiuye/flow/common/Metric.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public interface Metric {
6666
void addRt(long rt);
6767

6868
/**
69-
* 获取以耗秒为单位的滑动窗口长度
69+
* 获取以毫秒为单位的滑动窗口长度
7070
*/
7171
long getWindowInterval();
7272

src/test/java/com/wujiuye/flow/FlowTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
public class FlowTest {
99

1010
public static void main(String[] args) throws InterruptedException {
11-
FlowHelper flowHelper = new FlowHelper(FlowType.Minute);
11+
FlowHelper flowHelper = new FlowHelper(FlowType.Second);
1212
new Thread(() -> {
1313
while (!Thread.interrupted()) {
1414
try {
@@ -21,7 +21,7 @@ public static void main(String[] args) throws InterruptedException {
2121
}).start();
2222
new Thread(() -> {
2323
while (!Thread.interrupted()) {
24-
Flower flower = flowHelper.getFlow(FlowType.Minute);
24+
Flower flower = flowHelper.getFlow(FlowType.Second);
2525
System.out.println("总请求数:" + flower.total());
2626
System.out.println("成功请求数:" + flower.totalSuccess());
2727
System.out.println("异常请求数:" + flower.totalException());

0 commit comments

Comments
 (0)