Add proper per-file copyright notices/licenses and top-level license.
[bluesky.git] / kvstore / kvbench.cc
1 #include <boost/program_options.hpp>
2 #include <boost/shared_ptr.hpp>
3 #include <iostream>
4 #include <string>
5 #include "kvservice.h"
6 #include "kvclient.h"
7 #include "protobufrpc.h"
8
9 using namespace bicker;
10 using namespace boost;
11 using namespace kvstore;
12 using namespace std;
13
14 namespace po = boost::program_options;
15
16 class KVBench
17 {
18 public:
19     KVBench(const vector<string> &hosts)
20         :_kv_client(list<string>(hosts.begin(), hosts.end()))
21     {
22     }
23
24     virtual ~KVBench()
25     {
26     }
27
28
29     void Bench(const size_t size,
30                const size_t count)
31     {
32         string data(size, 'A');
33
34         for (size_t i = 0; i < count; ++i)
35         {
36             ostringstream key;
37             key << "key_" << size << "_" << i << endl;
38
39             _kv_client.Put(key.str(), data);
40         }
41
42         for (size_t i = 0; i < count; ++i)
43         {
44             string value;
45             ostringstream key;
46             key << "key_" << size << "_" << i << endl;
47
48             _kv_client.Get(key.str(), &value);
49         }
50     }
51
52 protected:
53     KeyValueClient _kv_client;
54 };
55
56
57 int
58 main(
59      int argc,
60      char **argv
61     )
62 {
63     size_t opt_low;
64     size_t opt_high;
65     size_t opt_count;
66
67     po::options_description options("Options");
68
69     options.add_options()
70         ("help,h", "display help message")
71         ("servers",
72          po::value< vector<string> >()->multitoken(),
73          "server:port ... server:port")
74         ("low,l",
75          po::value<size_t>(&opt_low)->default_value(1),
76          "low 2^i")
77         ("high,H",
78          po::value<size_t>(&opt_high)->default_value(16),
79          "high 2^i")
80         ("count,c",
81          po::value<size_t>(&opt_count)->default_value(100),
82          "count of each size")
83         ;
84
85     po::variables_map vm;
86     po::store(po::parse_command_line(argc, argv, options), vm);
87     po::notify(vm);
88
89     if (vm.count("help"))
90     {
91         cerr << options << endl;
92         return 1;
93     }
94
95     if (!vm.count("servers"))
96     {
97         cerr << "No Servers Specified" << endl;
98         return 1;
99     }
100
101
102     KVBench bench(vm["servers"].as< vector<string> >());
103
104     for (size_t i = opt_low; i <= opt_high; ++i)
105     {
106         cout << i << ": " << (1<<i) << endl;
107         bench.Bench(1<<i, opt_count);
108     }
109
110     return 0;
111 }