I wrote a simple httpbenchmark script.

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.