func cmdBenchmarkSet() error { if len(globalBrokerList) == 0 { return errors.NotValidf("broker list") } if len(globalTopic) == 0 { return errors.NotValidf("Topic") } sendString := utils.GenTestMessage(globalMsgLength) producerConfig := siesta_producer.NewProducerConfig() producerConfig.Linger = time.Millisecond connConfig := siesta.NewConnectorConfig() brokerList := strings.Split(globalBrokerList, ",") producerConfig.BrokerList = brokerList connConfig.BrokerList = brokerList log.Printf("%v", brokerList) connector, err := siesta.NewDefaultConnector(connConfig) if err != nil { return errors.Trace(err) } // go func() { // timeout := time.Tick(producerConfig.MetadataExpire / 2) // for { // <-timeout // connector.RefreshMetadata([]string{globalTopic}) // } // }() producer := siesta_producer.NewKafkaProducer(producerConfig, siesta_producer.ByteSerializer, siesta_producer.ByteSerializer, connector) bt := utils.NewBenchmarkTester(globalConcurrentLevel, globalDuration, func(bt *utils.BenchmarkTester, index int) error { record := &siesta_producer.ProducerRecord{ Topic: globalTopic, Value: []byte(sendString), } recordMetadata := <-producer.Send(record) if recordMetadata.Error == siesta.ErrNoError { return nil } return recordMetadata.Error }, nil) return errors.Trace(bt.Run()) }
func cmdBenchmarkSetNoAck() error { if len(globalBrokerList) == 0 { return errors.NotValidf("broker list") } if len(globalTopic) == 0 { return errors.NotValidf("Topic") } sendString := utils.GenTestMessage(globalMsgLength) producerConfig := siesta_producer.NewProducerConfig() producerConfig.ClientID = "Benchmark" producerConfig.RequiredAcks = 0 connConfig := siesta.NewConnectorConfig() brokerList := strings.Split(globalBrokerList, ",") producerConfig.BrokerList = brokerList connConfig.BrokerList = brokerList log.Printf("%v", brokerList) connector, err := siesta.NewDefaultConnector(connConfig) if err != nil { return errors.Trace(err) } producer := siesta_producer.NewKafkaProducer(producerConfig, siesta_producer.ByteSerializer, siesta_producer.ByteSerializer, connector) bt := utils.NewBenchmarkTester(globalConcurrentLevel, globalDuration, func(bt *utils.BenchmarkTester, index int) error { record := &siesta_producer.ProducerRecord{ Topic: globalTopic, Value: []byte(sendString), } recordMetadata := <-producer.Send(record) if recordMetadata.Error == siesta.ErrNoError { return nil } return recordMetadata.Error }, nil) return errors.Trace(bt.Run()) }
func benchmarkMCSet() error { key := fmt.Sprintf("%s.%s", globalQueue, globalBiz) sendString := utils.GenTestMessage(globalMsgLength) log.Printf("Test Key: %s, Data: %s", key, sendString) mc := memcache.New(globalHost) bt := utils.NewBenchmarkTester(globalConcurrentLevel, globalDuration, func(bt *utils.BenchmarkTester, index int) error { err := mc.Set(&memcache.Item{Key: key, Value: []byte(sendString)}) if err != nil { return err } return nil }, nil) return errors.Trace(bt.Run()) }
func benchmarkHttpSet() error { url := fmt.Sprintf("http://%s/msg", globalHost) sendString := fmt.Sprintf("action=send&queue=%s&group=%s&msg=%s", globalQueue, globalBiz, utils.GenTestMessage(globalMsgLength)) log.Printf("Test URL: %s, Data: %s", url, sendString) bt := utils.NewBenchmarkTester(globalConcurrentLevel, globalDuration, func(bt *utils.BenchmarkTester, index int) error { body := strings.NewReader(sendString) resp, err := http.Post(url, "application/x-www-form-urlencoded", body) if err != nil { return err } if resp.StatusCode != 200 { return fmt.Errorf("http code %d", resp.StatusCode) } return nil }, nil) return errors.Trace(bt.Run()) }