Created
June 27, 2011 10:53
-
-
Save nono/1048668 to your computer and use it in GitHub Desktop.
Stressing my long-polling server
This file contains hidden or 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
| package main | |
| import ( | |
| "fmt" | |
| "http" | |
| "net" | |
| "os" | |
| "os/signal" | |
| "runtime" | |
| "strconv" | |
| ) | |
| var rawUrl string = "http://localhost:8000/" | |
| func Connect() { | |
| for { | |
| url, err := http.ParseURL(rawUrl) | |
| if err != nil { | |
| fmt.Println(err) | |
| return | |
| } | |
| var req http.Request | |
| req.Method = "GET" | |
| req.Header = http.Header{} | |
| req.URL = url | |
| dial, err := net.Dial("tcp", url.Host) | |
| if err != nil { | |
| fmt.Println(err) | |
| return | |
| } | |
| conn := http.NewClientConn(dial, nil) | |
| conn.Do(&req) | |
| conn.Close() | |
| } | |
| } | |
| func InstallSignalHandler() { | |
| for s := range signal.Incoming { | |
| if s == os.SIGINT { | |
| fmt.Printf("\nCtrl-C signalled\n") | |
| os.Exit(0) | |
| } | |
| } | |
| } | |
| func main() { | |
| nbConns := 1000 | |
| if len(os.Args) > 1 { | |
| c, err := strconv.Btoi64(os.Args[1], 0) | |
| if err != nil { | |
| fmt.Println(err) | |
| return | |
| } | |
| nbConns = int(c) | |
| } | |
| fmt.Printf("Opening %d connections\n", nbConns) | |
| for i := 0; i < nbConns; i++ { | |
| go Connect() | |
| runtime.Gosched() | |
| } | |
| InstallSignalHandler() | |
| } |
This file contains hidden or 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
| include $(GOROOT)/src/Make.inc | |
| TARG=go-bench | |
| GOFILES=go-bench.go | |
| include $(GOROOT)/src/Make.cmd |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment