go: net/http: benchmarks fail on sierra with 'too many open files'

Sample run excerpt:

BenchmarkCookieString-8                      	 2000000	       900 ns/op	     384 B/op	       3 allocs/op
BenchmarkReadSetCookies-8                    	  500000	      3703 ns/op	     960 B/op	      17 allocs/op
BenchmarkReadCookies-8                       	  300000	      4948 ns/op	    2008 B/op	      16 allocs/op
BenchmarkHeaderWriteSubset-8                 	 3000000	       545 ns/op	       0 B/op	       0 allocs/op
BenchmarkReadRequestChrome-8                 	  500000	      3187 ns/op	 191.68 MB/s	    1809 B/op	      14 allocs/op
BenchmarkReadRequestCurl-8                   	 1000000	      1663 ns/op	  46.90 MB/s	     880 B/op	       9 allocs/op
BenchmarkReadRequestApachebench-8            	 1000000	      1670 ns/op	  49.10 MB/s	     883 B/op	       9 allocs/op
BenchmarkReadRequestSiege-8                  	 1000000	      2161 ns/op	  69.87 MB/s	     965 B/op	      11 allocs/op
BenchmarkReadRequestWrk-8                    	 1000000	      1682 ns/op	  23.78 MB/s	     832 B/op	       7 allocs/op
BenchmarkClientServer-8                      	   20000	     71011 ns/op	    4962 B/op	      67 allocs/op
BenchmarkClientServerParallel4-8             	  100000	     15276 ns/op	    4937 B/op	      64 allocs/op
BenchmarkClientServerParallel64-8            	2017/01/22 11:19:46 http: Accept error: accept tcp 127.0.0.1:60387: accept: too many open files; retrying in 5ms
2017/01/22 11:19:46 http: Accept error: accept tcp 127.0.0.1:60387: accept: too many open files; retrying in 5ms
2017/01/22 11:19:46 http: Accept error: accept tcp 127.0.0.1:60387: accept: too many open files; retrying in 10ms
2017/01/22 11:19:46 http: Accept error: accept tcp 127.0.0.1:60387: accept: too many open files; retrying in 20ms
2017/01/22 11:19:46 http: Accept error: accept tcp 127.0.0.1:60387: accept: too many open files; retrying in 40ms
2017/01/22 11:19:46 http: Accept error: accept tcp 127.0.0.1:60387: accept: too many open files; retrying in 80ms
2017/01/22 11:19:46 http: Accept error: accept tcp 127.0.0.1:60387: accept: too many open files; retrying in 5ms
   10000	    135870 ns/op	    4749 B/op	      63 allocs/op
--- BENCH: BenchmarkClientServerParallel64-8
	serve_test.go:4494: Get: Get http://127.0.0.1:60387: dial tcp 127.0.0.1:60387: socket: too many open files
	serve_test.go:4494: Get: Get http://127.0.0.1:60387: dial tcp 127.0.0.1:60387: socket: too many open files
	serve_test.go:4494: Get: Get http://127.0.0.1:60387: dial tcp 127.0.0.1:60387: socket: too many open files
	serve_test.go:4494: Get: Get http://127.0.0.1:60387: dial tcp 127.0.0.1:60387: socket: too many open files
	serve_test.go:4494: Get: Get http://127.0.0.1:60387: dial tcp 127.0.0.1:60387: socket: too many open files
	serve_test.go:4494: Get: Get http://127.0.0.1:60387: dial tcp 127.0.0.1:60387: socket: too many open files
	serve_test.go:4494: Get: Get http://127.0.0.1:60387: dial tcp 127.0.0.1:60387: socket: too many open files
	serve_test.go:4494: Get: Get http://127.0.0.1:60387: dial tcp 127.0.0.1:60387: socket: too many open files
	serve_test.go:4494: Get: Get http://127.0.0.1:60387: dial tcp 127.0.0.1:60387: socket: too many open files
	serve_test.go:4494: Get: Get http://127.0.0.1:60387: dial tcp 127.0.0.1:60387: socket: too many open files
	... [output truncated]
BenchmarkClientServerParallelTLS4-8          	  100000	     15757 ns/op	    4945 B/op	      64 allocs/op
BenchmarkClientServerParallelTLS64-8         	2017/01/22 11:19:49 http: Accept error: accept tcp 127.0.0.1:60976: accept: too many open files; retrying in 5ms
2017/01/22 11:19:49 http: Accept error: accept tcp 127.0.0.1:60976: accept: too many open files; retrying in 5ms
2017/01/22 11:19:49 http: Accept error: accept tcp 127.0.0.1:60976: accept: too many open files; retrying in 10ms
2017/01/22 11:19:49 http: Accept error: accept tcp 127.0.0.1:60976: accept: too many open files; retrying in 20ms
2017/01/22 11:19:49 http: Accept error: accept tcp 127.0.0.1:60976: accept: too many open files; retrying in 40ms
2017/01/22 11:19:49 http: Accept error: accept tcp 127.0.0.1:60976: accept: too many open files; retrying in 5ms
2017/01/22 11:19:50 http: Accept error: accept tcp 127.0.0.1:60976: accept: too many open files; retrying in 5ms
2017/01/22 11:19:50 http: Accept error: accept tcp 127.0.0.1:60976: accept: too many open files; retrying in 5ms
2017/01/22 11:19:50 http: Accept error: accept tcp 127.0.0.1:60976: accept: too many open files; retrying in 5ms
2017/01/22 11:19:50 http: Accept error: accept tcp 127.0.0.1:60976: accept: too many open files; retrying in 5ms
2017/01/22 11:19:50 http: Accept error: accept tcp 127.0.0.1:60976: accept: too many open files; retrying in 5ms
2017/01/22 11:19:50 http: Accept error: accept tcp 127.0.0.1:60976: accept: too many open files; retrying in 5ms
    5000	    475368 ns/op	    6175 B/op	      80 allocs/op
--- BENCH: BenchmarkClientServerParallelTLS64-8
	serve_test.go:4494: Get: Get https://127.0.0.1:60976: dial tcp 127.0.0.1:60976: socket: too many open files
	serve_test.go:4494: Get: Get https://127.0.0.1:60976: dial tcp 127.0.0.1:60976: socket: too many open files
	serve_test.go:4494: Get: Get https://127.0.0.1:60976: dial tcp 127.0.0.1:60976: socket: too many open files
	serve_test.go:4494: Get: Get https://127.0.0.1:60976: dial tcp 127.0.0.1:60976: socket: too many open files
	serve_test.go:4494: Get: Get https://127.0.0.1:60976: dial tcp 127.0.0.1:60976: socket: too many open files
	serve_test.go:4494: Get: Get https://127.0.0.1:60976: dial tcp 127.0.0.1:60976: socket: too many open files
	serve_test.go:4494: Get: Get https://127.0.0.1:60976: dial tcp 127.0.0.1:60976: socket: too many open files
	serve_test.go:4494: Get: Get https://127.0.0.1:60976: dial tcp 127.0.0.1:60976: socket: too many open files
	serve_test.go:4494: Get: Get https://127.0.0.1:60976: dial tcp 127.0.0.1:60976: socket: too many open files
	serve_test.go:4494: Get: Get https://127.0.0.1:60976: dial tcp 127.0.0.1:60976: socket: too many open files
	... [output truncated]
BenchmarkServer-8                            	   20000	     75523 ns/op	    2341 B/op	      21 allocs/op
BenchmarkClient-8                            	   20000	     72795 ns/op	    3351 B/op	      50 allocs/op

About this issue

  • Original URL
  • State: open
  • Created 7 years ago
  • Comments: 16 (10 by maintainers)

Most upvoted comments

I’ve seen this too recently (same output as josharian above). Errors on all the BenchmarkClientServerParallel tests, most often on BenchmarkClientServerParallel64.

You can raise the file limit with ulimit (for current session), but then I see a different error:

Ada:http kenny$ ulimit -n 10000
Ada:http kenny$ ulimit -a
core file size          (blocks, -c) 0
data seg size           (kbytes, -d) unlimited
file size               (blocks, -f) unlimited
max locked memory       (kbytes, -l) unlimited
max memory size         (kbytes, -m) unlimited
open files                      (-n) 10000
pipe size            (512 bytes, -p) 1
stack size              (kbytes, -s) 8192
cpu time               (seconds, -t) unlimited
max user processes              (-u) 709
virtual memory          (kbytes, -v) unlimited
Ada:http kenny$ go test -bench=.
goos: darwin
goarch: amd64
pkg: net/http
BenchmarkCookieString-4                      	 1000000	      1103 ns/op	     384 B/op	       3 allocs/op
BenchmarkReadSetCookies-4                    	  500000	      3599 ns/op	     688 B/op	      11 allocs/op
BenchmarkReadCookies-4                       	  300000	      4672 ns/op	    2008 B/op	      16 allocs/op
BenchmarkHeaderWriteSubset-4                 	 2000000	       701 ns/op	       0 B/op	       0 allocs/op
BenchmarkReadRequestChrome-4                 	  500000	      3823 ns/op	 159.82 MB/s	    1808 B/op	      14 allocs/op
BenchmarkReadRequestCurl-4                   	 1000000	      2102 ns/op	  37.10 MB/s	     880 B/op	       9 allocs/op
BenchmarkReadRequestApachebench-4            	 1000000	      2012 ns/op	  40.75 MB/s	     883 B/op	       9 allocs/op
BenchmarkReadRequestSiege-4                  	 1000000	      2701 ns/op	  55.89 MB/s	     965 B/op	      11 allocs/op
BenchmarkReadRequestWrk-4                    	 1000000	      1434 ns/op	  27.88 MB/s	     832 B/op	       7 allocs/op
BenchmarkClientServer-4                      	   20000	     86044 ns/op	    4852 B/op	      64 allocs/op
BenchmarkClientServerParallel4-4             	   50000	     51470 ns/op	    7672 B/op	      74 allocs/op
BenchmarkClientServerParallel64-4            	    3000	    928726 ns/op	   11285 B/op	      88 allocs/op
--- BENCH: BenchmarkClientServerParallel64-4
	serve_test.go:4493: Get: Get http://127.0.0.1:61917: read tcp 127.0.0.1:62040->127.0.0.1:61917: read: connection reset by peer
	serve_test.go:4493: Get: Get http://127.0.0.1:61917: read tcp 127.0.0.1:62039->127.0.0.1:61917: read: connection reset by peer
	serve_test.go:4493: Get: Get http://127.0.0.1:61917: read tcp 127.0.0.1:62038->127.0.0.1:61917: read: connection reset by peer
	serve_test.go:4493: Get: Get http://127.0.0.1:61917: read tcp 127.0.0.1:62037->127.0.0.1:61917: read: connection reset by peer
	serve_test.go:4493: Get: Get http://127.0.0.1:61917: read tcp 127.0.0.1:62036->127.0.0.1:61917: read: connection reset by peer
	serve_test.go:4493: Get: Get http://127.0.0.1:61917: read tcp 127.0.0.1:62035->127.0.0.1:61917: read: connection reset by peer
	serve_test.go:4493: Get: Get http://127.0.0.1:61917: read tcp 127.0.0.1:62031->127.0.0.1:61917: read: connection reset by peer
	serve_test.go:4493: Get: Get http://127.0.0.1:61917: read tcp 127.0.0.1:62034->127.0.0.1:61917: read: connection reset by peer
	serve_test.go:4493: Get: Get http://127.0.0.1:61917: read tcp 127.0.0.1:62029->127.0.0.1:61917: read: connection reset by peer
	serve_test.go:4493: Get: Get http://127.0.0.1:61917: read tcp 127.0.0.1:62033->127.0.0.1:61917: read: connection reset by peer
	... [output truncated]
BenchmarkClientServerParallelTLS4-4          	2017/03/17 09:03:38 http: TLS handshake error from 127.0.0.1:63863: read tcp 127.0.0.1:63405->127.0.0.1:63863: use of closed file or network connection
2017/03/17 09:03:39 http: TLS handshake error from 127.0.0.1:63354: read tcp 127.0.0.1:63865->127.0.0.1:63354: use of closed file or network connection
2017/03/17 09:03:39 http: TLS handshake error from 127.0.0.1:63360: read tcp 127.0.0.1:63865->127.0.0.1:63360: use of closed file or network connection
    5000	    273600 ns/op	   21305 B/op	     228 allocs/op
BenchmarkClientServerParallelTLS64-4         	    2000	    547983 ns/op	   48283 B/op	     488 allocs/op
--- BENCH: BenchmarkClientServerParallelTLS64-4
	serve_test.go:4493: Get: Get https://127.0.0.1:63468: read tcp 127.0.0.1:63513->127.0.0.1:63468: read: connection reset by peer
	serve_test.go:4493: Get: Get https://127.0.0.1:63468: read tcp 127.0.0.1:63516->127.0.0.1:63468: read: connection reset by peer
	serve_test.go:4493: Get: Get https://127.0.0.1:63468: read tcp 127.0.0.1:63515->127.0.0.1:63468: read: connection reset by peer
	serve_test.go:4493: Get: Get https://127.0.0.1:63468: read tcp 127.0.0.1:63517->127.0.0.1:63468: read: connection reset by peer
	serve_test.go:4493: Get: Get https://127.0.0.1:63468: read tcp 127.0.0.1:63518->127.0.0.1:63468: read: connection reset by peer
	serve_test.go:4493: Get: Get https://127.0.0.1:63468: read tcp 127.0.0.1:63520->127.0.0.1:63468: read: connection reset by peer
	serve_test.go:4493: Get: Get https://127.0.0.1:63468: read tcp 127.0.0.1:63519->127.0.0.1:63468: read: connection reset by peer
	serve_test.go:4493: Get: Get https://127.0.0.1:63468: read tcp 127.0.0.1:63521->127.0.0.1:63468: read: connection reset by peer
	serve_test.go:4493: Get: Get https://127.0.0.1:63468: read tcp 127.0.0.1:63522->127.0.0.1:63468: read: connection reset by peer
	serve_test.go:4493: Get: Get https://127.0.0.1:63468: read tcp 127.0.0.1:63524->127.0.0.1:63468: read: connection reset by peer
	... [output truncated]
BenchmarkServer-4                            	   10000	    117595 ns/op	    2238 B/op	      20 allocs/op
BenchmarkClient-4                            	   10000	    102093 ns/op	    3349 B/op	      48 allocs/op
BenchmarkServerFakeConnNoKeepAlive-4         	  100000	     18730 ns/op	    4524 B/op	      44 allocs/op
BenchmarkServerFakeConnWithKeepAlive-4       	  100000	     14655 ns/op	    2439 B/op	      22 allocs/op
BenchmarkServerFakeConnWithKeepAliveLite-4   	  200000	      7824 ns/op	    1300 B/op	      12 allocs/op
BenchmarkServerHandlerTypeLen-4              	  200000	      9385 ns/op	    2119 B/op	      20 allocs/op
BenchmarkServerHandlerNoLen-4                	  200000	      8380 ns/op	    2087 B/op	      17 allocs/op
BenchmarkServerHandlerNoType-4               	  200000	      8227 ns/op	    2087 B/op	      18 allocs/op
BenchmarkServerHandlerNoHeader-4             	  200000	      6155 ns/op	    1300 B/op	      12 allocs/op
BenchmarkServerHijack-4                      	  100000	     24303 ns/op	   15968 B/op	      42 allocs/op
BenchmarkCloseNotifier-4                     	    2000	    675642 ns/op	    3316 B/op	      54 allocs/op
PASS
ok  	net/http	82.847s

Running the tests with b.SetParallelism(1) in benchmarkClientServerParallel seems to fix it, so presumably it’s some problem with running these tests in parallel.