Пример #1
0
func TestPerformance(t *testing.T) {
	runtime.GOMAXPROCS(util.CPU())
	dbm.ShowLog = true
	err := AddDefault2("mysql", "cny:123@tcp(192.168.2.57:3306)/test?charset=utf8&loc=Local")
	if err != nil {
		t.Error(err.Error())
		return
	}
	used, err := tutil.DoPerf(5000, "", func(i int) {
		_, err = dbutil.DbQueryF(Db(), "select 1")
		if err != nil {
			t.Error(err.Error())
		}
	})
	fmt.Println(used, err)
}
Пример #2
0
func TestPerformance(t *testing.T) {
	runtime.GOMAXPROCS(util.CPU())
	Default = dbm.NewMDbs2()
	err := AddDefault("cny:[email protected]:27017/cny", "cny")
	if err != nil {
		t.Error(err.Error())
		return
	}
	fmt.Println("xxxx->")
	var added = map[int64]bool{}
	var lck = sync.RWMutex{}
	C(Sequence).RemoveAll(nil)
	fmt.Println(Next2("abc", 1))
	fmt.Println(Next2("abc", 10))
	used, err := tutil.DoPerf(2000, "", func(i int) {
		err := C("abc").Insert(bson.M{"a": 1, "b": 2})
		if err != nil {
			t.Error(err.Error())
			return
		}
		_, nv, err := Next2("abc", 1)
		if err != nil {
			t.Error(err.Error())
			return
		}
		_, nv2, err := Next(Sequence, "abc", 1)
		if err != nil {
			t.Error(err.Error())
			return
		}
		lck.Lock()
		if added[nv] {
			panic("exit")
		}
		if added[nv2] {
			panic("exit")
		}
		added[nv] = true
		added[nv2] = true
		lck.Unlock()
	})
	fmt.Println("used->", used, err)
	fmt.Println(Next2("abc", 0))
	//
	// added = map[int64]bool{}
	used, err = tutil.DoPerf(20000, "", func(i int) {
		nv := WaitNext("abc")
		if err != nil {
			t.Error(err.Error())
			return
		}
		nv2 := WaitNext("abc")
		if err != nil {
			t.Error(err.Error())
			return
		}
		lck.Lock()
		if added[nv] {
			fmt.Println(nv)
			fmt.Println(pool)
			panic("exists")
		}
		if added[nv2] {
			fmt.Println(nv2)
			panic("exists")
		}
		added[nv] = true
		added[nv2] = true
		lck.Unlock()
	})
	fmt.Println("used->", used, err)
	fmt.Println(Next2("abc", 0))
}