测试结果:
请求单个/多个接口,接口同时的请求量受限于整个项目.缺省搭建的springcloud项目为同时容纳200个并发请求
压测用脚本
import threading,requests class MyThread(threading.Thread): def __init__(self, thread_name, method, otherParam): threading.Thread.__init__(self) self.thread_name = thread_name self.otherParam = otherParam self.method = method def run(self): print("Starting " + self.name) self.method(self.thread_name, self.otherParam) def stop(self): pass def testThread(thread_name, otherParam): print(requests.get("http://127.0.0.1:8083/api/pressure/reg{}?count={}".format(otherParam % 9, otherParam)).text) if __name__ == ‘__main__‘: threads = [] for i in range(1, 300): threads.append(MyThread("Thread-" + str(i), testThread, i)) # 请忽略遍历及启动的时间差 for t in threads: t.start()
场景1: 只请求单个接口
@SneakyThrows @GetMapping("onlyOne") public String onlyOne(@RequestParam("count") Integer count) { log.error("onlyOne: 请求序号:{}", count); TimeUnit.SECONDS.sleep(20L); return "成功"; }
场景2: 同时请求两个接口
@SneakyThrows @GetMapping("splitTwo0") public String splitTwo0(@RequestParam("count") Integer count) { log.error("splitTwo0: 请求序号:{}", count); TimeUnit.SECONDS.sleep(20L); return "成功"; } @SneakyThrows @GetMapping("splitTwo1") public String splitTwo1(@RequestParam("count") Integer count) { log.error("splitTwo1: 请求序号:{}", count); TimeUnit.SECONDS.sleep(20L); return "成功"; }
场景3: 通配符方式同时请求单个接口
@SneakyThrows @GetMapping("/reg**") public String regQuery(HttpServletRequest request, @RequestParam("count") Integer count) { log.error("{}: 请求序号:{}",request.getServletPath(), count); TimeUnit.SECONDS.sleep(20L); return "成功"; }