extend/ranch — pull request #12 by keynslug (2012-10-11 14:54:22+00:00)
Title: Allow acceptor to accept and handle sockets synchronously

There are use cases when we do not want ranch to spawn a process for each accept and then handling. It is such when we are serving huge number of lightweight http requests with huge number of active acceptors, and intensive process spawning and dying actually drop throughput observably.

Instead it seems ok to let end user decide if he wants to get rid of such performance drops.

There are some simple benchmarks done with mentioned features enabled^

```

Cowboy on localhost:80 with 1024 acceptors and cowboy_protocol, simple and fast handler.

-- Command line:

# for ii in {1..4}; do
# ab -n 50000 -c 512 "http://localhost/check?url=http://example.com/path" 2>/dev/null | grep "per second";
# done

-- On master:

Requests per second: 9788.94 [#/sec] (mean)
Requests per second: 9765.10 [#/sec] (mean)
Requests per second: 9917.74 [#/sec] (mean)
Requests per second: 9893.71 [#/sec] (mean)

-- With patch but without any options passed in childspec:

Requests per second: 9950.02 [#/sec] (mean)
Requests per second: 9752.39 [#/sec] (mean)
Requests per second: 9794.46 [#/sec] (mean)
Requests per second: 9964.40 [#/sec] (mean)

-- With patch and passed {sync_accept, true} option:

Requests per second: 10089.53 [#/sec] (mean)
Requests per second: 10068.27 [#/sec] (mean)
Requests per second: 9859.74 [#/sec] (mean)
Requests per second: 10160.97 [#/sec] (mean)

-- With patch and passed {sync_handle, true} option:

Requests per second: 11581.87 [#/sec] (mean)
Requests per second: 10935.11 [#/sec] (mean)
Requests per second: 11384.52 [#/sec] (mean)
Requests per second: 11285.44 [#/sec] (mean)

-- With patch and passed {sync_accept, true} and {sync_handle, true} options together:

Requests per second: 12244.53 [#/sec] (mean)
Requests per second: 12419.50 [#/sec] (mean)
Requests per second: 12277.67 [#/sec] (mean)
Requests per second: 12368.79 [#/sec] (mean)

-- ApacheBench logs with both options applied (to assure no errors was met):

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/

Server Software:
Server Hostname: localhost
Server Port: 80

Document Path: /check?url=http://example.com/path
Document Length: 4 bytes

Concurrency Level: 2048
Time taken for tests: 5.290 seconds
Complete requests: 50000
Failed requests: 0
Write errors: 0
Total transferred: 4750000 bytes
HTML transferred: 200000 bytes
Requests per second: 9451.37 [#/sec] (mean)
Time per request: 216.688 [ms] (mean)
Time per request: 0.106 [ms] (mean, across all concurrent requests)
Transfer rate: 876.84 [Kbytes/sec] received

Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 72 238.7 21 3048
Processing: 4 91 112.9 76 3227
Waiting: 1 82 112.9 67 3227
Total: 8 162 299.1 102 4231

Percentage of the requests served within a certain time (ms)
50% 102
66% 116
75% 127
80% 135
90% 177
95% 299
98% 1149
99% 1668
100% 4231 (longest request)

```