Created
June 12, 2020 13:22
-
-
Save Hadyn/fe38087c74ac2d91e6c9e1b5b955f336 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 ( | |
"bytes" | |
"log" | |
"net/http" | |
"sync" | |
"time" | |
) | |
func main() { | |
for { | |
const N = 500 | |
start := time.Now() | |
var wg sync.WaitGroup | |
wg.Add(N) | |
for i := 0; i < N; i++ { | |
// id := i | |
go func() { | |
// log.Printf("Sending %d\n", id) | |
_, err := http.Post( | |
"https://us-central1-whimsical-wombat.cloudfunctions.net/adder", | |
"application/json", | |
bytes.NewBuffer([]byte(`{"lhs":5,"rhs":5}`)), | |
) | |
// log.Printf("Received %d\n", id) | |
if err != nil { | |
log.Fatal(err) | |
} | |
wg.Done() | |
}() | |
} | |
wg.Wait() | |
log.Printf("%d took %v, sleeping\n", N, time.Now().Sub(start)) | |
time.Sleep(500*time.Millisecond) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment