get.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // Copyright 2015 CoreOS, Inc.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package main
  15. import (
  16. "time"
  17. "github.com/coreos/etcd/Godeps/_workspace/src/golang.org/x/net/context"
  18. "github.com/coreos/etcd/Godeps/_workspace/src/google.golang.org/grpc"
  19. "github.com/coreos/etcd/etcdserver/etcdserverpb"
  20. )
  21. func benchGet(conn *grpc.ClientConn, key, rangeEnd []byte, n, c int) {
  22. wg.Add(c)
  23. requests := make(chan struct{}, n)
  24. for i := 0; i < c; i++ {
  25. go get(etcdserverpb.NewKVClient(conn), key, rangeEnd, requests)
  26. }
  27. for i := 0; i < n; i++ {
  28. requests <- struct{}{}
  29. }
  30. close(requests)
  31. }
  32. func get(client etcdserverpb.KVClient, key, end []byte, requests <-chan struct{}) {
  33. defer wg.Done()
  34. req := &etcdserverpb.RangeRequest{Key: key, RangeEnd: end}
  35. for _ = range requests {
  36. st := time.Now()
  37. _, err := client.Range(context.Background(), req)
  38. var errStr string
  39. if err != nil {
  40. errStr = err.Error()
  41. }
  42. results <- &result{
  43. errStr: errStr,
  44. duration: time.Now().Sub(st),
  45. }
  46. bar.Increment()
  47. }
  48. }