59

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?

1
  • I too am getting these.. I get them while testing a small Go web server, and with a Python Gevent server.
    – Justin
    Sep 30, 2011 at 6:15

6 Answers 6

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.

3
  • 12
    It 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 Jun 15, 2012 at 4:13
  • 3
    unfortunately it still exits
    – DataGreed
    Sep 5, 2012 at 22:46
  • Worked for me on OS X 10.9
    – Willem
    Sep 17, 2014 at 1:32
48

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
    
4
  • 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
    Jan 20, 2012 at 4:04
  • Is this still an issue in OSX 10.8.2? Oct 25, 2012 at 23:28
  • 3
    i 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
    Dec 20, 2012 at 3:08
  • 3
    When running ./configure, take a look at this post if you run into configure: error: C compiler cannot create executables: stackoverflow.com/a/11712497/599391
    – Chiubaka
    Aug 16, 2013 at 1:45
6

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.

0
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
4
  • 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
    Jul 16, 2012 at 17:52
  • I'm getting: Error: Download failed: http://www.apache.org/dist/httpd/httpd-2.4.2.tar.bz2 Jul 27, 2013 at 20:35
  • @pinouchon although the script is now longer being maintained by the author, here is a new, working link: raw.githubusercontent.com/simonair/homebrew-dupes/… (type: brew install "https://raw.githubusercontent.com/simonair/homebrew-dupes/e26f111d450d1a030515e1dde4e1dc4693efa78d/ab.rb")
    – Matt3o12
    Sep 2, 2014 at 21:58
  • Error: ab: undefined method `sha1' for Formulary::FormulaNamespacebc6d3f6af42f9cfa51e2e726dcc9ff30::Ab:Class @Matt3o12 Oct 20, 2018 at 1:19
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
0
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
2
  • Thanks for the reply @polynomial :) ab google.com/ works for me too, try ab -n 1000 -c 1000 google.com/
    – ben
    Aug 31, 2011 at 7:35
  • @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.
    – user98645
    Jul 20, 2012 at 14:30

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .