-
Notifications
You must be signed in to change notification settings - Fork 0
/
get.go
51 lines (42 loc) · 760 Bytes
/
get.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// This stupid program just tests download concurrency.
package main
import (
"fmt"
"io"
"net/http"
"os"
"sync"
)
func downloadFile(filepath string, url string) (err error) {
out, err := os.Create(filepath)
if err != nil {
return err
}
defer out.Close()
resp, err := http.Get(url)
if err != nil {
return err
}
defer resp.Body.Close()
_, err = io.Copy(out, resp.Body)
if err != nil {
return err
}
return nil
}
func main() {
fmt.Printf("pid: %d\n", os.Getpid())
var wg sync.WaitGroup
for i := 0; i < 10000; i++ {
wg.Add(1)
go func() {
defer wg.Done()
err := downloadFile(fmt.Sprintf("/tmp/test-download-%d", i), "http://localhost:5555")
if err != nil {
panic(err)
}
fmt.Printf(".")
}()
}
wg.Wait()
}