commit 3c826c123f7dec26d8d41560e6d6099aab4c1bbc Author: Nicolas MASSE Date: Fri Jul 24 11:53:21 2020 +0200 initial commit diff --git a/golang-fasthttp/.gitignore b/golang-fasthttp/.gitignore new file mode 100644 index 0000000..6969dda --- /dev/null +++ b/golang-fasthttp/.gitignore @@ -0,0 +1,2 @@ +golang-fasthttp + diff --git a/golang-fasthttp/build-and-deploy.sh b/golang-fasthttp/build-and-deploy.sh new file mode 100755 index 0000000..c59ae56 --- /dev/null +++ b/golang-fasthttp/build-and-deploy.sh @@ -0,0 +1,18 @@ +#!/bin/sh + +if [ $# -ne 1 ]; then + echo "Usage: $0 user@target.hostname" + exit 1 +fi + +set -xe + +#go generate +GOOS=linux GOARCH=arm GOARM=5 go build -o golang-fasthttp +ssh $1 start-stop-daemon -x /usr/local/bin/golang-fasthttp -b -K || true +ssh $1 mkdir -p /usr/local/bin/ +scp golang-fasthttp $1:/usr/local/bin/golang-fasthttp +ssh $1 start-stop-daemon -x /usr/local/bin/golang-fasthttp -b -S +ssh $1 pgrep golang-fasthttp +curl http://$1:8002/ + diff --git a/golang-fasthttp/go.mod b/golang-fasthttp/go.mod new file mode 100644 index 0000000..ad5e13e --- /dev/null +++ b/golang-fasthttp/go.mod @@ -0,0 +1,5 @@ +module itix.fr/golang-http-benchmark/golang-fasthttp + +go 1.14 + +require github.com/valyala/fasthttp v1.15.1 diff --git a/golang-fasthttp/main.go b/golang-fasthttp/main.go new file mode 100644 index 0000000..94ca2a8 --- /dev/null +++ b/golang-fasthttp/main.go @@ -0,0 +1,26 @@ +package main + +import ( + "fmt" + "time" + + "github.com/valyala/fasthttp" +) + +type HelloWorldHandler struct { +} + +func fastHTTPHandler(ctx *fasthttp.RequestCtx) { + fmt.Fprintln(ctx, "Hello, World!") +} + +func main() { + s := &fasthttp.Server{ + Handler: fastHTTPHandler, + ReadTimeout: 10 * time.Second, + WriteTimeout: 10 * time.Second, + IdleTimeout: 10 * time.Second, + } + fmt.Println("Listening for requests on port 8002...") + s.ListenAndServe(":8002") +} diff --git a/golang-net-http/.gitignore b/golang-net-http/.gitignore new file mode 100644 index 0000000..2f1a1d0 --- /dev/null +++ b/golang-net-http/.gitignore @@ -0,0 +1,2 @@ +golang-net-http + diff --git a/golang-net-http/build-and-deploy.sh b/golang-net-http/build-and-deploy.sh new file mode 100755 index 0000000..a1d8b5c --- /dev/null +++ b/golang-net-http/build-and-deploy.sh @@ -0,0 +1,17 @@ +#!/bin/sh + +if [ $# -ne 1 ]; then + echo "Usage: $0 user@target.hostname" + exit 1 +fi + +set -xe + +#go generate +GOOS=linux GOARCH=arm GOARM=5 go build -o golang-net-http +ssh $1 start-stop-daemon -x /usr/local/bin/golang-net-http -b -K || true +ssh $1 mkdir -p /usr/local/bin/ +scp golang-net-http $1:/usr/local/bin/golang-net-http +ssh $1 start-stop-daemon -x /usr/local/bin/golang-net-http -b -S +ssh $1 pgrep golang-net-http +curl http://$1:8001/ diff --git a/golang-net-http/go.mod b/golang-net-http/go.mod new file mode 100644 index 0000000..1dc512f --- /dev/null +++ b/golang-net-http/go.mod @@ -0,0 +1,3 @@ +module itix.fr/golang-http-benchmark/golang-net-http + +go 1.14 diff --git a/golang-net-http/main.go b/golang-net-http/main.go new file mode 100644 index 0000000..98c86ab --- /dev/null +++ b/golang-net-http/main.go @@ -0,0 +1,32 @@ +package main + +import ( + "fmt" + "log" + "net/http" + "time" +) + +type HelloWorldHandler struct { +} + +func (h *HelloWorldHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { + w.WriteHeader(http.StatusOK) + w.Write([]byte("Hello, World!")) +} + +func main() { + h := &HelloWorldHandler{} + + s := &http.Server{ + Addr: ":8001", + Handler: h, + ReadTimeout: 10 * time.Second, + ReadHeaderTimeout: 10 * time.Second, + WriteTimeout: 10 * time.Second, + MaxHeaderBytes: 1 << 20, + IdleTimeout: 10 * time.Second, + } + fmt.Println("Listening for requests on port 8001...") + log.Fatal(s.ListenAndServe()) +} diff --git a/jmeter/.gitignore b/jmeter/.gitignore new file mode 100644 index 0000000..e69198a --- /dev/null +++ b/jmeter/.gitignore @@ -0,0 +1,3 @@ +jmeter.log +results-* +report-* diff --git a/jmeter/golang-http-benchmark.jmx b/jmeter/golang-http-benchmark.jmx new file mode 100644 index 0000000..2548407 --- /dev/null +++ b/jmeter/golang-http-benchmark.jmx @@ -0,0 +1,243 @@ + + + + + + false + true + false + + + + + + + + + + server_hostname + seagate-goflex.itix.fr + = + + + scenario + ${__P(scenario,golang-net-http)} + = + + + + + + + + 5 + 0 + 10 + 120 + 10 + + + + false + -1 + + continue + + + + true + -1 + + + + false + true + false + + + + ${__jexl3("${scenario}" == "golang-net-http",)} + false + true + + + + + + + ${server_hostname} + 8001 + http + + / + GET + true + false + true + false + + HttpClient4 + + + + + + + ${__jexl3("${scenario}" == "golang-fasthttp",)} + false + true + + + + + + + ${server_hostname} + 8002 + http + + / + GET + true + false + true + false + + HttpClient4 + + + + + + + + + false + + saveConfig + + + true + true + true + + true + true + true + true + false + true + true + false + false + false + true + false + false + false + true + 0 + true + true + true + true + true + true + + + response-time.csv + 500 + false + + + + + false + false + + + + false + + saveConfig + + + true + true + true + + true + true + true + true + false + true + true + false + false + false + true + false + false + false + true + 0 + true + true + true + true + true + true + + + tps.csv + 1000 + false + + + + + false + false + + + + false + + saveConfig + + + true + true + true + + true + true + true + true + false + true + true + false + false + false + true + false + false + false + true + 0 + true + true + true + true + true + true + + + + + + + + diff --git a/jmeter/run.sh b/jmeter/run.sh new file mode 100755 index 0000000..ad0545b --- /dev/null +++ b/jmeter/run.sh @@ -0,0 +1,18 @@ +#!/bin/sh + +set -e # Do not continue if jmeter fails + +: ${JMETER:=jmeter} +export HEAP="-Xms1g -Xmx1g -XX:MaxMetaspaceSize=256m" +date="$(date +%F-%H-%M-%S)" + +for scenario in golang-net-http golang-fasthttp; do + echo + echo "================================================================================" + echo "Running scenario $scenario..." + echo "================================================================================" + echo + export JVM_ARGS="-Djmeter.reportgenerator.report_title=$scenario" + $JMETER -n -t golang-http-benchmark.jmx -l "results-$date-$scenario.csv" -e -o "report-$date-$scenario" -Jscenario=$scenario + sleep 2 +done diff --git a/jmeter/user.properties b/jmeter/user.properties new file mode 100644 index 0000000..697a8eb --- /dev/null +++ b/jmeter/user.properties @@ -0,0 +1,10 @@ +# Aggregate metrics over the second (rather than the minute) +jmeter.reportgenerator.overall_granularity=1000 + +# Keep alive timeouts +httpclient4.idletimeout=10000 +httpclient4.time_to_live=60000 +httpclient4.validate_after_inactivity=10000 + +# Enable this if your HTTP sampler is not enclosed in a loop +#httpclient.reset_state_on_thread_group_iteration=false