Benchmark

Benchmark is as simple as:

redis-benchmark -p 8888 -t ping -n 10000

Redis

Goroutines - Golang

Code:

package main

import (
    _ "bufio"
    "net"
)

var PONG = []byte("+PONG\r\n")

func proxy(conn net.Conn) {
    buf := make([]byte, 100)

    for {
        _, err := conn.Read(buf)
        if err != nil {
            break
        }

        _, err = conn.Write(PONG)
        if err != nil {
            break
        }
    }

    conn.Close()
}

func main() {
    listener, err := net.Listen("tcp", "localhost:8888")
    if err != nil {
        panic(err)
    }

    for {
        conn, err := listener.Accept()
        if err != nil {
            panic(err)
        }
        go proxy(conn)
    }
}

Gevent - Python

import gevent
from gevent import socket


PONG = '+PONG\r\n'


def proxy(conn):
    while 1:
        s = conn[0]
        try:
            s.recv(100)
        except Exception:
            break

        try:
            s.send(PONG)
        except Exception:
            break


def main():
    s = socket.socket()
    s.bind(('', 8888))
    s.listen(1)

    while 1:
        conn = s.accept()
        gevent.spawn(proxy, conn)


if __name__ == '__main__':
    main()