Skip to content

Instantly share code, notes, and snippets.

@jmervine
Last active December 3, 2015 22:53
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 jmervine/ec366538115d0d9e4a66 to your computer and use it in GitHub Desktop.
Save jmervine/ec366538115d0d9e4a66 to your computer and use it in GitHub Desktop.
request something over and over
package main
import (
"flag"
"fmt"
"net/http"
"os"
"runtime"
"sync"
"time"
)
// limitations
// - only does get request
// - no custom headers
// - http only, no https
var (
concurent int
conns int
path string
wg sync.WaitGroup
)
func main() {
flag.IntVar(&conns, "n", 1, "number of total connections")
flag.IntVar(&concurent, "c", 1, "number of concurrent connections")
flag.StringVar(&path, "p", "", "endpoint to hit")
flag.Parse()
if path == "" {
fmt.Println("'-p' option is required, see '-help' for options")
os.Exit(1)
}
runtime.GOMAXPROCS(concurent)
fmt.Printf("args: -n %d -c %d -p %q\n", conns, concurent, path)
for i := 0; i < conns; i++ {
wg.Add(1)
go func(i int, path string) {
defer func() {
wg.Done()
}()
begin := time.Now()
r, e := http.Get(path)
if e != nil {
panic(e)
}
fmt.Printf("%s [response %q] took %v\n", path, r.Status, time.Since(begin))
}(i, path)
}
wg.Wait()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment