I was trying to play around with AB for performance recording/tracking in a new Rails 3 app. Since the app always require to be logged in, I had to do POST request to login. I was able to put the credentials in some text file as follows but the AuthenticityToken is giving the problem.
#login_data.txt
user_account%5Busername%5D=admin&user_account%5Bpassword%5D=adminhr
#AB command
ab -v4 -n100 -t5 -T 'application/x-www-form-urlencoded' -p login_data.txt http://nhc.lvh.me:3000/
#The log
Started POST "/" for 127.0.0.1 at 2011-02-15 11:13:37 +0545
Processing by CompaniesController#index as */*
Parameters: {"user_account"=>{"username"=>"admin", "password"=>"[FILTERED]"}}
Completed in 1ms
ActionController::InvalidAuthenticityToken (ActionController::InvalidAuthenticityToken):
Rendered /Users/millisami/.rvm/gems/ruby-1.9.2-p136/gems/actionpack-3.0.0/lib/action_dispatch/middleware/templates/rescues/_trace.erb (1.0ms)
Rendered /Users/millisami/.rvm/gems/ruby-1.9.2-p136/gems/actionpack-3.0.0/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (1194.0ms)
Rendered /Users/millisami/.rvm/gems/ruby-1.9.2-p136/gems/actionpack-3.0.0/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (1291.3ms)
The problem is how to pass or ignore that AuthenticityToken when using ab
?
Since it gets generated dynamically, can I store somewhere or is there other better solution?
What you could do is set up an environment aside from test and development. You could put a copy of development.rb environment and name it benchmark.rb.
Also put an entry on database.yml for the benchmark environment. You could copy the contents of the development entry for this.
And then in your code you could skip validation of authenticity token if the environment is benchmark. Now fire up rails s -e benchmark and perform your benchmark against that server.