Apache Bench test error on OS X: "apr_socket_recv: Connection reset by peer (54)"

56

21

I updated my MacBook Pro 13" to Lion a few weeks ago. I just found out that Apache Bench (apache2.2.19) is not working. It always shows this error, no matter what:

apr_socket_recv: Connection reset by peer (54)

I also did a clean install on my Mac Mini and it produced the same error.

How can I fix this?

ben

Posted 2011-08-16T11:14:46.743

Reputation: 661

I too am getting these.. I get them while testing a small Go web server, and with a Python Gevent server. – Justin – 2011-09-30T06:15:06.873

Answers

67

Note that if you use -r with Apache Bench, it won't exit on errors.

From the documentation:

-r
Don't exit on socket receive errors.

Miles

Posted 2011-08-16T11:14:46.743

Reputation: 679

Worked for me on OS X 10.9 – Willem – 2014-09-17T01:32:58.970

12It should except it's wrong. I just tried to run: ab -n 200 -c 20 -r http://localhost and got (god forbid a comment have newlines!)

`Test aborted after 10 failures

apr_socket_connect(): Operation already in progress (37) Total of 4 requests completed` – umassthrower – 2012-06-15T04:13:44.433

3unfortunately it still exits – DataGreed – 2012-09-05T22:46:04.740

47

This is due to a bug in the Apache software that's bundled with Lion. A more recent version of Apache (beta) fixes the problem. To fix ab, here are the steps:

  1. Download the latest version of Apache

    $ wget http://apache.mirrors.pair.com//httpd/httpd-2.3.16-beta.tar.bz2
    

If 2.3.16 is not available, go to http://apache.mirrors.pair.com/httpd and get the latest

  1. Install pcre (you need brew for this)

    $ brew install pcre
    
  2. Build Apache

    $ tar xzvf httpd-2.3.16-beta.tar.bz2
    $ cd httpd-2.3.16-beta
    $ ./configure
    $ make
    
  3. Overwrite the existing ab with the newly built one

    $ sudo cp support/ab /usr/sbin
    

andy318

Posted 2011-08-16T11:14:46.743

Reputation: 571

when I make http I get:

Undefined symbols: "_apr_file_link", referenced from: _post_rotate in rotatelogs.o ld: symbol(s) not found collect2: ld returned 1 exit status make[2]: *** [rotatelogs] Error 1 make[1]: *** [all-recursive] Error 1 make: *** [all-recursive] Error 1

Any tips how to solve that? – Jonathan – 2012-01-20T04:04:45.990

Is this still an issue in OSX 10.8.2? – Chris Wagner – 2012-10-25T23:28:30.690

3i am benchmarking a node.js helloworld app. At first i was receiving a Connection reset by peer (54) for any ab benchmarking. Then after doing the fix above, i could do ab -n 100 -c 100. Then i could do ab -n 200 -c 100. I could do ab -n 200 -c 150... When i take -c above -c 200, SOMETIMES it executes and sometimes it throws a Connection Reset by Peer (54) error. It's being non-deterministic. What to do? – Rakib – 2012-12-20T03:08:26.990

3

When running ./configure, take a look at this post if you run into configure: error: C compiler cannot create executables: http://stackoverflow.com/a/11712497/599391

– Chiubaka – 2013-08-16T01:45:34.037

5

Using the method of updating ab through homebrew at this link worked for me.

brew install 'https://raw.github.com/simonair/homebrew-dupes/e5177ef4fc82ae5246842e5a544124722c9e975b/ab.rb'
brew test ab

mmay

Posted 2011-08-16T11:14:46.743

Reputation: 51

@pinouchon although the script is now longer being maintained by the author, here is a new, working link: https://raw.githubusercontent.com/simonair/homebrew-dupes/e26f111d450d1a030515e1dde4e1dc4693efa78d/ab.rb (type: brew install "https://raw.githubusercontent.com/simonair/homebrew-dupes/e26f111d450d1a030515e1dde4e1dc4693efa78d/ab.rb")

– Matt3o12 – 2014-09-02T21:58:19.717

Error: ab: undefined method `sha1' for Formulary::FormulaNamespacebc6d3f6af42f9cfa51e2e726dcc9ff30::Ab:Class @Matt3o12 – Mark Ramotowski – 2018-10-20T01:19:50.657

2

Welcome to Super User! Whilst this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference.

– slhck – 2012-07-16T17:52:18.107

I'm getting: Error: Download failed: http://www.apache.org/dist/httpd/httpd-2.4.2.tar.bz2 – Benjamin Crouzier – 2013-07-27T20:35:10.373

4

Did you try using: 127.0.0.1 instead of localhost?

Also my ab fails if I don't write url with http:// in front.

user98645

Posted 2011-08-16T11:14:46.743

Reputation:

2

I had the same error with Mountain Lion ab v2.3, and was almost ready to install brew and the latest version of ab as instructed by one of the above answers. Before finally going that way I tried just adding the trailing slash.

user$ ab http://dl.cubrid.org
ab: invalid URL
Usage: ab [options] [http[s]://]hostname[:port]/path

In the above message pay attention to the required format of the input URL. Optional components are marked with square brackets, but notice that /path part seems to be not optional. So I assumed that if I'm testing the root domain, I should at least add the trailing slash, which really did the trick! I hope this helps to you, too.

user$ ab dl.cubrid.org/
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 dl.cubrid.org (be patient).....done


Server Software:        
Server Hostname:        dl.cubrid.org
Server Port:            80

Document Path:          /
Document Length:        13437 bytes

Concurrency Level:      1
Time taken for tests:   0.863 seconds
Complete requests:      1
Failed requests:        0
Write errors:           0
Total transferred:      13606 bytes
HTML transferred:       13437 bytes
Requests per second:    1.16 [#/sec] (mean)
Time per request:       862.778 [ms] (mean)
Time per request:       862.778 [ms] (mean, across all concurrent requests)
Transfer rate:          15.40 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:      207  207   0.0    207     207
Processing:   655  655   0.0    655     655
Waiting:      234  234   0.0    234     234
Total:        862  862   0.0    862     862

Eye

Posted 2011-08-16T11:14:46.743

Reputation: 177

0

A few things to test:

  • can you try disabling the firewall any seeing if that works?
  • enable web sharing and test localhost/ (make sure it works in a browser first)

If neither of those work can you open a terminal and

$ sudo opensnoop

then run the apache bench and post the output of the opensnoop terminal in the question. If none of that works you could try installing macports and then installing apache from there and seeing if that works as a work around(sort of lame).

My Air is on lion but the apache version is different(there was an update recently, have you already installed that?). I was able to verify ab does work for me:

$ ab -V
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/
$ uname -a
Darwin air.local 11.1.0 Darwin Kernel Version 11.1.0: Tue Jul 26 16:07:11 PDT 2011; root:xnu-1699.22.81~1/RELEASE_X86_64 x86_64
$ ab google.com/ 
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 google.com (be patient).....done


Server Software:        gws
Server Hostname:        google.com
Server Port:            80

Document Path:          /
Document Length:        219 bytes

Concurrency Level:      1
Time taken for tests:   4.130 seconds
Complete requests:      1
Failed requests:        0
Write errors:           0
Non-2xx responses:      1
Total transferred:      511 bytes
HTML transferred:       219 bytes
Requests per second:    0.24 [#/sec] (mean)
Time per request:       4130.343 [ms] (mean)
Time per request:       4130.343 [ms] (mean, across all concurrent requests)
Transfer rate:          0.12 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:     4119 4119   0.0   4119    4119
Processing:    11   11   0.0     11      11
Waiting:       11   11   0.0     11      11
Total:       4130 4130   0.0   4130    4130

polynomial

Posted 2011-08-16T11:14:46.743

Reputation: 1 424

Thanks for the reply @polynomial :)

ab google.com/ works for me too, try ab -n 1000 -c 1000 google.com/ – ben – 2011-08-31T07:35:02.747

@ben I remember having similar problem, and I remember it resolved by adding http:// ? I'm on windows machine now, will check when I get home. – None – 2012-07-20T14:30:13.840