Exemplo n.º 1
0
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()
}
Exemplo n.º 2
0
// SaveServiceConfig saves service config into database.
func SaveServiceConfig(serviceId string, conf apis.BinaryMarshaller) error {
	db := db.DatabaseInstance()
	data, _ := conf.Marshal()
	err := db.StoreData(cfgKey(serviceId), data)
	if err != nil {
		log.Error("Failed to save config: %s", err.Error())
		return mpqerr.ServerError("Can not save service data: " + serviceId)
	}
	return nil
}
Exemplo n.º 3
0
func LoadServiceConfig(serviceId string, cfg apis.BinaryMarshaller) error {
	db := db.DatabaseInstance()
	data := db.GetData(cfgKey(serviceId))
	if len(data) == 0 {
		return mpqerr.NotFoundRequest("No service settings found: " + serviceId)
	}

	if err := cfg.Unmarshal(data); err != nil {
		log.Error("Error in '%s' service settings: %s", serviceId, err.Error())
		return mpqerr.ServerError("Service settings error: " + serviceId)
	}
	return nil
}
Exemplo n.º 4
0
func DeleteServiceData(serviceId string) {
	desc := GetServiceDescription(serviceId)
	if desc == nil {
		log.Error("Attempt to delete unknown service id: %s", serviceId)
		return
	}
	desc.ToDelete = true
	SaveServiceDescription(desc)

	db := db.DatabaseInstance()
	db.DeleteDataWithPrefix(serviceId)
	db.DeleteData(cfgKey(serviceId))
	db.DeleteData(descKey(serviceId))
}
Exemplo n.º 5
0
// GetServiceDescriptions Loads all service descriptions prefixed with ServiceDescPrefix
func GetServiceDescriptions() ServiceDescriptionList {
	sdList := make(ServiceDescriptionList, 0, 16)
	db := db.DatabaseInstance()
	descIter := db.IterData(ServiceDescPrefix)
	defer descIter.Close()

	for ; descIter.Valid(); descIter.Next() {
		svcDesc, err := UnmarshalServiceDesc([]byte(descIter.GetValue()))
		if err != nil {
			log.Error("Coudn't read service '%s' description: %s", descIter.GetTrimKey(), err.Error())
			continue
		}
		sdList = append(sdList, svcDesc)
	}
	return sdList
}
Exemplo n.º 6
0
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()
}
Exemplo n.º 7
0
// SaveServiceDescription saves service config into database.
func SaveServiceDescription(desc *ServiceDescription) error {
	db := db.DatabaseInstance()
	data, _ := desc.Marshal()
	return db.StoreData(descKey(desc.ServiceId), data)
}
Exemplo n.º 8
0
// GetServiceDescriptions Loads all service descriptions prefixed with ServiceDescPrefix
func GetServiceDescription(serviceId string) *ServiceDescription {
	db := db.DatabaseInstance()
	data := db.GetData(descKey(serviceId))
	desc, _ := UnmarshalServiceDesc([]byte(data))
	return desc
}