已开启
校验8k+数据传输大小问题 #164
清石小猿创建于 7月16日
校验8k+数据传输大小问题 #164
已开启
共 2 个文件变更+47-4
| @@ -17,6 +17,7 @@ | |||
| 17 | 17 | ||
| 18 | 18 | ||
| 19 | 19 | ||
| 20 | + | ||
| 20 | 21 | ||
| 21 | 22 | ||
| 22 | 23 | ||
| @@ -75,7 +76,7 @@ DEFINE_int32(test_seconds, 20, "Test running time"); | |||
| 75 | DEFINE_int32(test_iterations, 0, "Test iterations"); | 76 | DEFINE_int32(test_iterations, 0, "Test iterations"); |
| 76 | DEFINE_int32(dummy_port, 8001, "Dummy server port number"); | 77 | DEFINE_int32(dummy_port, 8001, "Dummy server port number"); |
| 77 | DEFINE_int32(connect_timeout_ms, 2000, "connect timeout"); | 78 | DEFINE_int32(connect_timeout_ms, 2000, "connect timeout"); |
| 78 | -DEFINE_int64(req_size, 0, "request size"); | 79 | +DEFINE_int64(req_size, 8192, "request size, default 8K for send/recv consistency test (name echo)"); |
| 79 | DEFINE_bool(client_ignore_oc, false, "Client ignore eovercrowded, false by default"); | 80 | DEFINE_bool(client_ignore_oc, false, "Client ignore eovercrowded, false by default"); |
| 80 | DEFINE_int32(max_retry, 3, "max retry times (0-1000)"); | 81 | DEFINE_int32(max_retry, 3, "max retry times (0-1000)"); |
| 81 | DEFINE_int32(connect_retry_interval, 200, "connect retry interval(ms)"); | 82 | DEFINE_int32(connect_retry_interval, 200, "connect retry interval(ms)"); |
| @@ -85,6 +86,8 @@ DEFINE_bool(test_keep_alive, false, "Keep connections alive for 10 seconds after | |||
| 85 | DEFINE_bool(debug_latency, false, "Print latency of each successful request"); | 86 | DEFINE_bool(debug_latency, false, "Print latency of each successful request"); |
| 86 | DEFINE_string(export_percentile_file, "", "Export percentile samples to a binary file for cross-instance aggregation (empty to skip)"); | 87 | DEFINE_string(export_percentile_file, "", "Export percentile samples to a binary file for cross-instance aggregation (empty to skip)"); |
| 87 | 88 | ||
| 89 | +DEFINE_bool(print_response_log, true, "Print one line per response: [OK] / [MISMATCH] for name echo check"); | ||
| 90 | + | ||
| 88 | // ==================== 全局变量 ==================== | 91 | // ==================== 全局变量 ==================== |
| 89 | // 性能统计记录器 (bvar 内部线程安全) | 92 | // 性能统计记录器 (bvar 内部线程安全) |
| 90 | bvar::LatencyRecorder g_latency_recorder("client"); | 93 | bvar::LatencyRecorder g_latency_recorder("client"); |
| @@ -359,6 +362,41 @@ public: | |||
| 359 | g_server_cpu_recorder << atof(closure->resp->cpu_usage().c_str()) * 100; | 362 | g_server_cpu_recorder << atof(closure->resp->cpu_usage().c_str()) * 100; |
| 360 | } | 363 | } |
| 361 | 364 | ||
| 365 | + // 8K+ 一致性测试: 校验 server 回来的 name 字段与 g_name 是否一致 | ||
| 366 | + const std::string& resp_name = closure->resp->name(); | ||
| 367 | + if (FLAGS_req_size > 0) { | ||
| 368 | + if (resp_name.size() != g_name.size()) { | ||
| 369 | + if (FLAGS_print_response_log) { | ||
| 370 | + LOG(ERROR) << "[MISMATCH][name size] req=" << g_total_cnt.load() | ||
| 371 | + << " sent=" << g_name.size() | ||
| 372 | + << " recv=" << resp_name.size(); | ||
| 373 | + } | ||
| 374 | + } else if (resp_name != g_name) { | ||
| 375 | + size_t diffs = 0; | ||
| 376 | + size_t first = (size_t)-1; | ||
| 377 | + size_t last = 0; | ||
| 378 | + for (size_t i = 0; i < resp_name.size(); ++i) { | ||
| 379 | + if (resp_name[i] != g_name[i]) { | ||
| 380 | + if (first == (size_t)-1) first = i; | ||
| 381 | + last = i; | ||
| 382 | + ++diffs; | ||
| 383 | + } | ||
| 384 | + } | ||
| 385 | + if (FLAGS_print_response_log) { | ||
| 386 | + LOG(ERROR) << "[MISMATCH][name content] req=" << g_total_cnt.load() | ||
| 387 | + << " size=" << resp_name.size() | ||
| 388 | + << " diffs=" << diffs | ||
| 389 | + << " first_off=" << first | ||
| 390 | + << " last_off=" << last | ||
| 391 | + << " (expected pattern: i&0xFF)"; | ||
| 392 | + } | ||
| 393 | + } else if (FLAGS_print_response_log) { | ||
| 394 | + uint64_t req_no = g_total_cnt.load(); | ||
| 395 | + LOG(INFO) << "[OK][name] req=" << req_no | ||
| 396 | + << " size=" << resp_name.size() << " match"; | ||
| 397 | + } | ||
| 398 | + } | ||
| 399 | + | ||
| 362 | if (FLAGS_req_size != 0) { | 400 | if (FLAGS_req_size != 0) { |
| 363 | g_total_bytes.fetch_add(closure->resp->name().size(), butil::memory_order_relaxed); | 401 | g_total_bytes.fetch_add(closure->resp->name().size(), butil::memory_order_relaxed); |
| 364 | } else { | 402 | } else { |
| @@ -757,7 +795,11 @@ void Test(int thread_num, int attachment_size) { | |||
| 757 | // ==================== 主函数 ==================== | 795 | // ==================== 主函数 ==================== |
| 758 | int main(int argc, char* argv[]) { | 796 | int main(int argc, char* argv[]) { |
| 759 | GFLAGS_NAMESPACE::ParseCommandLineFlags(&argc, &argv, true); | 797 | GFLAGS_NAMESPACE::ParseCommandLineFlags(&argc, &argv, true); |
| 760 | - g_name.resize(FLAGS_req_size, 'r'); | 798 | + // 用固定的递增字节模式 (0,1,2,...,255,0,1,...) 填充 request.name, |
| 799 | + g_name.resize(FLAGS_req_size, '\0'); | ||
| 800 | + for (size_t i = 0; i < g_name.size(); ++i) { | ||
| 801 | + g_name[i] = (char)(i & 0xFF); | ||
| 802 | + } | ||
| 761 | 803 | ||
| 762 | g_token.store(FLAGS_initial_tokens); | 804 | g_token.store(FLAGS_initial_tokens); |
| 763 | 805 | ||
| @@ -134,8 +134,9 @@ public: | |||
| 134 | } | 134 | } |
| 135 | 135 | ||
| 136 | brpc::Controller* cntl = static_cast<brpc::Controller*>(cntl_base); | 136 | brpc::Controller* cntl = static_cast<brpc::Controller*>(cntl_base); |
| 137 | - | 137 | + |
| 138 | - response->set_name(g_name); | 138 | + // 把 client 发送的 name 字段原样 echo 回去, |
| 139 | + response->set_name(request->name()); | ||
| 139 | if (request->echo_attachment()) { | 140 | if (request->echo_attachment()) { |
| 140 | cntl->response_attachment().append(cntl->request_attachment()); | 141 | cntl->response_attachment().append(cntl->request_attachment()); |
| 141 | g_total_bytes.fetch_add(cntl->response_attachment().size(), butil::memory_order_relaxed); | 142 | g_total_bytes.fetch_add(cntl->response_attachment().size(), butil::memory_order_relaxed); |