Exemplo n.º 1
0
func newOutChannelGroup() *outChannelGroup {
	objPtr := helpers.NewAsyncSafeObject()
	group := outChannelGroup{
		AsyncSafeObject: *objPtr,
		channels:        make(map[int64]*chan coreprocessing.CoreInstruction)}
	return &group
}
Exemplo n.º 2
0
// test unsafe set
func TestAsyncStrDictСompareSetSpeed(t *testing.T) {
	dictPtr := helpers.NewAsyncStrDict()
	var n, wCount, doneCount int
	n = 1000
	wCount = 50
	doneChannel := make(chan bool, wCount)
	testWorker := func(index int, dict *helpers.AsyncStrDict, done *chan bool) {
		for i := 0; i < n; i++ {
			dict.SetUnsafe(
				fmt.Sprintf("%d-%d", index+1, i+1),
				fmt.Sprintf("%d.%d", index, i))
		}
		*done <- true
	}
	testWorkerAnalog := func(index int, dict *simpleAnalogDict, done *chan bool) {
		for i := 0; i < n; i++ {
			dict.Set(
				fmt.Sprintf("%d-%d", index+1, i+1),
				fmt.Sprintf("%d.%d", index, i))
		}
		*done <- true
	}
	// run workers
	var startTime time.Time
	startTime = time.Now()
	for i := 0; i < wCount; i++ {
		go testWorker(i, dictPtr, &doneChannel)
	}
	for doneCount < wCount {
		done := <-doneChannel
		if done {
			doneCount += 1
		}
	}
	rtime := float32(time.Since(startTime).Seconds())
	s := dictPtr.Size()
	if n*wCount != s {
		t.Errorf("Dict size: %d", s)
	}
	doneCount = 0
	dictAnalog := simpleAnalogDict{
		content:         make(map[string]string),
		AsyncSafeObject: *(helpers.NewAsyncSafeObject())}

	startTime = time.Now()
	for i := 0; i < wCount; i++ {
		go testWorkerAnalog(i, &dictAnalog, &doneChannel)
	}
	for doneCount < wCount {
		done := <-doneChannel
		if done {
			doneCount += 1
		}
	}
	atime := float32(time.Since(startTime).Seconds())
	t.Logf("real: %f analog: %f\n", rtime, atime)
	if rtime > atime {
		t.Error("broken improvement")
	}
}
Exemplo n.º 3
0
func newConnectionDataStorageCell() *ConnectionDataStorageCell {
	objPtr := helpers.NewAsyncSafeObject()
	result := ConnectionDataStorageCell{
		data:            make(map[int64]*ClientStateData),
		AsyncSafeObject: *objPtr}
	return &result
}
Exemplo n.º 4
0
func NewConnectionDataManager(options options.SysOption) *ConnectionDataManager {
	rand := helpers.NewSystemRandom()
	result := ConnectionDataManager{
		rand:    *rand,
		options: options,
		// all pointer set reserved now
		storage:         make([]*ConnectionDataStorageCell, GroupCount),
		AsyncSafeObject: *(helpers.NewAsyncSafeObject())}
	return &result
}
Exemplo n.º 5
0
	if set, exists := (*manager).methods[method]; exists {
		size := set.Size()
		if size > 0 {
			result = make([]string, size)
			index := 0
			for cid, _ := range set.set {
				result[index] = cid
				index++
			}
		}
	}
	return result
}

var onceRpcServerManager = RpcServerManager{
	AsyncSafeObject:     *(helpers.NewAsyncSafeObject()),
	ResultDirectionDict: helpers.NewAsyncStrDict(),
	ResultBufferDict:    helpers.NewAsyncStrDict(),
	methods:             make(map[string]*CidSet)}

func NewRpcServerManager() *RpcServerManager {
	// use as singltone
	return &onceRpcServerManager
}

// main instruction commnad router
type MethodInstructionDict struct {
	helpers.AsyncSafeObject
	content map[string]int
}