Exemple #1
0
func workerGetSetNew(client memcache_new.Cacher, wg *sync.WaitGroup, ch <-chan int, stats *Stats) {
	defer wg.Done()
	var item memcache_new.Item
	for _ = range ch {
		n := rand.Intn(*itemsCount)
		item.Key = []byte(fmt.Sprintf("%s_%d", key, n))
		startTime := time.Now()
		if rand.Float64() < *getRatio {
			err := client.Get(&item)
			if err == memcache_new.ErrCacheMiss {
				stats.cacheMissCount++
				continue
			}
			if err != nil {
				stats.errorsCount++
				continue
			}
			stats.cacheHitCount++
			updateResponseTimeHistogram(stats, startTime)
		} else {
			item.Value = value
			if err := client.Set(&item); err != nil {
				stats.errorsCount++
				continue
			}
			updateResponseTimeHistogram(stats, startTime)
		}
	}
}
Exemple #2
0
func precreateItemsNew(client memcache_new.Cacher) {
	item := memcache_new.Item{
		Value: value,
	}
	for i := 0; i < *itemsCount; i++ {
		item.Key = []byte(fmt.Sprintf("%s_%d", key, i))
		client.SetNowait(&item)
	}
}
Exemple #3
0
func workerSetNew(client memcache_new.Cacher, wg *sync.WaitGroup, ch <-chan int, stats *Stats) {
	defer wg.Done()
	var item memcache_new.Item
	for _ = range ch {
		n := rand.Intn(*itemsCount)
		item.Key = []byte(fmt.Sprintf("%s_%d", key, n))
		item.Value = value
		startTime := time.Now()
		if err := client.Set(&item); err != nil {
			stats.errorsCount++
			continue
		}
		updateResponseTimeHistogram(stats, startTime)
	}
}
Exemple #4
0
func getWorkerNew(serverAddrs_ []string) func(wg *sync.WaitGroup, ch chan int, stats *Stats) {
	config := memcache_new.ClientConfig{
		ConnectionsCount:        *connectionsCount,
		MaxPendingRequestsCount: *maxPendingRequestsCount,
		ReadBufferSize:          *readBufferSize,
		WriteBufferSize:         *writeBufferSize,
		OSReadBufferSize:        *osReadBufferSize,
		OSWriteBufferSize:       *osWriteBufferSize,
	}
	var client memcache_new.Cacher
	if len(serverAddrs_) < 2 {
		client = &memcache_new.Client{
			ServerAddr:   *serverAddrs,
			ClientConfig: config,
		}
		client.Start()
	} else {
		c := &memcache_new.DistributedClient{
			ClientConfig: config,
		}
		c.StartStatic(serverAddrs_)
		client = c
	}

	worker := workerGetMissNew
	switch *workerMode {
	case "GetHit":
		precreateItemsNew(client)
		worker = workerGetHitNew
	case "GetMiss":
		client.Delete(key)
		worker = workerGetMissNew
	case "Set":
		worker = workerSetNew
	case "GetSet":
		precreateItemsNew(client)
		worker = workerGetSetNew
	default:
		log.Fatalf("Unknown workerMode=[%s]", *workerMode)
	}
	return func(wg *sync.WaitGroup, ch chan int, stats *Stats) {
		worker(client, wg, ch, stats)
	}

}