コード例 #1
0
ファイル: bench_pqueue.go プロジェクト: vburenin/firempq
func BenchMassPush() {
	f := qmgr.NewServiceManager()
	resp := f.DropService("BenchTest")
	if !resp.IsError() {
		log.Info("BenchTest Queue exists alredy! Dropping...")
	}
	log.Info("Creating new service")
	resp = f.CreateService("pqueue", "BenchTest", []string{})
	if resp.IsError() {
		log.Fatal("Can not create BenchTest queue")
	}

	svc, ok := f.GetService("BenchTest")
	if !ok {
		log.Fatal("Could not get created service: BenchTest")
	}
	respWriter := mpqtesting.NewTestResponseWriter()
	ctx := svc.NewContext(respWriter)

	ctx.Call(pqueue.PQ_CMD_SET_CFG, []string{pqueue.CPRM_MAX_MSGS_IN_QUEUE, "10000000", pqueue.CPRM_MSG_TTL, "10000000"})

	var grp sync.WaitGroup
	data := []string{pqueue.PRM_PAYLOAD, "7777777777777777777777777777777777777777777777777777777777777777"}

	testFunc := func() {
		for i := 0; i < 1000000; i++ {
			ctx.Call(pqueue.PQ_CMD_PUSH, data)
		}
		grp.Done()
	}
	log.Info("Adding goroutines")

	startTs := time.Now().UnixNano()
	for i := 0; i < 10; i++ {
		grp.Add(1)
		go testFunc()

	}
	log.Info("Waiting for result")
	grp.Wait()
	finishTs := time.Now().UnixNano()
	ctx.Finish()

	log.Info("Test finished in: %d - %d", (finishTs - startTs), (finishTs-startTs)/1000000)
	db.DatabaseInstance().FlushCache()
	//println("waiting...")
	//time.Sleep(time.Second * 1200)
	//f.DropService("BenchTest")
	f.Close()
	db.DatabaseInstance().Close()
}
コード例 #2
0
ファイル: binlog.go プロジェクト: vburenin/firempq
func (self *BinaryLog) initializeLogFile() *BinLogFile {
	if len(self.logFiles) == 0 {
		firstName := self.logLocation + BinaryLogNamePrefix + "0" + BinaryLogFileExt
		self.logFiles = append(self.logFiles, &BinLogFile{firstName, 0})
	}
	lastLogFile := self.logFiles[len(self.logFiles)-1]

	err := createFileIfNotExists(lastLogFile.FilePath)
	if err != nil {
		log.Fatal("Failed to open a log file: %s", err.Error())
	}
	return lastLogFile
}
コード例 #3
0
ファイル: binlog.go プロジェクト: vburenin/firempq
func NewBinaryLog(cfg conf.Config) *BinaryLog {
	binlog := &BinaryLog{
		dataChan:    make(chan []byte, cfg.BinaryLogBufferSize),
		serviceChan: make(chan []byte, cfg.BinaryLogBufferSize),
		//frameSize: cfg.FrameSize,
		seqId:       0,
		maxPageSize: cfg.BinaryLogPageSize,
		pageSize:    0,
		logWriter:   nil,
	}
	logFiles, err := findLogFiles(cfg.BinaryLogPath)
	if err != nil {
		log.Fatal("Coould not init bin log subsystems: %s", err.Error())
	}
	binlog.logFiles = logFiles
	return binlog
}
コード例 #4
0
ファイル: binlog.go プロジェクト: vburenin/firempq
// createFileIfNotExists initializes log file.
func createFileIfNotExists(path string) error {
	_, err := os.Lstat(path)
	if err != nil {
		// What??? It is false if file doesn't exist.
		if os.IsExist(err) {
			log.Fatal("Can not read file stats: %s", err.Error())
		}
		f, err := os.Create(path)
		if err != nil {
			return err
		}

		if err := f.Close(); err != nil {
			return err
		}
		return createFileIfNotExists(path)
	}
	return nil
}
コード例 #5
0
ファイル: bench_pqueue.go プロジェクト: vburenin/firempq
func BenchMassPushMultiQueue() {
	f := qmgr.NewServiceManager()
	resp1 := f.DropService("BenchTest1")
	resp2 := f.DropService("BenchTest2")
	resp3 := f.DropService("BenchTest3")
	resp4 := f.DropService("BenchTest4")

	resp1 = f.CreateService(apis.ServiceTypePriorityQueue, "BenchTest1", []string{})
	if resp1.IsError() {
		log.Fatal("Can not create BenchTest queue")
	}

	resp2 = f.CreateService(apis.ServiceTypePriorityQueue, "BenchTest2", []string{})
	if resp2.IsError() {
		log.Fatal("Can not create BenchTest queue")
	}

	resp3 = f.CreateService(apis.ServiceTypePriorityQueue, "BenchTest3", []string{})
	if resp3.IsError() {
		log.Fatal("Can not create BenchTest queue")
	}

	resp4 = f.CreateService(apis.ServiceTypePriorityQueue, "BenchTest4", []string{})
	if resp4.IsError() {
		log.Fatal("Can not create BenchTest queue")
	}

	svc1, ok := f.GetService("BenchTest1")
	if !ok {
		log.Fatal("Could not get created service: BenchTest1")
	}
	svc2, ok := f.GetService("BenchTest2")
	if !ok {
		log.Fatal("Could not get created service: BenchTest2")
	}
	svc3, ok := f.GetService("BenchTest3")
	if !ok {
		log.Fatal("Could not get created service: BenchTest3")
	}

	svc4, ok := f.GetService("BenchTest4")
	if !ok {
		log.Fatal("Could not get created service: BenchTest4")
	}

	respWriter1 := mpqtesting.NewTestResponseWriter()
	respWriter2 := mpqtesting.NewTestResponseWriter()
	respWriter3 := mpqtesting.NewTestResponseWriter()
	respWriter4 := mpqtesting.NewTestResponseWriter()
	ctx1 := svc1.NewContext(respWriter1)
	ctx2 := svc2.NewContext(respWriter2)
	ctx3 := svc3.NewContext(respWriter3)
	ctx4 := svc4.NewContext(respWriter4)

	ctx1.Call(pqueue.PQ_CMD_SET_CFG, []string{pqueue.CPRM_MAX_MSGS_IN_QUEUE, "10000000", pqueue.CPRM_MSG_TTL, "100000", pqueue.CPRM_DELIVERY_DELAY, "0"})
	ctx2.Call(pqueue.PQ_CMD_SET_CFG, []string{pqueue.CPRM_MAX_MSGS_IN_QUEUE, "10000000", pqueue.CPRM_MSG_TTL, "100000", pqueue.CPRM_DELIVERY_DELAY, "0"})
	ctx3.Call(pqueue.PQ_CMD_SET_CFG, []string{pqueue.CPRM_MAX_MSGS_IN_QUEUE, "10000000", pqueue.CPRM_MSG_TTL, "100000", pqueue.CPRM_DELIVERY_DELAY, "0"})
	ctx4.Call(pqueue.PQ_CMD_SET_CFG, []string{pqueue.CPRM_MAX_MSGS_IN_QUEUE, "10000000", pqueue.CPRM_MSG_TTL, "100000", pqueue.CPRM_DELIVERY_DELAY, "0"})

	startTs := time.Now().UnixNano()
	data := []string{pqueue.PRM_PAYLOAD, "7777777777777777777777777777777777777777777777777777777777777777"}

	var grp sync.WaitGroup
	testFunc := func(ctx apis.ServiceContext) {
		for i := 0; i < 1000000; i++ {
			ctx.Call(pqueue.PQ_CMD_PUSH, data)
		}
		grp.Done()
	}
	log.Info("Adding goroutines")
	for i := 0; i < 1; i++ {
		grp.Add(1)
		go testFunc(ctx1)
		grp.Add(1)
		go testFunc(ctx2)
		grp.Add(1)
		go testFunc(ctx3)
		grp.Add(1)
		go testFunc(ctx4)
	}
	log.Info("Waiting for result")
	grp.Wait()
	ctx1.Finish()
	svc1.Close()
	ctx2.Finish()
	svc2.Close()
	ctx3.Finish()
	svc3.Close()

	ctx4.Finish()
	svc4.Close()

	finishTs := time.Now().UnixNano()
	log.Info("Test finished in: %d - %d", (finishTs - startTs), (finishTs-startTs)/1000000)

	db.DatabaseInstance().FlushCache()

	log.Info("Deleting BenchTest1")
	f.DropService("BenchTest1")
	log.Info("Deleting BenchTest2")
	f.DropService("BenchTest2")
	log.Info("Deleting BenchTest3")
	f.DropService("BenchTest3")
	log.Info("Deleting BenchTest4")
	f.DropService("BenchTest4")
	log.Info("Closing facade...")
	f.Close()
	log.Info("Waiting flush...")
	log.Info("Closing DB")
	db.DatabaseInstance().Close()
}