Fix flow control host bug
This commit is contained in:
@@ -325,7 +325,8 @@ public class FlowControlFilter extends FizzWebFilter {
|
|||||||
StringBuilder b = ThreadContext.getStringBuilder();
|
StringBuilder b = ThreadContext.getStringBuilder();
|
||||||
|
|
||||||
if (hasHost) {
|
if (hasHost) {
|
||||||
String resourceId = ResourceIdUtils.buildResourceId(app, ip, node, service, path);
|
// String resourceId = ResourceIdUtils.buildResourceId(app, ip, node, service, path);
|
||||||
|
String resourceId = ResourceIdUtils.buildResourceId(null, null, node, null, null);
|
||||||
ResourceConfig resourceConfig = new ResourceConfig(resourceId, 0, 0);
|
ResourceConfig resourceConfig = new ResourceConfig(resourceId, 0, 0);
|
||||||
resourceConfigs.add(resourceConfig);
|
resourceConfigs.add(resourceConfig);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -197,7 +197,7 @@ public class FlowStat {
|
|||||||
// increase request and concurrent request
|
// increase request and concurrent request
|
||||||
for (ResourceConfig resourceConfig : resourceConfigs) {
|
for (ResourceConfig resourceConfig : resourceConfigs) {
|
||||||
ResourceStat resourceStat = getResourceStat(resourceConfig.getResourceId());
|
ResourceStat resourceStat = getResourceStat(resourceConfig.getResourceId());
|
||||||
long cons = resourceStat.getConcurrentRequests().incrementAndGet();
|
int cons = resourceStat.getConcurrentRequests().incrementAndGet();
|
||||||
resourceStat.getTimeSlot(curTimeSlotId).updatePeakConcurrentReqeusts(cons);
|
resourceStat.getTimeSlot(curTimeSlotId).updatePeakConcurrentReqeusts(cons);
|
||||||
resourceStat.getTimeSlot(curTimeSlotId).incr();
|
resourceStat.getTimeSlot(curTimeSlotId).incr();
|
||||||
}
|
}
|
||||||
@@ -276,7 +276,7 @@ public class FlowStat {
|
|||||||
// increase request and concurrent request
|
// increase request and concurrent request
|
||||||
for (ResourceConfig resourceConfig : resourceConfigs) {
|
for (ResourceConfig resourceConfig : resourceConfigs) {
|
||||||
ResourceStat resourceStat = getResourceStat(resourceConfig.getResourceId());
|
ResourceStat resourceStat = getResourceStat(resourceConfig.getResourceId());
|
||||||
long cons = resourceStat.getConcurrentRequests().incrementAndGet();
|
int cons = resourceStat.getConcurrentRequests().incrementAndGet();
|
||||||
resourceStat.getTimeSlot(curTimeSlotId).updatePeakConcurrentReqeusts(cons);
|
resourceStat.getTimeSlot(curTimeSlotId).updatePeakConcurrentReqeusts(cons);
|
||||||
resourceStat.getTimeSlot(curTimeSlotId).incr();
|
resourceStat.getTimeSlot(curTimeSlotId).incr();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ package we.stats;
|
|||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.ConcurrentMap;
|
import java.util.concurrent.ConcurrentMap;
|
||||||
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
import java.util.concurrent.atomic.AtomicLong;
|
import java.util.concurrent.atomic.AtomicLong;
|
||||||
import java.util.concurrent.locks.Lock;
|
import java.util.concurrent.locks.Lock;
|
||||||
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
||||||
@@ -50,7 +51,8 @@ public class ResourceStat {
|
|||||||
/**
|
/**
|
||||||
* Concurrent requests
|
* Concurrent requests
|
||||||
*/
|
*/
|
||||||
private AtomicLong concurrentRequests = new AtomicLong(0);
|
// private AtomicLong concurrentRequests = new AtomicLong(0);
|
||||||
|
private AtomicInteger concurrentRequests = new AtomicInteger(0);
|
||||||
|
|
||||||
private ReentrantReadWriteLock rwl1 = new ReentrantReadWriteLock();
|
private ReentrantReadWriteLock rwl1 = new ReentrantReadWriteLock();
|
||||||
private ReentrantReadWriteLock rwl2 = new ReentrantReadWriteLock();
|
private ReentrantReadWriteLock rwl2 = new ReentrantReadWriteLock();
|
||||||
@@ -95,16 +97,16 @@ public class ResourceStat {
|
|||||||
try {
|
try {
|
||||||
boolean isExceeded = false;
|
boolean isExceeded = false;
|
||||||
if (maxCon != null && maxCon.intValue() > 0) {
|
if (maxCon != null && maxCon.intValue() > 0) {
|
||||||
long n = this.concurrentRequests.get();
|
int n = this.concurrentRequests.get();
|
||||||
if (n >= maxCon.longValue()) {
|
if (n >= maxCon.longValue()) {
|
||||||
isExceeded = true;
|
isExceeded = true;
|
||||||
this.incrBlockRequestToTimeSlot(timeSlotId);
|
this.incrBlockRequestToTimeSlot(timeSlotId);
|
||||||
} else {
|
} else {
|
||||||
long conns = this.concurrentRequests.incrementAndGet();
|
int conns = this.concurrentRequests.incrementAndGet();
|
||||||
this.getTimeSlot(timeSlotId).updatePeakConcurrentReqeusts(conns);
|
this.getTimeSlot(timeSlotId).updatePeakConcurrentReqeusts(conns);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
long conns = this.concurrentRequests.incrementAndGet();
|
int conns = this.concurrentRequests.incrementAndGet();
|
||||||
this.getTimeSlot(timeSlotId).updatePeakConcurrentReqeusts(conns);
|
this.getTimeSlot(timeSlotId).updatePeakConcurrentReqeusts(conns);
|
||||||
}
|
}
|
||||||
return !isExceeded;
|
return !isExceeded;
|
||||||
@@ -118,7 +120,7 @@ public class ResourceStat {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public void decrConcurrentRequest(long timeSlotId) {
|
public void decrConcurrentRequest(long timeSlotId) {
|
||||||
long conns = this.concurrentRequests.decrementAndGet();
|
int conns = this.concurrentRequests.decrementAndGet();
|
||||||
this.getTimeSlot(timeSlotId).updatePeakConcurrentReqeusts(conns);
|
this.getTimeSlot(timeSlotId).updatePeakConcurrentReqeusts(conns);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -335,11 +337,11 @@ public class ResourceStat {
|
|||||||
this.timeSlots = timeSlots;
|
this.timeSlots = timeSlots;
|
||||||
}
|
}
|
||||||
|
|
||||||
public AtomicLong getConcurrentRequests() {
|
public AtomicInteger getConcurrentRequests() {
|
||||||
return concurrentRequests;
|
return concurrentRequests;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setConcurrentRequests(AtomicLong concurrentRequests) {
|
public void setConcurrentRequests(AtomicInteger concurrentRequests) {
|
||||||
this.concurrentRequests = concurrentRequests;
|
this.concurrentRequests = concurrentRequests;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ public class TimeSlot {
|
|||||||
* Total response time
|
* Total response time
|
||||||
*/
|
*/
|
||||||
// private AtomicLong totalRt = new AtomicLong(0);
|
// private AtomicLong totalRt = new AtomicLong(0);
|
||||||
private volatile long totalRt = 0;
|
private volatile int totalRt = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Completed Request counter
|
* Completed Request counter
|
||||||
@@ -68,11 +68,10 @@ public class TimeSlot {
|
|||||||
// private AtomicLong compReqs = new AtomicLong();
|
// private AtomicLong compReqs = new AtomicLong();
|
||||||
private volatile int compReqs = 0;
|
private volatile int compReqs = 0;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Peak concurrent requests
|
* Peak concurrent requests
|
||||||
*/
|
*/
|
||||||
private long peakConcurrentRequests;
|
private volatile int peakConcurrentRequests;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Block requests <br/>
|
* Block requests <br/>
|
||||||
@@ -84,7 +83,7 @@ public class TimeSlot {
|
|||||||
* Total block requests of the resource and its underlying resources <br/>
|
* Total block requests of the resource and its underlying resources <br/>
|
||||||
*/
|
*/
|
||||||
// private AtomicLong totalBlockRequests = new AtomicLong(0);
|
// private AtomicLong totalBlockRequests = new AtomicLong(0);
|
||||||
private volatile long totalBlockRequests = 0;
|
private volatile int totalBlockRequests = 0;
|
||||||
|
|
||||||
private AtomicReference<CircuitBreaker.State> circuitBreakState = new AtomicReference<>(CircuitBreaker.State.CLOSED);
|
private AtomicReference<CircuitBreaker.State> circuitBreakState = new AtomicReference<>(CircuitBreaker.State.CLOSED);
|
||||||
|
|
||||||
@@ -211,7 +210,7 @@ public class TimeSlot {
|
|||||||
*
|
*
|
||||||
* @param concurrentRequests Current concurrent requests
|
* @param concurrentRequests Current concurrent requests
|
||||||
*/
|
*/
|
||||||
public synchronized void updatePeakConcurrentReqeusts(long concurrentRequests) {
|
public synchronized void updatePeakConcurrentReqeusts(int concurrentRequests) {
|
||||||
peakConcurrentRequests = concurrentRequests > peakConcurrentRequests ? concurrentRequests
|
peakConcurrentRequests = concurrentRequests > peakConcurrentRequests ? concurrentRequests
|
||||||
: peakConcurrentRequests;
|
: peakConcurrentRequests;
|
||||||
}
|
}
|
||||||
@@ -244,11 +243,11 @@ public class TimeSlot {
|
|||||||
this.max = max;
|
this.max = max;
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getTotalRt() {
|
public int getTotalRt() {
|
||||||
return totalRt;
|
return totalRt;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTotalRt(long totalRt) {
|
public void setTotalRt(int totalRt) {
|
||||||
this.totalRt = totalRt;
|
this.totalRt = totalRt;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -256,7 +255,7 @@ public class TimeSlot {
|
|||||||
return peakConcurrentRequests;
|
return peakConcurrentRequests;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPeakConcurrentRequests(long peakConcurrentRequests) {
|
public void setPeakConcurrentRequests(int peakConcurrentRequests) {
|
||||||
this.peakConcurrentRequests = peakConcurrentRequests;
|
this.peakConcurrentRequests = peakConcurrentRequests;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -288,7 +287,7 @@ public class TimeSlot {
|
|||||||
this.compReqs = compReqs;
|
this.compReqs = compReqs;
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getTotalBlockRequests() {
|
public int getTotalBlockRequests() {
|
||||||
return totalBlockRequests;
|
return totalBlockRequests;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -296,7 +295,7 @@ public class TimeSlot {
|
|||||||
++totalBlockRequests;
|
++totalBlockRequests;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTotalBlockRequests(long totalBlockRequests) {
|
public void setTotalBlockRequests(int totalBlockRequests) {
|
||||||
this.totalBlockRequests = totalBlockRequests;
|
this.totalBlockRequests = totalBlockRequests;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user