|
|
@ -17,6 +17,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
package com.tencent.cloud.ratelimit.example.service.callee;
|
|
|
|
package com.tencent.cloud.ratelimit.example.service.callee;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.concurrent.CountDownLatch;
|
|
|
|
import java.util.concurrent.atomic.AtomicInteger;
|
|
|
|
import java.util.concurrent.atomic.AtomicInteger;
|
|
|
|
import java.util.concurrent.atomic.AtomicLong;
|
|
|
|
import java.util.concurrent.atomic.AtomicLong;
|
|
|
|
|
|
|
|
|
|
|
@ -45,17 +46,15 @@ public class BusinessController {
|
|
|
|
private static final Logger LOG = LoggerFactory.getLogger(BusinessController.class);
|
|
|
|
private static final Logger LOG = LoggerFactory.getLogger(BusinessController.class);
|
|
|
|
|
|
|
|
|
|
|
|
private final AtomicInteger index = new AtomicInteger(0);
|
|
|
|
private final AtomicInteger index = new AtomicInteger(0);
|
|
|
|
|
|
|
|
private final AtomicLong lastTimestamp = new AtomicLong(0);
|
|
|
|
@Autowired
|
|
|
|
@Autowired
|
|
|
|
private RestTemplate restTemplate;
|
|
|
|
private RestTemplate restTemplate;
|
|
|
|
|
|
|
|
|
|
|
|
@Value("${spring.application.name}")
|
|
|
|
@Value("${spring.application.name}")
|
|
|
|
private String appName;
|
|
|
|
private String appName;
|
|
|
|
|
|
|
|
|
|
|
|
private AtomicLong lastTimestamp = new AtomicLong(0);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Get information.
|
|
|
|
* Get information.
|
|
|
|
|
|
|
|
*
|
|
|
|
* @return information
|
|
|
|
* @return information
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@GetMapping("/info")
|
|
|
|
@GetMapping("/info")
|
|
|
@ -63,30 +62,41 @@ public class BusinessController {
|
|
|
|
return "hello world for ratelimit service " + index.incrementAndGet();
|
|
|
|
return "hello world for ratelimit service " + index.incrementAndGet();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Get information 30 times per 1 second.
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @return result of 30 calls.
|
|
|
|
|
|
|
|
* @throws InterruptedException exception
|
|
|
|
|
|
|
|
*/
|
|
|
|
@GetMapping("/invoke")
|
|
|
|
@GetMapping("/invoke")
|
|
|
|
public String invokeInfo() {
|
|
|
|
public String invokeInfo() throws InterruptedException {
|
|
|
|
StringBuilder builder = new StringBuilder();
|
|
|
|
StringBuffer builder = new StringBuffer();
|
|
|
|
|
|
|
|
CountDownLatch count = new CountDownLatch(30);
|
|
|
|
for (int i = 0; i < 30; i++) {
|
|
|
|
for (int i = 0; i < 30; i++) {
|
|
|
|
try {
|
|
|
|
new Thread(() -> {
|
|
|
|
ResponseEntity<String> entity = restTemplate.getForEntity(
|
|
|
|
try {
|
|
|
|
"http://" + appName + "/business/info", String.class);
|
|
|
|
ResponseEntity<String> entity = restTemplate.getForEntity("http://" + appName + "/business/info",
|
|
|
|
builder.append(entity.getBody()).append("<br/>");
|
|
|
|
String.class);
|
|
|
|
}
|
|
|
|
builder.append(entity.getBody() + "\n");
|
|
|
|
catch (RestClientException e) {
|
|
|
|
|
|
|
|
if (e instanceof TooManyRequests) {
|
|
|
|
|
|
|
|
builder.append(((TooManyRequests) e).getResponseBodyAsString())
|
|
|
|
|
|
|
|
.append(index.incrementAndGet()).append("<br/>");
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
catch (RestClientException e) {
|
|
|
|
throw e;
|
|
|
|
if (e instanceof TooManyRequests) {
|
|
|
|
|
|
|
|
builder.append("TooManyRequests " + index.incrementAndGet() + "\n");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
|
|
|
|
throw e;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
count.countDown();
|
|
|
|
|
|
|
|
}).start();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
count.await();
|
|
|
|
return builder.toString();
|
|
|
|
return builder.toString();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Get information with unirate.
|
|
|
|
* Get information with unirate.
|
|
|
|
|
|
|
|
*
|
|
|
|
* @return information
|
|
|
|
* @return information
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@GetMapping("/unirate")
|
|
|
|
@GetMapping("/unirate")
|
|
|
|