Created
July 24, 2011 13:08
-
-
Save akrennmair/1102603 to your computer and use it in GitHub Desktop.
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
package main | |
import ( | |
"flag" | |
"fmt" | |
"os" | |
"time" | |
"http" | |
"runtime" | |
) | |
func main() { | |
runtime.GOMAXPROCS(4) | |
var rate *int = flag.Int("rate", 1, "requests per second") | |
var url *string = flag.String("url", "", "target URL") | |
flag.Parse() | |
if *url == "" { | |
fmt.Fprintf(os.Stderr, "error: empty URL\n") | |
os.Exit(1) | |
} | |
go func() { | |
for { | |
time.Sleep(int64(5000000000)) | |
fmt.Fprintf(os.Stderr, "# goroutines: %d\n", runtime.Goroutines()) | |
} | |
}() | |
for { | |
go doRequest(*url) | |
time.Sleep(int64(1000000000 / *rate)) | |
} | |
} | |
func doRequest(url string) { | |
c := new(http.Client) | |
r, err := c.Get(url) | |
if err != nil { | |
fmt.Fprintf(os.Stderr, "GET %s failed: %v\n", url, err) | |
return | |
} | |
r.Body.Close() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment