Jungho Ahn | 48d4307 | 2015-02-23 18:50:27 -0800 | [diff] [blame] | 1 | // A simple command-line tool to run the benchmark server. |
| 2 | package main |
| 3 | |
| 4 | import ( |
| 5 | "flag" |
| 6 | "runtime" |
| 7 | "time" |
| 8 | |
| 9 | "v.io/v23" |
Jiri Simsa | 337af23 | 2015-02-27 14:36:46 -0800 | [diff] [blame] | 10 | "v.io/x/lib/vlog" |
Jungho Ahn | 48d4307 | 2015-02-23 18:50:27 -0800 | [diff] [blame] | 11 | |
Jiri Simsa | ffceefa | 2015-02-28 11:03:34 -0800 | [diff] [blame] | 12 | "v.io/x/ref/lib/signals" |
Matt Rosencrantz | 94502cf | 2015-03-18 09:43:44 -0700 | [diff] [blame] | 13 | "v.io/x/ref/profiles/internal/rpc/stress/internal" |
Jiri Simsa | ffceefa | 2015-02-28 11:03:34 -0800 | [diff] [blame] | 14 | _ "v.io/x/ref/profiles/static" |
Jungho Ahn | 48d4307 | 2015-02-23 18:50:27 -0800 | [diff] [blame] | 15 | ) |
| 16 | |
| 17 | var ( |
| 18 | duration = flag.Duration("duration", 0, "duration of the stress test to run; if zero, there is no limit.") |
| 19 | ) |
| 20 | |
| 21 | func main() { |
| 22 | runtime.GOMAXPROCS(runtime.NumCPU()) |
| 23 | |
| 24 | ctx, shutdown := v23.Init() |
| 25 | defer shutdown() |
| 26 | |
| 27 | server, ep, stop := internal.StartServer(ctx, v23.GetListenSpec(ctx)) |
| 28 | vlog.Infof("listening on %s", ep.Name()) |
| 29 | |
| 30 | var timeout <-chan time.Time |
| 31 | if *duration > 0 { |
| 32 | timeout = time.After(*duration) |
| 33 | } |
| 34 | select { |
| 35 | case <-timeout: |
| 36 | case <-stop: |
| 37 | case <-signals.ShutdownOnSignals(ctx): |
| 38 | } |
| 39 | |
| 40 | if err := server.Stop(); err != nil { |
| 41 | vlog.Fatalf("Stop() failed: %v", err) |
| 42 | } |
| 43 | vlog.Info("stopped.") |
| 44 | } |