Skip to content

Instantly share code, notes, and snippets.

@arkan
Last active September 1, 2015 15:27
Show Gist options
  • Save arkan/3f344293fd79560a96c4 to your computer and use it in GitHub Desktop.
Save arkan/3f344293fd79560a96c4 to your computer and use it in GitHub Desktop.
package main
import (
"os"
"github.com/mailgun/oxy/forward"
"github.com/mailgun/oxy/roundrobin"
"github.com/mailgun/oxy/testutils"
"github.com/mailgun/oxy/utils"
"net/http"
)
func main() {
l := utils.NewFileLogger(os.Stdout, utils.INFO)
fwd, _ := forward.New(forward.Logger(l))
lb, _ := roundrobin.New(fwd)
lb.UpsertServer(testutils.ParseURI("http://127.0.0.1:8082"))
handler := http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
lb.ServeHTTP(w, req)
})
s := &http.Server{
Addr: ":8081",
Handler: handler,
}
go runTestServer()
panic(s.ListenAndServe())
}
func runTestServer() {
handler := http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
w.WriteHeader(200)
w.Write([]byte("Status: OK"))
})
s := &http.Server{
Addr: ":8082",
Handler: handler,
}
panic(s.ListenAndServe())
}
FO: 2015/09/01 17:26:17.334033 Round trip: http://127.0.0.1:8082, code: 200, duration: 39.66876ms
INFO: 2015/09/01 17:26:17.333794 Round trip: http://127.0.0.1:8082, code: 200, duration: 34.871113ms
INFO: 2015/09/01 17:26:17.334033 Round trip: http://127.0.0.1:8082, code: 200, duration: 29.365342ms
INFO: 2015/09/01 17:26:17.334216 Round trip: http://127.0.0.1:8082, code: 200, duration: 29.233768ms
INFO: 2015/09/01 17:26:17.333788 Round trip: http://127.0.0.1:8082, code: 200, duration: 34.799078ms
INFO: 2015/09/01 17:26:17.336525 Round trip: http://127.0.0.1:8082, code: 200, duration: 22.383779ms
INFO: 2015/09/01 17:26:17.336678 Round trip: http://127.0.0.1:8082, code: 200, duration: 36.675157ms
INFO: 2015/09/01 17:26:17.336688 Round trip: http://127.0.0.1:8082, code: 200, duration: 32.73832ms
INFO: 2015/09/01 17:26:17.336746 Round trip: http://127.0.0.1:8082, code: 200, duration: 18.014524ms
INFO: 2015/09/01 17:26:17.336785 Round trip: http://127.0.0.1:8082, code: 200, duration: 25.042251ms
INFO: 2015/09/01 17:26:17.336823 Round trip: http://127.0.0.1:8082, code: 200, duration: 31.357318ms
INFO: 2015/09/01 17:26:17.336968 Round trip: http://127.0.0.1:8082, code: 200, duration: 25.274102ms
INFO: 2015/09/01 17:26:17.336992 Round trip: http://127.0.0.1:8082, code: 200, duration: 18.374858ms
INFO: 2015/09/01 17:26:17.337082 Round trip: http://127.0.0.1:8082, code: 200, duration: 36.44443ms
....
and after some time, the program slow down, and start to throw errors
INFO: 2015/09/01 17:26:24.740251 Round trip: http://127.0.0.1:8082, code: 200, duration: 319.556018ms
INFO: 2015/09/01 17:26:24.740307 Round trip: http://127.0.0.1:8082, code: 200, duration: 319.598573ms
INFO: 2015/09/01 17:26:24.740350 Round trip: http://127.0.0.1:8082, code: 200, duration: 319.676137ms
ERR: 2015/09/01 17:26:24.762120 Error forwarding to http://127.0.0.1:8082, err: dial tcp 127.0.0.1:8082: can't assign requested address
ERR: 2015/09/01 17:26:24.762915 Error forwarding to http://127.0.0.1:8082, err: dial tcp 127.0.0.1:8082: can't assign requested address
ERR: 2015/09/01 17:26:24.762962 Error forwarding to http://127.0.0.1:8082, err: dial tcp 127.0.0.1:8082: can't assign requested address
ERR: 2015/09/01 17:26:24.777944 Error forwarding to http://127.0.0.1:8082, err: dial tcp 127.0.0.1:8082: can't assign requested address
INFO: 2015/09/01 17:26:24.793968 Round trip: http://127.0.0.1:8082, code: 200, duration: 373.327045ms
INFO: 2015/09/01 17:26:24.794171 Round trip: http://127.0.0.1:8082, code: 200, duration: 373.529171ms
INFO: 2015/09/01 17:26:24.814853 Round trip: http://127.0.0.1:8082, code: 200, duration: 315.535383ms
INFO: 2015/09/01 17:26:24.815035 Round trip: http://127.0.0.1:8082, code: 200, duration: 315.715131ms
INFO: 2015/09/01 17:26:24.832057 Round trip: http://127.0.0.1:8082, code: 200, duration: 372.995385ms
INFO: 2015/09/01 17:26:24.832224 Round trip: http://127.0.0.1:8082, code: 200, duration: 372.886037ms
INFO: 2015/09/01 17:26:24.832344 Round trip: http://127.0.0.1:8082, code: 200, duration: 411.615239ms
ERR: 2015/09/01 17:26:24.778090 Error forwarding to http://127.0.0.1:8082, err: dial tcp 127.0.0.1:8082: can't assign requested address
ERR: 2015/09/01 17:26:24.778843 Error forwarding to http://127.0.0.1:8082, err: dial tcp 127.0.0.1:8082: can't assign requested address
ERR: 2015/09/01 17:26:24.778854 Error forwarding to http://127.0.0.1:8082, err: dial tcp 127.0.0.1:8082: can't assign requested address
ERR: 2015/09/01 17:26:24.832045 Error forwarding to http://127.0.0.1:8082, err: dial tcp 127.0.0.1:8082: can't assign requested address
ERR: 2015/09/01 17:26:24.832620 Error forwarding to http://127.0.0.1:8082, err: dial tcp 127.0.0.1:8082: can't assign requested address
ERR: 2015/09/01 17:26:24.832630 Error forwarding to http://127.0.0.1:8082, err: dial tcp 127.0.0.1:8082: can't assign requested address
ERR: 2015/09/01 17:26:24.833311 Error forwarding to http://127.0.0.1:8082, err: dial tcp 127.0.0.1:8082: can't assign requested address
ERR: 2015/09/01 17:26:24.833379 Error forwarding to http://127.0.0.1:8082, err: dial tcp 127.0.0.1:8082: can't assign requested address
ERR: 2015/09/01 17:26:24.835191 Error forwarding to http://127.0.0.1:8082, err: dial tcp 127.0.0.1:8082: can't assign requested address
ERR: 2015/09/01 17:26:24.837629 Error forwarding to http://127.0.0.1:8082, err: dial tcp 127.0.0.1:8082: can't assign requested address
ERR: 2015/09/01 17:26:24.839621 Error forwarding to http://127.0.0.1:8082, err: dial tcp 127.0.0.1:8082: can't assign requested address
ERR: 2015/09/01 17:26:24.840037 Error forwarding to http://127.0.0.1:8082, err: dial tcp 127.0.0.1:8082: can't assign requested address
ERR: 2015/09/01 17:26:24.843441 Error forwarding to http://127.0.0.1:8082, err: dial tcp 127.0.0.1:8082: can't assign requested address
ERR: 2015/09/01 17:26:24.849245 Error forwarding to http://127.0.0.1:8082, err: dial tcp 127.0.0.1:8082: can't assign requested address
ERR: 2015/09/01 17:26:24.849412 Error forwarding to http://127.0.0.1:8082, err: dial tcp 127.0.0.1:8082: can't assign requested address
ERR: 2015/09/01 17:26:24.852523 Error forwarding to http://127.0.0.1:8082, err: dial tcp 127.0.0.1:8082: can't assign requested address
ERR: 2015/09/01 17:26:24.854025 Error forwarding to http://127.0.0.1:8082, err: dial tcp 127.0.0.1:8082: can't assign requested address
ERR: 2015/09/01 17:26:24.854142 Error forwarding to http://127.0.0.1:8082, err: dial tcp 127.0.0.1:8082: can't assign requested address
ERR: 2015/09/01 17:26:24.854219 Error forwarding to http://127.0.0.1:8082, err: dial tcp 127.0.0.1:8082: can't assign requested address
ERR: 2015/09/01 17:26:24.861358 Error forwarding to http://127.0.0.1:8082, err: dial tcp 127.0.0.1:8082: can't assign requested address
go get -u github.com/mailgun/oxy/...
GOMAXPROCS=4 go run main.go
And in another terminal: wrk -c 50 -d 60s -t 10 http://localhost:8081
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment