java高并发(五)并发模拟

释放双眼,带上耳机,听听看~!

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


1
2
3
4
5
6
7
8
9
10
11
12
1@RestController
2@Slf4j
3public class TestController {
4
5    @GetMapping("/test")
6    public String test() {
7        return "test";
8    }
9
10}
11
12

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


1
2
3
4
5
6
7
1        <dependency>
2            <groupId>org.projectlombok</groupId>
3            <artifactId>lombok</artifactId>
4            <version>1.18.6</version>
5        </dependency>
6
7

POSTMAN工具测试

在postman工具中新建collection:

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

Apache bench工具

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

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

输出结果如下:


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
1C:\Users\vincent>ab -n 1000 -c 50 http://localhost:8080/test
2This is ApacheBench, Version 2.3 <$Revision: 1843412 $>
3Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
4Licensed to The Apache Software Foundation, http://www.apache.org/
5
6Benchmarking localhost (be patient)
7Completed 100 requests
8Completed 200 requests
9Completed 300 requests
10Completed 400 requests
11Completed 500 requests
12Completed 600 requests
13Completed 700 requests
14Completed 800 requests
15Completed 900 requests
16Completed 1000 requests
17Finished 1000 requests
18
19
20Server Software:
21Server Hostname:        localhost
22Server Port:            8080
23
24Document Path:          /test
25Document Length:        4 bytes
26
27Concurrency Level:      50
28Time taken for tests:   0.673 seconds
29Complete requests:      1000
30Failed requests:        0
31Total transferred:      136000 bytes
32HTML transferred:       4000 bytes
33Requests per second:    1486.74 [#/sec] (mean)
34Time per request:       33.631 [ms] (mean)
35Time per request:       0.673 [ms] (mean, across all concurrent requests)
36Transfer rate:          197.46 [Kbytes/sec] received
37
38Connection Times (ms)
39              min  mean[+/-sd] median   max
40Connect:        0    0   0.3      0       1
41Processing:     1   19  19.8     15     291
42Waiting:        0   16  16.7     12     278
43Total:          1   20  19.8     15     292
44
45Percentage of the requests served within a certain time (ms)
46  50%     15
47  66%     19
48  75%     23
49  80%     24
50  90%     33
51  95%     62
52  98%     84
53  99%     99
54 100%    292 (longest request)
55

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

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

转载于:https://my.oschina.net/duanvincent/blog/3077439

给TA打赏
共{{data.count}}人
人已打赏
安全经验

Google Adsense优化心得

2021-10-11 16:36:11

安全经验

安全咨询服务

2022-1-12 14:11:49

个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索