千家信息网

怎么进行java并发模拟

发表于:2025-02-23 作者:千家信息网编辑
千家信息网最后更新 2025年02月23日,怎么进行java并发模拟,很多新手对此不是很清楚,为了帮助大家解决这个难题,下面小编将为大家详细讲解,有这方面需求的人可以来学习下,希望你能有所收获。在project-1中新建controller,T
千家信息网最后更新 2025年02月23日怎么进行java并发模拟

怎么进行java并发模拟,很多新手对此不是很清楚,为了帮助大家解决这个难题,下面小编将为大家详细讲解,有这方面需求的人可以来学习下,希望你能有所收获。

在project-1中新建controller,TestController.java内容如下:

@RestController@Slf4jpublic class TestController {    @GetMapping("/test")    public String test() {        return "test";    }}

需要依赖Slf4j包,需要在pom.xml文件中添加依赖:

                    org.projectlombok            lombok            1.18.6        

POSTMAN工具测试

在postman工具中新建collection:

并将测试url添加到这个collection中,点击run,然后配置:


Apache bench工具

下载地址:https://www.apachelounge.com/download/

ab -n 1000 -c 50 http://localhost:8080/test

输出结果如下:

C:\Users\vincent>ab -n 1000 -c 50 http://localhost:8080/testThis is ApacheBench, Version 2.3 <$Revision: 1843412 $>Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/Licensed to The Apache Software Foundation, http://www.apache.org/Benchmarking localhost (be patient)Completed 100 requestsCompleted 200 requestsCompleted 300 requestsCompleted 400 requestsCompleted 500 requestsCompleted 600 requestsCompleted 700 requestsCompleted 800 requestsCompleted 900 requestsCompleted 1000 requestsFinished 1000 requestsServer Software:Server Hostname:        localhostServer Port:            8080Document Path:          /testDocument Length:        4 bytesConcurrency Level:      50Time taken for tests:   0.673 secondsComplete requests:      1000Failed requests:        0Total transferred:      136000 bytesHTML transferred:       4000 bytesRequests per second:    1486.74 [#/sec] (mean)Time per request:       33.631 [ms] (mean)Time per request:       0.673 [ms] (mean, across all concurrent requests)Transfer rate:          197.46 [Kbytes/sec] receivedConnection Times (ms)              min  mean[+/-sd] median   maxConnect:        0    0   0.3      0       1Processing:     1   19  19.8     15     291Waiting:        0   16  16.7     12     278Total:          1   20  19.8     15     292Percentage of the requests served within a certain time (ms)  50%     15  66%     19  75%     23  80%     24  90%     33  95%     62  98%     84  99%     99 100%    292 (longest request)

-n 1000表示本次测试的总数为100个

-c 50表示本次请求的并发数是50

看完上述内容是否对您有帮助呢?如果还想对相关知识有进一步的了解或阅读更多相关文章,请关注行业资讯频道,感谢您对的支持。

0