-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
71 lines (54 loc) · 1.52 KB
/
main.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
package main
import (
"database/sql"
"flag"
"log"
"os"
"sync"
"github.com/amir-yaghoobi/floodly/generator"
"github.com/amir-yaghoobi/floodly/reporter"
"github.com/amir-yaghoobi/floodly/user"
"github.com/amir-yaghoobi/floodly/user/repository"
_ "github.com/herenow/go-crate"
)
type runner struct {
generatorSrv generator.Generator
reportSrv reporter.Reporter
}
func (r *runner) setupWorkers(total int, concurrency int, results chan<- reporter.Result) {
var wg sync.WaitGroup
wg.Add(concurrency)
for i := 0; i < concurrency; i++ {
go r.generatorSrv.Generate(total/concurrency, results, &wg)
}
wg.Wait()
close(results)
}
func (r *runner) Run(total int, concurrency int) {
results := make(chan reporter.Result, total)
go r.setupWorkers(total, concurrency, results)
r.reportSrv.Analyze(results)
}
func main() {
dbUrl := flag.String("db", "http://localhost:4200/", "crateDB url")
total := flag.Int("total", 1000, "total number of inserts")
concurrency := flag.Int("concurrency", 1000, "number of concurrent workers")
dropTable := flag.Bool("drop-table", false, "drop database table")
flag.Parse()
db, err := sql.Open("crate", *dbUrl)
if err != nil {
log.Fatal(err)
}
userRepository := repository.NewCrateRepository(db)
err = userRepository.Migrate(*dropTable)
if err != nil {
log.Fatal(err)
}
genSrv := user.NewUserGenerator(*userRepository)
repSrv := reporter.NewStandardReporter(os.Stdout)
srvRunner := &runner{
generatorSrv: genSrv,
reportSrv: repSrv,
}
srvRunner.Run(*total, *concurrency)
}