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?

slhck
  • 235,242
ben
  • 691

6 Answers6

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.

slhck
  • 235,242
Miles
  • 679
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
    
Sun Liwen
  • 103
andy318
  • 581
  • 4
  • 4
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.

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
  • 51
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
esengineer
  • 217
  • 2
  • 7
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
  • 1,564
  • 8
  • 8