Commit aaac5a11 authored by Elvis Pranskevichus's avatar Elvis Pranskevichus

Add golang echo server

parent f9aa2e26
......@@ -7,22 +7,26 @@ RUN DEBIAN_FRONTEND=noninteractive \
ENV LANG en_US.UTF-8
ENV WORKON_HOME /usr/local/python-venvs
ENV GOMAXPROCS 1
RUN mkdir -p /usr/local/python-venvs
RUN DEBIAN_FRONTEND=noninteractive \
apt-get update && apt-get install -y \
autoconf automake libtool build-essential \
python3 python3-pip git nodejs gosu
python3 python3-pip git nodejs golang gosu
RUN pip3 install vex
RUN vex --python=python3.5 -m bench pip install -U pip
RUN mkdir -p /var/lib/cache/pip
ADD servers /usr/src/servers
RUN go build /usr/src/servers/goecho.go
RUN vex bench pip --cache-dir=/var/lib/cache/pip \
install -r /usr/src/servers/requirements.txt
RUN vex bench pip freeze -r /usr/src/servers/requirements.txt
EXPOSE 25000
VOLUME /var/lib/cache
......
......@@ -42,8 +42,6 @@ if __name__ == '__main__':
help='message size in bytes')
parser.add_argument('--duration', '-T', default=30, type=int,
help='duration of test in seconds')
parser.add_argument('--times', default=1, type=int,
help='number of times to run the test')
parser.add_argument('--concurrency', default=3, type=int,
help='request concurrency')
parser.add_argument('--timeout', default=2, type=int,
......@@ -75,7 +73,7 @@ if __name__ == '__main__':
else:
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.settimeout(15)
sock.settimeout(timeout / 1000)
sock.connect(addr)
n = 0
......@@ -102,7 +100,6 @@ if __name__ == '__main__':
return n, latency_stats, min_latency, max_latency
TIMES = args.times
N = args.concurrency
DURATION = args.duration
......@@ -111,7 +108,7 @@ if __name__ == '__main__':
messages = 0
latency_stats = None
start = time.monotonic()
for _ in range(TIMES):
with futures.ProcessPoolExecutor(max_workers=N) as e:
fs = []
for _ in range(N):
......
......@@ -73,6 +73,12 @@ benchmarks = [{
'server': nodejs + ['/usr/src/servers/nodeecho.js'],
'server_address': tcp_address,
'client': tcp_client,
}, {
'name': 'tcpecho-golang',
'title': 'TCP echo server (golang)',
'server': ['/usr/src/servers/goecho'],
'server_address': tcp_address,
'client': tcp_client,
}, {
'name': 'tcpecho-asyncio-streams',
'title': 'TCP echo server (asyncio/streams)',
......
// Taken from https://gist.github.com/paulsmith/775764#file-echo-go
package main
import (
"net"
"strconv"
"fmt"
)
const PORT = 25000
func main() {
server, err := net.Listen("tcp", ":" + strconv.Itoa(PORT))
if server == nil {
panic("couldn't start listening: " + err.Error())
}
conns := clientConns(server)
for {
go handleConn(<-conns)
}
}
func clientConns(listener net.Listener) chan net.Conn {
ch := make(chan net.Conn)
i := 0
go func() {
for {
client, err := listener.Accept()
if client == nil {
fmt.Printf("couldn't accept: " + err.Error())
continue
}
i++
fmt.Printf("%d: %v <-> %v\n", i, client.LocalAddr(), client.RemoteAddr())
ch <- client
}
}()
return ch
}
func handleConn(client net.Conn) {
buf := make([]byte, 102400)
for {
reqLen, err := client.Read(buf)
if err != nil {
break
}
if reqLen > 0 {
client.Write(buf[:reqLen])
}
}
}
uvloop
curio
aiohttp
httptools
gevent
tornado
curio==0.1
aiohttp==0.21.5
gevent==1.1.1
tornado==4.3
Twisted==16.1.1
httptools==0.0.4
uvloop==0.4.7
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment