-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmilli.go
86 lines (63 loc) · 1.59 KB
/
milli.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package main
import (
"fmt"
"os"
"time"
"sync"
"encoding/csv"
"github.com/parnurzeal/gorequest"
)
const workersCount = 24
func getUrlWorker(urlChan chan string) {
for url := range urlChan {
resp, body, errs := gorequest.New().Get(url).End()
_ = resp
_ = body
_ = errs
}
}
func main() {
// Record start time. Will be used for
// detemine elapsed time once completed
start := time.Now()
// Open Alexa CSV file
fmt.Println("Opening top-1m.csv file")
csvfile, err := os.Open("top-1m.csv")
if err != nil {
panic(err)
} else {
defer csvfile.Close()
}
// Read in CSV file
reader := csv.NewReader(csvfile)
reader.FieldsPerRecord = -1
fmt.Println(" Reading Entries (May take a few seconds)")
rawCSVdata, err := reader.ReadAll()
if err != nil {
panic(err)
} else {
fmt.Println(" Completed!")
}
// Start concurrency management
var wg sync.WaitGroup
urlChan := make(chan string)
wg.Add(workersCount)
for i := 0; i < workersCount; i++ {
go func() {
getUrlWorker(urlChan)
wg.Done()
}()
}
completed := 0
for _, each := range rawCSVdata {
url := fmt.Sprintf("http://%s", each[1])
urlChan <- url
completed++
fmt.Printf("Completed %s (%d)\n", url, completed)
}
close(urlChan)
wg.Wait()
// End summary
fmt.Println("Completed Tranactoins : ", completed)
fmt.Println("Time Elapsed : ", time.Since(start))
}