Merge pull request #10 from wehotel/master

optimize flotstat unit tests
This commit is contained in:
hongqiaowei
2021-03-18 14:19:45 +08:00
committed by GitHub
2 changed files with 13 additions and 28 deletions

View File

@@ -193,10 +193,6 @@ public class FlowStat {
if (success) { if (success) {
success = resourceStat.incrRequestToTimeSlot(curTimeSlotId, maxRPS); success = resourceStat.incrRequestToTimeSlot(curTimeSlotId, maxRPS);
} }
if (log.isDebugEnabled()) {
log.debug(resourceId + " incr req for current time slot " + curTimeSlotId + " with max con " + maxCon
+ " and max rps " + maxRPS);
}
return success; return success;
} }
@@ -215,15 +211,6 @@ public class FlowStat {
ResourceStat resourceStat = getResourceStat(resourceId); ResourceStat resourceStat = getResourceStat(resourceId);
long conns = resourceStat.getConcurrentRequests().get(); long conns = resourceStat.getConcurrentRequests().get();
if (conns == 0) {
if (log.isDebugEnabled()) {
StringBuilder b = new StringBuilder(256);
b.append(timeSlotId + " " + resourceId + " conns 0 before decr it").append('\n');
Utils.threadCurrentStack2stringBuilder(b);
log.debug(b.toString());
}
}
resourceStat.decrConcurrentRequest(timeSlotId); resourceStat.decrConcurrentRequest(timeSlotId);
} }
@@ -250,9 +237,6 @@ public class FlowStat {
resourceStat = resourceStats.get(resourceId); resourceStat = resourceStats.get(resourceId);
} else { } else {
resourceStat = new ResourceStat(resourceId); resourceStat = new ResourceStat(resourceId);
if (log.isDebugEnabled()) {
log.debug("no resource stat for " + resourceId + ", create one " + resourceStat);
}
ResourceStat rs = resourceStats.putIfAbsent(resourceId, resourceStat); ResourceStat rs = resourceStats.putIfAbsent(resourceId, resourceStat);
if (rs != null) { if (rs != null) {
resourceStat = rs; resourceStat = rs;

View File

@@ -41,8 +41,8 @@ public class FlowStatTests {
private FlowStat stat = new FlowStat(); private FlowStat stat = new FlowStat();
class FlowRuleCase { class FlowRuleCase {
public int threads = 10; public int threads = 3;
public int requests = 10000; public int requests = 1000;
public int totalReqs = threads * requests; public int totalReqs = threads * requests;
public List<ResourceConfig> resourceConfigs = new ArrayList<>(); public List<ResourceConfig> resourceConfigs = new ArrayList<>();
public List<ResourceExpect> resourceExpects = new ArrayList<>(); public List<ResourceExpect> resourceExpects = new ArrayList<>();
@@ -302,8 +302,8 @@ public class FlowStatTests {
long nextSlotId = curTimeSlotId + 1000; long nextSlotId = curTimeSlotId + 1000;
Long maxCon = 10l; Long maxCon = 10l;
Long maxRPS = 20l; Long maxRPS = 20l;
int threads = 100; int threads = 3;
int requests = 10000; int requests = 1000;
int totalRequests = threads * requests; int totalRequests = threads * requests;
String resourceId = "c"; String resourceId = "c";
@@ -331,8 +331,8 @@ public class FlowStatTests {
long nextSlotId = curTimeSlotId + 1000; long nextSlotId = curTimeSlotId + 1000;
Long maxCon = Long.MAX_VALUE; Long maxCon = Long.MAX_VALUE;
Long maxRPS = 20l; Long maxRPS = 20l;
int threads = 100; int threads = 3;
int requests = 10000; int requests = 1000;
int totalRequests = threads * requests; int totalRequests = threads * requests;
String resourceId = "c"; String resourceId = "c";
@@ -361,9 +361,9 @@ public class FlowStatTests {
@Test @Test
public void testStat() throws Throwable { public void testStat() throws Throwable {
// requests per slot per resource // requests per slot per resource
int requests = 100; int requests = 30;
int threads = 10; int threads = 3;
int resources = 10; int resources = 3;
int slots = 100; int slots = 100;
long rt = 100; long rt = 100;
long t1 = System.currentTimeMillis(); long t1 = System.currentTimeMillis();
@@ -412,7 +412,8 @@ public class FlowStatTests {
// performance of getTimeWindowStat // performance of getTimeWindowStat
for (int n = 0; n < 10; n++) { for (int n = 0; n < 10; n++) {
long t3 = System.currentTimeMillis(); long t3 = System.currentTimeMillis();
int times = 100000; // int times = 100000;
int times = 1000;
for (int i = 0; i < times; i++) { for (int i = 0; i < times; i++) {
stat.getTimeWindowStat("resource-" + resource1, start, end); stat.getTimeWindowStat("resource-" + resource1, start, end);
} }
@@ -501,8 +502,8 @@ public class FlowStatTests {
@Test @Test
public void testGetResourceStat() throws Throwable { public void testGetResourceStat() throws Throwable {
int threads = 10; int threads = 3;
int requests = 100000; int requests = 100;
ExecutorService pool = Executors.newFixedThreadPool(threads); ExecutorService pool = Executors.newFixedThreadPool(threads);
long t1 = System.currentTimeMillis(); long t1 = System.currentTimeMillis();
for (int i = 0; i < threads; i++) { for (int i = 0; i < threads; i++) {