func (this *Kateway) runBenchmark(zkzone *zk.ZkZone) { this.Ui.Info(fmt.Sprintf("benchmark[%s] zone[%s] %s.%s.%s %s", this.benchId, zkzone.Name(), this.benchApp, this.benchTopic, this.benchVer, this.benchPubEndpoint)) yes, _ := this.Ui.Ask("Are you sure to execute the benchmark? [Y/N]") if yes == "Y" { log.SetOutput(os.Stdout) stress.Flags.Round = 5 stress.Flags.Tick = 5 if this.benchmarkMaster != "" { stress.Flags.MasterAddr = stress.MasterAddr(this.benchmarkMaster) } stress.RunStress(this.benchPub) } }
func (this *Produce) Run(args []string) (exitCode int) { cmdFlags := flag.NewFlagSet("produce", flag.ContinueOnError) cmdFlags.Usage = func() { this.Ui.Output(this.Help()) } cmdFlags.StringVar(&this.zone, "z", ctx.ZkDefaultZone(), "") cmdFlags.StringVar(&this.cluster, "c", "", "") cmdFlags.StringVar(&this.topic, "t", "", "") cmdFlags.BoolVar(&this.ackAll, "ackall", false, "") cmdFlags.BoolVar(&this.benchMode, "bench", false, "") cmdFlags.StringVar(&this.benchmarkMaster, "master", "", "") if err := cmdFlags.Parse(args); err != nil { return 1 } if validateArgs(this, this.Ui). require("-c", "-t"). requireAdminRights("-t", "-bench"). invalid(args) { return 2 } zkzone := zk.NewZkZone(zk.DefaultConfig(this.zone, ctx.ZoneZkAddrs(this.zone))) zkcluster := zkzone.NewCluster(this.cluster) if this.benchMode { this.zkcluster = zkcluster stress.Flags.Round = 5 stress.Flags.Tick = 5 stress.Flags.C1 = 5 log.SetOutput(os.Stdout) if this.benchmarkMaster != "" { stress.Flags.MasterAddr = stress.MasterAddr(this.benchmarkMaster) } stress.RunStress(this.benchmarkProducer) return } msg, err := this.Ui.Ask("Input>") swallow(err) cf := sarama.NewConfig() cf.Producer.RequiredAcks = sarama.WaitForLocal if this.ackAll { cf.Producer.RequiredAcks = sarama.WaitForAll } p, err := sarama.NewSyncProducer(zkcluster.BrokerList(), cf) swallow(err) defer p.Close() partition, offset, err := p.SendMessage(&sarama.ProducerMessage{ Topic: this.topic, Value: sarama.StringEncoder(msg), }) if err != nil { this.Ui.Error(err.Error()) return 1 } this.Ui.Output(fmt.Sprintf("ok, partition:%d, offset:%d", partition, offset)) return }