forked from tidwall/evio
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
305 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
bin/ | ||
socket |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
## evio benchmark tools | ||
|
||
Required: | ||
|
||
- [wrk](https://github.com/wg/wrk) for HTTP | ||
- [tcpkali](https://github.com/machinezone/tcpkali) for Echo | ||
- [Redis](http://redis.io) for Redis | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#!/bin/bash | ||
|
||
#set -e | ||
|
||
echo "" | ||
echo "--- ECHO START ---" | ||
echo "" | ||
|
||
cd $(dirname "${BASH_SOURCE[0]}") | ||
function cleanup { | ||
echo "--- ECHO DONE ---" | ||
kill $(jobs -rp) | ||
wait $(jobs -rp) 2>/dev/null | ||
} | ||
trap cleanup EXIT | ||
|
||
mkdir -p bin | ||
|
||
$(pkill net-echo-server || printf "") | ||
$(pkill evio-echo-server || printf "") | ||
|
||
function gobench { | ||
printf "\e[96m[%s]\e[0m\n" $1 | ||
if [ "$3" != "" ]; then | ||
go build -o $2 $3 | ||
fi | ||
$2 -port $4 & | ||
sleep 1 | ||
echo "Sending 6 byte packets, 50 connections" | ||
nl=$'\r\n' | ||
tcpkali -c 50 -m "PING{$nl}" 127.0.0.1:$4 | ||
echo "--- DONE ---" | ||
echo "" | ||
} | ||
|
||
gobench "net/echo" bin/net-echo-server net-echo-server/main.go 5001 | ||
gobench "evio/echo" bin/evio-echo-server ../examples/echo-server/main.go 5002 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#!/bin/bash | ||
|
||
#set -e | ||
|
||
echo "" | ||
echo "--- HTTP START ---" | ||
echo "" | ||
|
||
cd $(dirname "${BASH_SOURCE[0]}") | ||
function cleanup { | ||
echo "--- HTTP DONE ---" | ||
kill $(jobs -rp) | ||
wait $(jobs -rp) 2>/dev/null | ||
} | ||
trap cleanup EXIT | ||
|
||
mkdir -p bin | ||
$(pkill net-http-server || printf "") | ||
$(pkill fasthttp-server || printf "") | ||
$(pkill iris-server || printf "") | ||
$(pkill evio-http-server || printf "") | ||
|
||
function gobench { | ||
printf "\e[96m[%s]\e[0m\n" $1 | ||
if [ "$3" != "" ]; then | ||
go build -o $2 $3 | ||
fi | ||
$2 -port $4 & | ||
sleep 1 | ||
echo "Using 4 threads, 50 connections, 10 seconds" | ||
wrk -t4 -c50 -d10 http://127.0.0.1:$4 | ||
echo "--- DONE ---" | ||
echo "" | ||
} | ||
|
||
gobench "net/http" bin/net-http-server net-http-server/main.go 8081 | ||
gobench "iris" bin/iris-server iris-server/main.go 8082 | ||
gobench "fasthttp" bin/fasthttp-server fasthttp-server/main.go 8083 | ||
gobench "evio/http" bin/evio-http-server ../examples/http-server/main.go 8084 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#!/bin/bash | ||
|
||
#set -e | ||
|
||
echo "" | ||
echo "--- REDIS START ---" | ||
echo "" | ||
|
||
|
||
cd $(dirname "${BASH_SOURCE[0]}") | ||
function cleanup { | ||
echo "--- REDIS DONE ---" | ||
kill $(jobs -rp) | ||
wait $(jobs -rp) 2>/dev/null | ||
} | ||
trap cleanup EXIT | ||
|
||
mkdir -p bin | ||
|
||
$(pkill redis-server || printf "") | ||
$(pkill evio-redis-server || printf "") | ||
|
||
function gobench { | ||
printf "\e[96m[%s]\e[0m\n" $1 | ||
if [ "$3" != "" ]; then | ||
go build -o $2 $3 | ||
fi | ||
$2 --port $4 & | ||
sleep 1 | ||
echo "Sending pings, 50 connections, 1 packet pipeline" | ||
redis-benchmark -p $4 -t ping -q -P 1 | ||
echo "Sending pings, 50 connections, 10 packet pipeline" | ||
redis-benchmark -p $4 -t ping -q -P 10 | ||
echo "Sending pings, 50 connections, 20 packet pipeline" | ||
redis-benchmark -p $4 -t ping -q -P 20 | ||
echo "--- DONE ---" | ||
echo "" | ||
} | ||
gobench "real/redis" redis-server "" 6392 | ||
gobench "evio/redis" bin/evio-redis-server ../examples/redis-server/main.go 6393 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#!/bin/bash | ||
|
||
#set -e | ||
|
||
cd $(dirname "${BASH_SOURCE[0]}") | ||
|
||
./bench-http.sh | ||
./bench-echo.sh | ||
./bench-redis.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Copyright 2017 Joshua J Baker. All rights reserved. | ||
// Use of this source code is governed by an MIT-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package main | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
"log" | ||
|
||
"github.com/valyala/fasthttp" | ||
) | ||
|
||
var res string | ||
|
||
func main() { | ||
var port int | ||
flag.IntVar(&port, "port", 8080, "server port") | ||
flag.Parse() | ||
go log.Printf("http server started on port %d", port) | ||
err := fasthttp.ListenAndServe(fmt.Sprintf(":%d", port), | ||
func(c *fasthttp.RequestCtx) { | ||
_, werr := c.WriteString("Hello World!\r\n") | ||
if werr != nil { | ||
log.Fatal(werr) | ||
} | ||
}) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Copyright 2017 Joshua J Baker. All rights reserved. | ||
// Use of this source code is governed by an MIT-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package main | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
"log" | ||
|
||
"github.com/kataras/iris" | ||
) | ||
|
||
var res string | ||
|
||
func main() { | ||
var port int | ||
flag.IntVar(&port, "port", 8080, "server port") | ||
flag.Parse() | ||
go log.Printf("http server started on port %d", port) | ||
app := iris.New() | ||
app.Get("/", func(ctx iris.Context) { | ||
ctx.WriteString("Hello World!\r\n") | ||
}) | ||
err := app.Run(iris.Addr(fmt.Sprintf(":%d", port))) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Copyright 2017 Joshua J Baker. All rights reserved. | ||
// Use of this source code is governed by an MIT-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package main | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
"log" | ||
"net" | ||
) | ||
|
||
func main() { | ||
var port int | ||
flag.IntVar(&port, "port", 5000, "server port") | ||
flag.Parse() | ||
ln, err := net.Listen("tcp4", fmt.Sprintf(":%d", port)) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
defer ln.Close() | ||
log.Printf("echo server started on port %d", port) | ||
var id int | ||
for { | ||
conn, err := ln.Accept() | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
id++ | ||
go func(id int, conn net.Conn) { | ||
defer func() { | ||
//log.Printf("closed: %d", id) | ||
conn.Close() | ||
}() | ||
//log.Printf("opened: %d: %s", id, conn.RemoteAddr().String()) | ||
var packet [0xFFF]byte | ||
for { | ||
n, err := conn.Read(packet[:]) | ||
if err != nil { | ||
return | ||
} | ||
conn.Write(packet[:n]) | ||
} | ||
}(id, conn) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Copyright 2017 Joshua J Baker. All rights reserved. | ||
// Use of this source code is governed by an MIT-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package main | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
"log" | ||
"net/http" | ||
"strings" | ||
) | ||
|
||
var res string | ||
|
||
func main() { | ||
var port int | ||
var aaaa bool | ||
flag.IntVar(&port, "port", 8080, "server port") | ||
flag.BoolVar(&aaaa, "aaaa", false, "aaaaa....") | ||
flag.Parse() | ||
if aaaa { | ||
res = strings.Repeat("a", 1024) | ||
} else { | ||
res = "Hello World!\r\n" | ||
} | ||
log.Printf("http server started on port %d", port) | ||
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { | ||
w.Write([]byte(res)) | ||
}) | ||
err := http.ListenAndServe(fmt.Sprintf(":%d", port), nil) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.