Beispiel #1
0
func main() {
	switch mode {
	case "pub":
		stress.RunStress(benchmarkPub)

	case "sub":
		stress.RunStress(benchmarkSub)

	case "help":
		fmt.Println("Pub: go run pubsub.go -c1 10 -step 5 -mode pub -appid 73 -key xxxx -msgfile msg -ep pub.sit.mycorp.com:9191 -topic risk_beacon_test")
		fmt.Println("Sub: go run pubsub.go -c1 1 -c2 1 -mode sub -appid app2 -subappid app1 -key xxx -ep sub.sit.mycorp.com:9192 -topic risk_beacon_test -group bench_go -debug")

	}

}
Beispiel #2
0
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)
	}

}
Beispiel #3
0
func main() {
	flag.StringVar(&addr, "addr", "http://localhost:9191/", "kateway pub addr, must start with http or https")
	flag.IntVar(&loops, "loops", 1000, "loops in each thread")
	flag.IntVar(&sz, "size", 200, "each pub message size")
	flag.StringVar(&topic, "topic", "foobar", "pub topic")
	flag.StringVar(&mode, "mode", "gw", "<gw|kafka|http|redis>")
	flag.StringVar(&appid, "appid", "app1", "appid of pub")
	flag.StringVar(&pubkey, "pubkey", "mypubkey", "pubkey")
	flag.StringVar(&ver, "ver", "v1", "pub topic version")
	flag.BoolVar(&async, "async", false, "async pub")
	flag.DurationVar(&sleep, "sleep", 0, "sleep between pub")
	flag.BoolVar(&suppressError, "noerr", false, "suppress error output")
	flag.Parse()

	switch mode {
	case "gw":
		http.DefaultClient.Timeout = time.Second * 30
		stress.RunStress(pubGatewayLoop)

	case "kafka":
		if async {
			stress.RunStress(pubKafkaAsyncLoop)
		} else {
			stress.RunStress(pubKafkaLoop)
		}

	case "redis":
		stress.RunStress(redisLoop)

	case "disque":
		stress.RunStress(disqueLoop)

	case "http":
		http.DefaultClient.Timeout = time.Second * 30
		stress.RunStress(getHttpLoop)
	}

}
Beispiel #4
0
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
}
Beispiel #5
0
// An example of using stress lib to load test xmpp server.
func main() {
	stress.RunStress(runSession)
}