GlassFish 负责处理对同一个@Path
. 实际上,不建议在使用 Java EE 编写的代码中使用线程。
这种方法
@Path("/task")
@GET
@Produces("text/plain")
public String startTask() throws InterruptedException {
Thread.sleep(1000); // sleep for one second
return "ok: ";
}
睡眠一秒钟可以这样进行基准测试ab
:
% ab -c 20 -n 20 http://localhost:8080/WebApplication1/rest/console/task
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
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).....done
Server Software: GlassFish
Server Hostname: localhost
Server Port: 8080
Document Path: /WebApplication1/rest/console/task
Document Length: 4 bytes
Concurrency Level: 20
Time taken for tests: 4.014 seconds
Complete requests: 20
Failed requests: 0
Write errors: 0
Total transferred: 5380 bytes
HTML transferred: 80 bytes
Requests per second: 4.98 [#/sec] (mean)
Time per request: 4014.363 [ms] (mean)
Time per request: 200.718 [ms] (mean, across all concurrent requests)
Transfer rate: 1.31 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 1 0.2 1 1
Processing: 1004 2509 1150.0 3009 4013
Waiting: 1003 2507 1150.3 3008 4012
Total: 1004 2509 1149.8 3010 4013
Percentage of the requests served within a certain time (ms)
50% 3010
66% 3010
75% 4012
80% 4012
90% 4013
95% 4013
98% 4013
99% 4013
100% 4013 (longest request)
ab
并行执行 20 个请求。如您所见,这只需要 4.014 秒。