Otherwise, the default HTTP server config may result in high latency, due to Nagle’s algorithm (on the server) and delayed ACK (on the client):
[1] https://www.extrahop.com/blog/tcp-nodelay-nagle-quickack-best-practices [2] https://eklitzke.org/the-caveats-of-tcp-nodelay
Without the fix, fetching a small block takes ~40ms (when connection keep-alive is enabled):
0$ ab -k -c 1 -n 100 http://localhost:8332/rest/block/00000000000002b5898f7cdc80d9c84e9747bc6b9388cc989971d443f05713ee.bin
1
2Server Software:
3Server Hostname: localhost
4Server Port: 8332
5
6Document Path: /rest/block/00000000000002b5898f7cdc80d9c84e9747bc6b9388cc989971d443f05713ee.bin
7Document Length: 25086 bytes
8
9Concurrency Level: 1
10Time taken for tests: 4.075 seconds
11Complete requests: 100
12Failed requests: 0
13Keep-Alive requests: 100
14Total transferred: 2519200 bytes
15HTML transferred: 2508600 bytes
16Requests per second: 24.54 [#/sec] (mean)
17Time per request: 40.747 [ms] (mean)
18Time per request: 40.747 [ms] (mean, across all concurrent requests)
19Transfer rate: 603.76 [Kbytes/sec] received
20
21Connection Times (ms)
22 min mean[+/-sd] median max
23Connect: 0 0 0.0 0 0
24Processing: 0 41 4.1 41 42
25Waiting: 0 0 0.1 0 1
26Total: 0 41 4.1 41 42
27
28Percentage of the requests served within a certain time (ms)
29 50% 41
30 66% 41
31 75% 41
32 80% 41
33 90% 42
34 95% 42
35 98% 42
36 99% 42
37 100% 42 (longest request)
With the fix, it takes ~0.2ms:
0$ ab -k -c 1 -n 1000 http://localhost:8332/rest/block/00000000000002b5898f7cdc80d9c84e9747bc6b9388cc989971d443f05713ee.bin
1
2Benchmarking localhost (be patient)
3Completed 100 requests
4Completed 200 requests
5Completed 300 requests
6Completed 400 requests
7Completed 500 requests
8Completed 600 requests
9Completed 700 requests
10Completed 800 requests
11Completed 900 requests
12Completed 1000 requests
13Finished 1000 requests
14
15
16Server Software:
17Server Hostname: localhost
18Server Port: 8332
19
20Document Path: /rest/block/00000000000002b5898f7cdc80d9c84e9747bc6b9388cc989971d443f05713ee.bin
21Document Length: 25086 bytes
22
23Concurrency Level: 1
24Time taken for tests: 0.194 seconds
25Complete requests: 1000
26Failed requests: 0
27Keep-Alive requests: 1000
28Total transferred: 25192000 bytes
29HTML transferred: 25086000 bytes
30Requests per second: 5147.05 [#/sec] (mean)
31Time per request: 0.194 [ms] (mean)
32Time per request: 0.194 [ms] (mean, across all concurrent requests)
33Transfer rate: 126625.50 [Kbytes/sec] received
34
35Connection Times (ms)
36 min mean[+/-sd] median max
37Connect: 0 0 0.0 0 0
38Processing: 0 0 0.0 0 0
39Waiting: 0 0 0.0 0 0
40Total: 0 0 0.0 0 0
41
42Percentage of the requests served within a certain time (ms)
43 50% 0
44 66% 0
45 75% 0
46 80% 0
47 90% 0
48 95% 0
49 98% 0
50 99% 0
51 100% 0 (longest request)