I've been profiling the Goliath-based server I've been building, and
ran into a really interesting problem. By merely removing the "
require 'mongoid' " line for the mongoid gem (2.3.3) from my config,
I'm seeing drastic improvements in response time.
Using apachebench, I tested the simple status endpoint that is
provided via Goliath::Rack::Heartbeat. No other code is being
exercised in the endpoint.
When I have this line in the config:
require 'mongoid'
...the ab results show that I'm getting approximately 80 requests per
second for the /status. When I remove the require, my throughput jumps
up to around 350 requests per second for /status. The actual ab
results are at the bottom of this message.
Anyone have any idea what could be going on? I might expect that
slowdowns could occur if something in the mongoing gem was not async-
aware... but given that I'm not actually using any of the code (just
requiring the gem) I'm puzzled by this result.
ab results *without* the mongoid gem being required:
(! 726)-> ab -n500 -c20
http://localhost:9000/status
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)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Finished 500 requests
Server Software: Goliath
Server Hostname: localhost
Server Port: 9000
Document Path: /status
Document Length: 2 bytes
Concurrency Level: 20
Time taken for tests: 1.320 seconds
Complete requests: 500
Failed requests: 0
Write errors: 0
Total transferred: 47752 bytes
HTML transferred: 1016 bytes
Requests per second: 378.78 [#/sec] (mean)
Time per request: 52.801 [ms] (mean)
Time per request: 2.640 [ms] (mean, across all concurrent
requests)
Transfer rate: 35.33 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.1 0 0
Processing: 16 51 8.3 52 72
Waiting: 3 40 12.9 42 56
Total: 16 51 8.2 53 72
Percentage of the requests served within a certain time (ms)
50% 53
66% 56
75% 56
80% 56
90% 60
95% 64
98% 72
99% 72
100% 72 (longest request)
ab results *with* the mongoid mongoid being required:
(! 727)-> ab -n500 -c20
http://localhost:9000/status
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)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Finished 500 requests
Server Software: Goliath
Server Hostname: localhost
Server Port: 9000
Document Path: /status
Document Length: 2 bytes
Concurrency Level: 20
Time taken for tests: 5.151 seconds
Complete requests: 500
Failed requests: 0
Write errors: 0
Total transferred: 47658 bytes
HTML transferred: 1014 bytes
Requests per second: 97.07 [#/sec] (mean)
Time per request: 206.041 [ms] (mean)
Time per request: 10.302 [ms] (mean, across all concurrent
requests)
Transfer rate: 9.04 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.1 0 0
Processing: 27 202 43.4 207 299
Waiting: 9 168 45.7 189 224
Total: 27 203 43.4 207 300
Percentage of the requests served within a certain time (ms)
50% 207
66% 212
75% 217
80% 220
90% 255
95% 280
98% 297
99% 300
100% 300 (longest request)
Cheers,
Adam