14

My rails application is running on thin server which i want to benchmark using apachebench

the command am using is

ab -n 1 -c 1 http://localhost:3001/welcome/search?query="doctor"&rad=5

But thin server is not taking this url.Its giving

!! Invalid Request

Can any one help me how to give the url such that thin accepts the url with query string

kshama
  • 1,637
  • 4
  • 18
  • 21

3 Answers3

30

apache benchmark wont resolve "localhost" out of the url. change it to 0.0.0.0 or 127.0.0.1 and quote the whole url to avoid problems with the ampersand. eg:

ab -n 1 -c 1 "http://0.0.0.0:3001/welcome/search?query=doctor&rad=5"
Steven Soroka
  • 19,404
  • 4
  • 52
  • 40
5

Your query string is not properly encoded. Remove the double quote. If it's needed, you need to send it like this,

ab -n 1 -c 1 http://localhost:3001/welcome/search?query=%22doctor%22&rad=5
ZZ Coder
  • 74,484
  • 29
  • 137
  • 169
  • yeah you were right.I removed double quote so Invalid request is resolved. NOw suppose my query is http://localhost:3001/welcome/search?query=%22medical%20college%22&rad=5 ,medical is taken but college is not considered, value 5 of rad is not taken by thin; i even tried with substituting & with %26 it didnt work. – kshama May 09 '10 at 13:39
  • 2
    & is interpredet as a shell parameter. You can put the whole URL in quotes and it will work: `ab -n 1 -c 1 "http://localhost:3001/welcome/search?query=%22doctor%22&rad=5"` – Tomas Markauskas May 09 '10 at 16:26
  • 1
    Apparently this doesn't work with ApacheBench2. I am trying the following: ab2 -n 8000 -c 100 "http://xxx.xx.xxx.xx:8000?jsonp=callbackFunction&articeUrl=http%3A%2F%2Fwww.cnn.com%2F2010%2FCRIME%2F08%2F30%2Fclemens.case%2Findex.html%2F" Getting an "invalid URL" error! – IgorGanapolsky Sep 01 '10 at 14:16
  • as pointed out the problem is the ampersand, the other answer (using double quotes around the url) works. – Benja Apr 30 '14 at 03:44
3

This was not working for me, though this line did work:

ab -n 1 -c 1 -B 127.0.0.1 "http://localhost:3001/some/stuff"

Mind the casing!

Joost Schepel
  • 626
  • 9
  • 21