Skip to content

Instantly share code, notes, and snippets.

@zono
Last active June 7, 2018 04:46
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 zono/7193ed4c61c8a10784efb11661573081 to your computer and use it in GitHub Desktop.
Save zono/7193ed4c61c8a10784efb11661573081 to your computer and use it in GitHub Desktop.
package main
import (
"net/http"
"sync"
"log"
"time"
)
func main() {
url := "http://localhost:8081"
maxConnection := make(chan bool,2000)
wg := &sync.WaitGroup{}
count := 0
start := time.Now()
for maxRequest := 0; maxRequest < 2000; maxRequest ++{
wg.Add(1)
maxConnection <- true
go func() {
defer wg.Done()
resp, err := http.Get(url)
if err != nil {
return
}
defer resp.Body.Close()
count++
<-maxConnection
}()
}
wg.Wait()
end := time.Now()
log.Printf("%d count\n", count)
log.Printf("%f sec\n",(end.Sub(start)).Seconds())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment