Apache Bench and POST data

emh picture emh · Sep 10, 2010 · Viewed 22.7k times · Source

i am trying to use apache bench to load test a create action in my rails application but ab doesn't appear to be sending the POST data - though it does correctly submit a POST and not a GET request.

this is the command i run:

ab -n 1 -p post -v 4 "http://oz01.zappos.net/registrations"

and this is the contents of the post file:

authenticity_token=M18KXwSOuIVbDPZOVQy5h8aSGoU159V9S5uV2lpsAI0

the rails logs show a POST request coming through but don't show any parameters being posted:

Started POST "/registrations" for 10.66.210.70 at Thu Sep 09 17:48:06 -0700 2010
  Processing by RegistrationsController#create as */*
Rendered registrations/new.html.erb within layouts/application (14.0ms)
Completed 200 OK in 24ms (Views: 14.6ms | ActiveRecord: 0.1ms)

whereas a POST request coming from a browser results in this log entry:

Started POST "/registrations" for 192.168.66.20 at Thu Sep 09 17:49:47 -0700 2010
  Processing by RegistrationsController#create as HTML
  Parameters: {"submit"=>"true", "authenticity_token"=>"AfNG0UoTbJXnxke2725efhYAoi3ogddMC7Uqu5mAui0=", "utf8"=>"\342\234\223", "registration"=>{"city"=>"", "address"=>"", "name"=>"", "zip"=>"", "optin"=>"0", "state"=>"", "email"=>""}}
Rendered registrations/new.html.erb within layouts/application (13.7ms)
Completed 200 OK in 24ms (Views: 14.3ms | ActiveRecord: 0.1ms)

and finally, this is what ab logs for the request:

---
POST /registrations HTTP/1.0
User-Agent: ApacheBench/2.0.40-dev
Host: oz01.zappos.net
Accept: */*
Content-length: 63
Content-type: text/plain


---

why is it not picking up the post data?

if the "post" file is not there then i get an error message saying it can't find the file so i know at very least it is finding the file...

Answer

k4ml picture k4ml · Jan 24, 2011

Maybe you need the -T option as stated in man ab:-

ab -n 1 -p post -v 4 -T application/x-www-form-urlencoded "http://oz01.zappos.net/registrations"

I tested with Django and it seem that Django don't really care about the content type header (it displayed the POSTed content whether I used -T or not) but Rails maybe want it.