Last active
June 7, 2018 04:46
-
-
Save zono/7193ed4c61c8a10784efb11661573081 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 ( | |
"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