예제 #1
0
파일: perf.go 프로젝트: maniktaneja/luxstor
func main() {
	flag.Parse()
	rand.Seed(time.Now().UnixNano())
	var wg sync.WaitGroup

	memServer := fmt.Sprintf("%s:%d", *server, *port)

	log.Printf(" Connected to server %v", memServer)

	var c []*memcached.Client

	for j := 0; j < *threadCount; j++ {
		client, err := memcached.Connect("tcp", memServer)
		if err != nil {
			log.Printf(" Unable to connect to %v, error %v", memServer, err)
			return
		}

		c = append(c, client)
	}

	data := RandStringRunes(*size)
	now := time.Now()
	docPerThread := *documentCount / runtime.GOMAXPROCS(0)

	for j := 0; j < *threadCount; j++ {
		wg.Add(1)
		go func(offset int) {
			defer wg.Done()
			client := c[offset]

			for i := 0; i < docPerThread; i++ {
				docid := fmt.Sprintf("doc-%d", i+offset*docPerThread)
				res, err := client.Set(0, docid, 0, 0, []byte(data))
				if err != nil || res.Status != gomemcached.SUCCESS {
					log.Printf("Set failed. Error %v", err)
					return
				}

				for k := 0; k < *readRatio; k++ {
					res, err := client.Get(0, docid)
					if err != nil || res.Status != gomemcached.SUCCESS {
						log.Printf("Get failed. Error %v", err)
						return
					}
				}
			}

		}(j)
	}

	wg.Wait()
	elapsed := time.Since(now)
	ops := runtime.GOMAXPROCS(0) * docPerThread
	log.Printf("sets:%d, gets:%d time_taken:%v\n", ops, ops**readRatio, elapsed)

	//log.Printf("Get returned %v", res)
}
예제 #2
0
func main() {

	flag.Parse()
	var wg sync.WaitGroup

	runtime.GOMAXPROCS(4)

	memServer := fmt.Sprintf("%s:%d", *server, *port)

	log.Printf(" Connected to server %v", memServer)

	var c []*memcached.Client

	data := RandStringRunes(512)

	for j := 0; j < runtime.GOMAXPROCS(0); j++ {
		client, err := memcached.Connect("tcp", memServer)
		if err != nil {
			log.Printf(" Unable to connect to %v, error %v", memServer, err)
			return
		}

		c = append(c, client)
	}
	n := 10000000
	now := time.Now()
	for j := 0; j < runtime.GOMAXPROCS(0); j++ {
		wg.Add(1)
		go func(offset int) {
			defer wg.Done()
			client := c[offset]

			for i := 0; i < n; i++ {

				res, err := client.Set(0, "test"+string(i), 0, 0, []byte(data))
				if err != nil || res.Status != gomemcached.SUCCESS {
					log.Printf("Set failed. Error %v", err)
					return
				}
			}

			for {
				i := rand.Intn(1000000)
				res, err := client.Get(0, "test"+string(i))
				if err != nil || res.Status != gomemcached.SUCCESS {
					log.Printf("Get failed. Error %v", err)
					return
				}

				//                              log.Printf(" Time %v", elapsed)
			}
		}(j)
	}

	wg.Wait()
	elapsed := time.Since(now)
	ops := runtime.GOMAXPROCS(0) * n
	log.Printf("sets:%d, gets:%d time_taken:%v\n", ops, ops, elapsed)

	//log.Printf("Get returned %v", res)

}