Ejemplo n.º 1
0
func (p *program) Start() error {
	glog.InitWithFlag(flagSet)

	flagSet.Parse(os.Args[1:])

	if *showVersion {
		fmt.Println(version.String("nsqlookupd"))
		os.Exit(0)
	}

	var cfg map[string]interface{}
	if *config != "" {
		_, err := toml.DecodeFile(*config, &cfg)
		if err != nil {
			log.Fatalf("ERROR: failed to load config file %s - %s", *config, err.Error())
		}
	}

	opts := nsqlookupd.NewOptions()
	options.Resolve(opts, flagSet, cfg)
	if opts.LogDir != "" {
		glog.SetGLogDir(opts.LogDir)
	}
	nsqlookupd.SetLogger(opts)
	glog.StartWorker(time.Second * 2)
	daemon := nsqlookupd.New(opts)

	daemon.Main()
	p.nsqlookupd = daemon
	return nil
}
Ejemplo n.º 2
0
func main() {
	glog.InitWithFlag(flagSet)
	flagSet.Parse(os.Args[1:])

	if *showVersion {
		fmt.Println(version.String("nsqadmin"))
		return
	}
	defer glog.Flush()

	if *templateDir != "" {
		log.Printf("WARNING: --template-dir is deprecated and will be removed in the next release (templates are now compiled into the binary)")
	}

	exitChan := make(chan int)
	signalChan := make(chan os.Signal, 1)
	go func() {
		<-signalChan
		exitChan <- 1
	}()
	signal.Notify(signalChan, syscall.SIGINT, syscall.SIGTERM)

	var cfg map[string]interface{}
	if *config != "" {
		_, err := toml.DecodeFile(*config, &cfg)
		if err != nil {
			log.Fatalf("ERROR: failed to load config file %s - %s", *config, err)
		}
	}

	opts := nsqadmin.NewOptions()
	options.Resolve(opts, flagSet, cfg)
	if opts.LogDir != "" {
		glog.SetGLogDir(opts.LogDir)
	}
	glog.StartWorker(time.Second * 2)

	nsqadmin := nsqadmin.New(opts)

	nsqadmin.Main()
	<-exitChan
	nsqadmin.Exit()
}
Ejemplo n.º 3
0
func main() {
	glog.InitWithFlag(flagSet)
	flagSet.Parse(os.Args[1:])
	glog.StartWorker(time.Second)
	if *ordered {
		*trace = true
	}
	config = nsq.NewConfig()
	config.MsgTimeout = time.Second * time.Duration(10*(*channelNum))
	if config.MsgTimeout >= time.Second*200 {
		config.MsgTimeout = time.Second * 200
	}
	config.DefaultRequeueDelay = time.Second * 30
	config.MaxRequeueDelay = time.Second * 60
	config.MaxInFlight = 20
	config.EnableTrace = *trace
	config.EnableOrdered = *ordered

	log.SetPrefix("[bench_writer] ")
	dumpCheck = make(map[string]map[uint64]*nsq.Message, 5)
	pubRespCheck = make(map[string]map[uint64]pubResp, 5)
	orderCheck = make(map[string]pubResp)
	traceIDWaitingList = make(map[string]map[uint64]*nsq.Message, 5)
	pubTraceFailedList = make(map[string]map[uint64]int64)

	topicMutex = make(map[string]*sync.Mutex)
	if *topicListFile != "" {
		f, err := os.Open(*topicListFile)
		if err != nil {
			log.Printf("load topic list file error: %v", err)
		} else {
			scanner := bufio.NewScanner(f)
			for scanner.Scan() {
				line := scanner.Text()
				line = strings.TrimSpace(line)
				topics = append(topics, line)
			}
		}
	}
	log.Printf("testing topic list: %v", topics)

	msg := make([]byte, *size)
	batch := make([][]byte, *batchSize)
	for i := range batch {
		batch[i] = msg
	}

	if *benchCase == "simple" {
		startSimpleTest(msg, batch)
	} else if *benchCase == "benchpub" {
		startBenchPub(msg, batch)
	} else if *benchCase == "benchsub" {
		startBenchSub()
	} else if *benchCase == "checkdata" {
		startCheckData(msg, batch)
	} else if *benchCase == "benchlookup" {
		startBenchLookup()
	} else if *benchCase == "benchreg" {
		startBenchLookupRegUnreg()
	} else if *benchCase == "consumeoffset" {
		startCheckSetConsumerOffset()
	} else if *benchCase == "checkdata2" {
		startCheckData2()
	}
}