Apache benchmark can only test a single url. I wrote a benchmark script using shell, supporting concurrent tests and specifying parameters. However, no statistics were made on the response time and ret code, it is applicable to precise statistics on servers.
#! /Bin/bash
Concurrency = 50
Workdirectory =/tmp/httpbenchmark_workdir/
Inputurlfile =
Function usage (){
Echo "Http Benchmark is used for sending http request in pararrel ."
Echo "Usage:./http_benchmark.sh [-c int] [-I string] [-w string]"
Echo "-c: Specify concurrency number. (Default: 50 )"
Echo "-I: Specify input file, if it's empty, then read from standard input. (Default :\"\")"
Echo "-w: Specify work directory. (Default: \"/tmp/httpbenchmark_workdir /\")"
}
Function thread_run (){
Fileno = $1
While read url
Do
Curl $ url-s-o/dev/null
Done <$ {workdirectory}/spilits _ $ {fileno}. lst
}
While getopts 'C: I: w: H' OPTION
Do
Case $ OPTION in
C) concurrency = "$ OPTARG"
;;
I) inputurlfile = "$ OPTARG"
;;
W) workdirectory = "$ OPTARG"
;;
H) usage
Exit 0
;;
?) Usage
Exit 1
;;
Esac
Done
Shift $(OPTIND-1 ))
Echo "Concurrency =$ {concurrency }"
Echo "Workdirectory =$ {workdirectory }"
Echo "InputUrlFile =$ {inputurlfile }"
Rm-rf $ workdirectory
Mkdir-p $ workdirectory
# Split url list.
Echo "Begin splitting urls ..."
Lineno = 0
If [-z $ inputurlfile]; then
While read line
Do
# As the 'split' command differs between different distribution, we do it manually.
If [-n $ line]; then
Fileno = 'expr $ lineno % $ concurrency'
Echo $ line >>$ {workdirectory}/spilits _ $ {fileno}. lst
Let lineno = $ lineno + 1
Fi
Done
Else
While read line
Do
# As the 'split' command differs between different distribution, we do it manually.
If [-n $ line]; then
Fileno = 'expr $ lineno % $ concurrency'
Echo $ line >>$ {workdirectory}/spilits _ $ {fileno}. lst
Let lineno = $ lineno + 1
Fi
Done <$ inputurlfile
Fi
Echo "Splitting done ."
# 'Curl' in pararrel.
For I in 'seq 1 $ concurrency'
Do
Let pos = $ I-1
Thread_run $ pos &
Done
# Wait
Echo "Waiting subprocesses joined .."
Wait
Echo "Benchmark finished! Please inspect server log ."
# Clean work directory.
Rm-rf $ workdirectory