随着apache bench中并发性的增加,Tomcat响应时间也在增加

时间:2014-09-25 04:59:41

标签: java rest tomcat apachebench

当我在ab(apache bench)中增加并发性-c时,我的响应时间会有所不同。

-c      99%
3       2ms
5       4ms
8       6ms

如果我进一步增加-c,那么响应时间也会增加。我的代码非常简单,没有线程饥饿,没有阻塞等等。那么为什么响应时间会增加?

我认为ab -c 8表示同时向http://localhost:8070/benchmark发出请求。那么是否有可能将请求汇集到tomcat?如果是这样的话,那么如何让tomcat处理更多并发用户的响应时间更短(4ms为99%)?

@RestController
public class PerformanceController {

    @RequestMapping(value="/benchmark",method=RequestMethod.GET)
    public String getRetargetingData(){
        return "Just plain call";
    }

}

ritesh@ritesh:~$ ab -n 10000 -c 3 'http://localhost:8070/benchmark'
Server Software:        Apache-Coyote/1.1
Server Hostname:        localhost
Server Port:            8070

Document Path:          /benchmark
Document Length:        15 bytes

Concurrency Level:      3
Time taken for tests:   2.602 seconds
Complete requests:      10000
Failed requests:        0
Total transferred:      4050000 bytes
HTML transferred:       150000 bytes
Requests per second:    3843.57 [#/sec] (mean)
Time per request:       0.781 [ms] (mean)
Time per request:       0.260 [ms] (mean, across all concurrent requests)
Transfer rate:          1520.16 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.0      0       0
Processing:     0    1   0.5      1      23
Waiting:        0    1   0.4      1      23
Total:          0    1   0.5      1      24

Percentage of the requests served within a certain time (ms)
  50%      1
  66%      1
  75%      1
  80%      1
  90%      1
  95%      1
  98%      2
  99%      2
 100%     24 (longest request)


ritesh@ritesh:~$ ab -n 10000 -c 6 'http://localhost:8070/benchmark'
Server Software:        Apache-Coyote/1.1
Server Hostname:        localhost
Server Port:            8070

Document Path:          /benchmark
Document Length:        15 bytes

Concurrency Level:      6
Time taken for tests:   1.814 seconds
Complete requests:      10000
Failed requests:        0
Total transferred:      4050000 bytes
HTML transferred:       150000 bytes
Requests per second:    5514.16 [#/sec] (mean)
Time per request:       1.088 [ms] (mean)
Time per request:       0.181 [ms] (mean, across all concurrent requests)
Transfer rate:          2180.89 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.0      0       1
Processing:     0    1   0.9      1      22
Waiting:        0    1   0.8      1      22
Total:          0    1   0.9      1      22

Percentage of the requests served within a certain time (ms)
  50%      1
  66%      1
  75%      1
  80%      1
  90%      2
  95%      2
  98%      3
  99%      4
 100%     22 (longest request)


ritesh@ritesh:~$ ab -n 10000 -c 8 'http://localhost:8070/benchmark'

Server Software:        Apache-Coyote/1.1
Server Hostname:        localhost
Server Port:            8070

Document Path:          /benchmark
Document Length:        15 bytes

Concurrency Level:      8
Time taken for tests:   1.889 seconds
Complete requests:      10000
Failed requests:        0
Total transferred:      4050000 bytes
HTML transferred:       150000 bytes
Requests per second:    5293.55 [#/sec] (mean)
Time per request:       1.511 [ms] (mean)
Time per request:       0.189 [ms] (mean, across all concurrent requests)
Transfer rate:          2093.64 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.0      0       2
Processing:     0    1   1.8      1      50
Waiting:        0    1   1.8      1      50
Total:          0    1   1.8      1      50

Percentage of the requests served within a certain time (ms)
  50%      1
  66%      1
  75%      2
  80%      2
  90%      2
  95%      3
  98%      5
  99%      6
 100%     50 (longest request)
ritesh@ritesh:~$ ab -n 10000 -c 500 'http://localhost:8070/benchmark'
Server Software:        Apache-Coyote/1.1
Server Hostname:        localhost
Server Port:            8070

Document Path:          /benchmark
Document Length:        15 bytes

Concurrency Level:      500
Time taken for tests:   1.830 seconds
Complete requests:      10000
Failed requests:        0
Total transferred:      4050000 bytes
HTML transferred:       150000 bytes
Requests per second:    5464.11 [#/sec] (mean)
Time per request:       91.506 [ms] (mean)
Time per request:       0.183 [ms] (mean, across all concurrent requests)
Transfer rate:          2161.10 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0   25 154.8      0    1001
Processing:     1   23  45.7     12     818
Waiting:        1   23  45.6     12     818
Total:          2   48 188.5     12    1818

Percentage of the requests served within a certain time (ms)
  50%     12
  66%     17
  75%     22
  80%     26
  90%     45
  95%     66
  98%   1021
  99%   1220
 100%   1818 (longest request)

0 个答案:

没有答案