关于zuul和云网关性能测试

时间:2018-07-06 09:35:26

标签: spring gateway spring-cloud-gateway

我想测试zuul和网关的性能,我构建了一个用于提供服务的cloudEurekaClient,并构建了zuul和网关的项目来测试其性能。我写了一个测试方法来测试它,

//count is the number of request ,the url is the request url
//the mehtod used Executors send many request and get the time
private List httpReq(int count ,Map map,String url,String type) throws InterruptedException {
{
//启动多个线程同时发起请求 设置100个线程
ExecutorService executorService = Executors.newFixedThreadPool(max_thread);
final CountDownLatch startLatch = new CountDownLatch(1);
final CountDownLatch endLatch = new CountDownLatch(count);
IntStream.range(0, count).forEach(i ->
executorService.execute(new PerformDemo(startLatch, endLatch, url))
);
startLatch.countDown();
long starttime = System.currentTimeMillis();
endLatch.await();
long endtime = System.currentTimeMillis();
executorService.shutdownNow();
while(!executorService.isTerminated()){
//TODO
}
map.put("type","1".equals(type)?"zull":"gateway");
map.put("time", endtime - starttime);
list.add(map);
return list;
}

class PerformDemo implements Runnable {

private CountDownLatch startLatch;

private CountDownLatch endLatch;

private String url;

public PerformDemo(CountDownLatch startLatch,CountDownLatch endLatch,String url){
    this.startLatch = startLatch;
    this.endLatch = endLatch;
    this.url = url;
}

@Override
public void run() {
    try {
        startLatch.await();
        demoReq(url);
    }catch (Exception e){
        //TODO
        throw new RuntimeException(e);
    }finally{
        endLatch.countDown();
    }
}

public static void demoReq(String url) {
    //1.使用默认的配置的httpclient
    CloseableHttpClient client = HttpClients.createDefault();
    //2.使用get方法
    HttpGet httpGet = new HttpGet(url);
    try {
        //3.执行请求,获取响应
        CloseableHttpResponse response = client.execute(httpGet);
    }catch(Exception e){
        //TODO
        throw new RuntimeException(e);
    }finally{

    }
}
}`

测试结果远远超出了我的预期 zuul比网关更好。 但是我用https://github.com/spencergibb/spring-cloud-gateway-benchhttp://www.itmuch.com/spring-cloud-sum/performance-zuul-and-gateway-linkerd/进行了测试,发现网关比zuul更好,我想知道为什么会这样。 @spencergibb @scottfrederick @eacdy @ryanjbaxter

0 个答案:

没有答案