GlassFish は、同じ への複数のリクエストを処理します@Path
。実際、Java EE を使用して記述されたコードでスレッドを使用することはお勧めしません。
この方法
@Path("/task")
@GET
@Produces("text/plain")
public String startTask() throws InterruptedException {
Thread.sleep(1000); // sleep for one second
return "ok: ";
}
1秒間スリープするものは、次のようにベンチマークできます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 秒しかかかりません。