| 219 | } |
| 220 | |
| 221 | void Test(int thread_num, int attachment_size) { |
| 222 | std::cout << "[Threads: " << thread_num |
| 223 | << ", Depth: " << FLAGS_queue_depth |
| 224 | << ", Attachment: " << attachment_size << "B" |
| 225 | << ", RDMA: " << (FLAGS_use_rdma ? "yes" : "no") |
| 226 | << ", Echo: " << (FLAGS_echo_attachment ? "yes]" : "no]") |
| 227 | << std::endl; |
| 228 | g_total_bytes.store(0, butil::memory_order_relaxed); |
| 229 | g_total_cnt.store(0, butil::memory_order_relaxed); |
| 230 | std::vector<PerformanceTest*> tests; |
| 231 | for (int k = 0; k < thread_num; ++k) { |
| 232 | PerformanceTest* t = new PerformanceTest(attachment_size, FLAGS_echo_attachment); |
| 233 | if (t->Init() < 0) { |
| 234 | exit(1); |
| 235 | } |
| 236 | tests.push_back(t); |
| 237 | } |
| 238 | uint64_t start_time = butil::cpuwide_time_us(); |
| 239 | bthread_t tid[thread_num]; |
| 240 | if (FLAGS_expected_qps > 0) { |
| 241 | bthread_t tid; |
| 242 | bthread_start_background(&tid, &BTHREAD_ATTR_NORMAL, GenerateToken, NULL); |
| 243 | } |
| 244 | for (int k = 0; k < thread_num; ++k) { |
| 245 | bthread_start_background(&tid[k], &BTHREAD_ATTR_NORMAL, |
| 246 | PerformanceTest::RunTest, tests[k]); |
| 247 | } |
| 248 | for (int k = 0; k < thread_num; ++k) { |
| 249 | while (!tests[k]->IsStop()) { |
| 250 | bthread_usleep(10000); |
| 251 | } |
| 252 | } |
| 253 | uint64_t end_time = butil::cpuwide_time_us(); |
| 254 | double throughput = g_total_bytes / 1.048576 / (end_time - start_time); |
| 255 | if (FLAGS_test_iterations == 0) { |
| 256 | std::cout << "Avg-Latency: " << g_latency_recorder.latency(10) |
| 257 | << ", 90th-Latency: " << g_latency_recorder.latency_percentile(0.9) |
| 258 | << ", 99th-Latency: " << g_latency_recorder.latency_percentile(0.99) |
| 259 | << ", 99.9th-Latency: " << g_latency_recorder.latency_percentile(0.999) |
| 260 | << ", Throughput: " << throughput << "MB/s" |
| 261 | << ", QPS: " << (g_total_cnt.load(butil::memory_order_relaxed) * 1000 / (end_time - start_time)) << "k" |
| 262 | << ", Server CPU-utilization: " << g_server_cpu_recorder.latency(10) << "\%" |
| 263 | << ", Client CPU-utilization: " << g_client_cpu_recorder.latency(10) << "\%" |
| 264 | << std::endl; |
| 265 | } else { |
| 266 | std::cout << " Throughput: " << throughput << "MB/s" << std::endl; |
| 267 | } |
| 268 | g_stop = true; |
| 269 | for (int k = 0; k < thread_num; ++k) { |
| 270 | bthread_start_background(&tid[k], &BTHREAD_ATTR_NORMAL, DeleteTest, tests[k]); |
| 271 | } |
| 272 | } |
| 273 | |
| 274 | int main(int argc, char* argv[]) { |
| 275 | GFLAGS_NAMESPACE::ParseCommandLineFlags(&argc, &argv, true); |
no test coverage detected