Skip to content

Instantly share code, notes, and snippets.

@akrennmair
Created July 24, 2011 13:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save akrennmair/1102603 to your computer and use it in GitHub Desktop.
Save akrennmair/1102603 to your computer and use it in GitHub Desktop.
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