|
1 | 1 | package main |
2 | 2 |
|
3 | 3 | import ( |
4 | | - "math/rand" |
5 | | - "strings" |
6 | | - "time" |
| 4 | + "runtime" |
7 | 5 |
|
8 | 6 | "github.com/negrel/configue" |
9 | 7 | ) |
10 | 8 |
|
11 | 9 | type Config struct { |
12 | | - TotalEvents uint64 `json:"total_events"` |
13 | | - BatchSize uint64 `json:"batch_size"` |
14 | | - Domains []string `json:"domains"` |
15 | | - FromDate time.Time `json:"from_date"` |
16 | | - CustomEventsRate float64 `json:"custom_events_rate"` |
17 | | - BounceRate float64 `json:"bounce_rate"` |
18 | | - ExitRate float64 `json:"exit_rate"` |
19 | | - MobileRate float64 `json:"mobile_rate"` |
20 | | - VisitorIdsRange uint64 `json:"visitor_ids_range"` |
21 | | - DirectTrafficRate float64 `json:"direct_traffic_rate"` |
| 10 | + BounceRate float64 `json:"bounce_rate"` |
| 11 | + CustomEventsRate float64 `json:"custom_events_rate"` |
| 12 | + DirectTrafficRate float64 `json:"direct_traffic_rate"` |
| 13 | + MobileRate float64 `json:"mobile_rate"` |
| 14 | + TotalSessions uint64 `json:"total_sessions"` |
| 15 | + PageViewsPerSession float64 `json:"view_per_session"` |
| 16 | + Workers uint64 `json:"workers"` |
22 | 17 | } |
23 | 18 |
|
24 | | -// RegisterOptions returns a Config parsed from command line. |
| 19 | +// RegisterOptions registers options in provided Figue. |
25 | 20 | func (c *Config) RegisterOptions(f *configue.Figue) { |
26 | | - domains := "localhost,mywebsite.localhost,foo.mywebsite.localhost" |
27 | | - var extraDomains int |
28 | | - var extraPaths int |
29 | | - |
30 | | - f.Uint64Var(&c.BatchSize, "batch.size", 40_000, "size of a batch") |
31 | | - f.Uint64Var(&c.TotalEvents, "total.events", 4_000_000, "number of events to generate") |
32 | | - f.StringVar(&domains, "domains", domains, "comma separated extra list of domains with events") |
33 | | - f.IntVar(&extraDomains, "extra.domains", 10, "number of random domains generated added to the domains list") |
34 | | - f.IntVar(&extraPaths, "extra.paths", 10, "number of random paths generated added to the paths list") |
35 | | - f.Float64Var(&c.CustomEventsRate, "custom.events-rate", 0.3, "custom events rate per viewed page") |
36 | 21 | f.Float64Var(&c.BounceRate, "bounce.rate", 0.56, "bounce rate") |
37 | | - f.Float64Var(&c.ExitRate, "exit.rate", 0.3, "exit rate when no bounce") |
38 | | - f.Float64Var(&c.MobileRate, "mobile.rate", 0.3, "mobile client rate") |
39 | | - f.Uint64Var(&c.VisitorIdsRange, "visitor.ids", 40_000, "range of visitor ids") |
| 22 | + f.Float64Var(&c.CustomEventsRate, "custom.events-rate", 0.3, "custom events rate per viewed page") |
40 | 23 | f.Float64Var(&c.DirectTrafficRate, "direct.rate", 0.5, "direct traffic rate against external traffic") |
41 | | - |
42 | | - c.FromDate = time.Now().AddDate(0, -6, 0) |
43 | | - |
44 | | - // Generate extra domains. |
45 | | - for i := 0; i < extraDomains; i++ { |
46 | | - c.Domains = append(c.Domains, randomString(alpha, 1)+randomString(alphaNum, rand.Intn(8))+randomItem([]string{".com", ".fr", ".eu", ".io", ".sh"})) |
47 | | - } |
48 | | - |
49 | | - // Generate extra paths |
50 | | - for range 1000 { |
51 | | - part := 1 + rand.Intn(8) |
52 | | - var path []string |
53 | | - for range part { |
54 | | - path = append(path, "/"+randomString(alphaNum, 1+rand.Intn(8))) |
55 | | - } |
56 | | - |
57 | | - pathnamesList = append(pathnamesList, strings.Join(path, "")) |
58 | | - } |
59 | | -} |
60 | | - |
61 | | -func (c Config) BatchCount() uint64 { |
62 | | - return c.TotalEvents / c.BatchSize |
| 24 | + f.Float64Var(&c.MobileRate, "mobile.rate", 0.3, "mobile client rate") |
| 25 | + f.Uint64Var(&c.TotalSessions, "total.sessions", 4_000_000, "number of sessions") |
| 26 | + f.Float64Var(&c.PageViewsPerSession, "views.per.session", 3.5, "average number of page view per session") |
| 27 | + f.Uint64Var(&c.Workers, "workers", min(1, uint64(runtime.NumCPU()/2)), "number of worker") |
63 | 28 | } |
0 commit comments