Skip to content
This repository
Browse code

CR and other fixes

  • Loading branch information...
commit 3bd83e697142cae0722e31f4e7a2d31e9797bc08 1 parent 5fcaed6
Erik Frey authored August 09, 2012

Showing 1 changed file with 23 additions and 17 deletions. Show diff stats Hide diff stats

  1. 40  bench/db.cpp
40  bench/db.cpp
@@ -55,7 +55,7 @@ class session : public enable_shared_from_this<session>
55 55
    typedef ip::tcp::socket socket_type;
56 56
    typedef shared_ptr<session> ptr_type;
57 57
 
58  
-   session(io_service& ios, results& _results, const std::string& host, size_t port)
  58
+   session(io_service& ios, results& _results, const string& host, size_t port)
59 59
    : socket_(ios),
60 60
      ios_(ios),
61 61
      results_(_results),
@@ -73,7 +73,12 @@ class session : public enable_shared_from_this<session>
73 73
 
74 74
 private:
75 75
 
76  
-   void fail(const std::string& method, const system::error_code& e)
  76
+   void fail(const string& method, const string& message)
  77
+   {
  78
+      cerr << "[ERROR] " << method << ": " << message << endl;
  79
+   }
  80
+
  81
+   void fail(const string& method, const system::error_code& e)
77 82
    {
78 83
       cerr << "[ERROR] " << method << ": " << e.message() << endl;
79 84
    }
@@ -128,14 +133,20 @@ class session : public enable_shared_from_this<session>
128 133
       results_.bytes_in += bytes_transferred;
129 134
 
130 135
       asio::streambuf::const_buffers_type bufs = in_.data();
131  
-      std::string header(buffers_begin(bufs), buffers_begin(bufs) + bytes_transferred);
  136
+      string header(buffers_begin(bufs), buffers_begin(bufs) + bytes_transferred);
132 137
       in_.consume(bytes_transferred);
133 138
 
134 139
       if (header == "END\r\n")
  140
+      {
  141
+         results_.times.push_back((posix_time::microsec_clock::local_time() - begin_).total_microseconds());
135 142
          do_get_or_set();
  143
+      }
136 144
       else
137 145
       {
138  
-         size_t required = results_.item_size + 7; // item + \r\nEND\r\n
  146
+         size_t pos = header.rfind(' ');
  147
+         if (pos == string::npos)
  148
+            return fail("get_on_header", "bad header");
  149
+         size_t required = atoi(header.c_str() + pos + 1);
139 150
          async_read(
140 151
             socket_, in_, transfer_at_least(required > in_.size() ? required - in_.size() : 0),
141 152
             bind(&session::get_on_value, shared_from_this(), _1, _2));
@@ -148,7 +159,7 @@ class session : public enable_shared_from_this<session>
148 159
          return fail("get_on_value", e);
149 160
 
150 161
       results_.times.push_back((posix_time::microsec_clock::local_time() - begin_).total_microseconds());
151  
-      results_.bytes_in += bytes_transferred;
  162
+      results_.bytes_in += in_.size();
152 163
 
153 164
       in_.consume(in_.size());
154 165
       do_get_or_set();
@@ -183,7 +194,7 @@ class session : public enable_shared_from_this<session>
183 194
       results_.times.push_back((posix_time::microsec_clock::local_time() - begin_).total_microseconds());
184 195
       results_.bytes_in += bytes_transferred;
185 196
 
186  
-      in_.consume(in_.size());
  197
+      in_.consume(bytes_transferred);
187 198
       do_get_or_set();
188 199
    }   
189 200
 
@@ -285,20 +296,15 @@ int main(int argc, char * argv[])
285 296
          avg += *it;
286 297
       avg /= r.times.size();
287 298
 
  299
+      cout << setw(24) << "Requests per second:" << (num_gets + num_sets) / elapsed_seconds << " [us] (mean)" << endl;
288 300
       cout << setw(24) << "Time per request:" << avg << " [us] (mean)" << endl << endl;
289 301
       cout << "Percentage of the requests served within a certain time (us)" << endl;
290  
-      cout << setw(10) << "  50%:" << r.times[r.times.size() * 50 / 100] << endl;
291  
-      cout << setw(10) << "  66%:" << r.times[r.times.size() * 66 / 100] << endl;
292  
-      cout << setw(10) << "  75%:" << r.times[r.times.size() * 75 / 100] << endl;
293  
-      cout << setw(10) << "  80%:" << r.times[r.times.size() * 80 / 100] << endl;
294  
-      cout << setw(10) << "  90%:" << r.times[r.times.size() * 90 / 100] << endl;
295  
-      cout << setw(10) << "  95%:" << r.times[r.times.size() * 95 / 100] << endl;
296  
-      cout << setw(10) << "  98%:" << r.times[r.times.size() * 98 / 100] << endl;
297  
-      cout << setw(10) << "  99%:" << r.times[r.times.size() * 99 / 100] << endl;
298  
-      cout << setw(10) << " 100%:" << r.times[r.times.size() - 1] << " (longest request)" << endl;
299  
-   }
300  
-
301 302
 
  303
+      int percentages[] = {50, 66, 75, 80, 90, 95, 98, 99};
  304
+      for (size_t i = 0; i < sizeof(percentages) / sizeof(int); ++i)
  305
+         cout << "  " <<  percentages[i] << "%:    " << r.times[r.times.size() * percentages[i] / 100] << endl;
  306
+      cout << " 100%:    " << r.times[r.times.size() - 1] << " (longest request)" << endl;
  307
+   }
302 308
 
303 309
    return 0;
304 310
 }

0 notes on commit 3bd83e6

Please sign in to comment.
Something went wrong with that request. Please try again.