func workerGetSetRand(client *memcache.Client, wg *sync.WaitGroup, ch <-chan int) { defer wg.Done() var item memcache.Item itemsCount := *requestsCount / *workersCount for _ = range ch { n := rand.Intn(itemsCount) item.Key = []byte(fmt.Sprintf("%s_%d", *key, n)) v := []byte(fmt.Sprintf("%s_%d", *value, n)) if rand.Float32() < 0.5 { err := client.Get(&item) if err == memcache.ErrCacheMiss { continue } if err != nil { log.Fatalf("Error in Client.Get(): [%s]", err) } if !bytes.Equal(item.Value, v) { log.Fatalf("Unexpected value=[%s] obtained. Expected [%s]", item.Value, v) } } else { item.Value = v if err := client.Set(&item); err != nil { log.Fatalf("Error in Client.Set(): [%s]", err) } } } }
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) } } }
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) } }
func workerSet(client *memcache.Client, wg *sync.WaitGroup, ch <-chan int) { defer wg.Done() var item memcache.Item for i := range ch { item.Key = []byte(fmt.Sprintf("%s_%d", *key, i)) item.Value = []byte(fmt.Sprintf("%s_%d", *value, i)) if err := client.Set(&item); err != nil { log.Fatalf("Error in Client.Set(): [%s]", err) } } }
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) } }
func workerGetHit(client *memcache.Client, wg *sync.WaitGroup, ch <-chan int) { defer wg.Done() item := memcache.Item{ Key: []byte(*key), Value: []byte(*value), } valueOrig := item.Value item.Value = nil for _ = range ch { if err := client.Get(&item); err != nil { log.Fatalf("Error in Client.Get(): [%s]", err) } if !bytes.Equal(valueOrig, item.Value) { log.Fatalf("Unexpected value read=[%s]. Expected=[%s]", item.Value, valueOrig) } } }