Spicy-cream commented on code in PR #3535:
URL: https://github.com/apache/brpc/pull/3535#discussion_r4661186502


##########
example/ubring_performance/client.cpp:
##########
@@ -130,107 +135,79 @@ class PerformanceTest {
             }
             LOG(WARNING) << "RPC call failed, retrying... (" << retry << " 
left): " << cntl.ErrorText();
             retry--;
-            bthread_usleep(1000000); // 100ms delay before retry
+            bthread_usleep(1000000);
         }
         LOG(ERROR) << "RPC call failed after multiple retries";
         return -1;
     }
 
-    struct RespClosure {
-        brpc::Controller* cntl;
-        test::PerfTestResponse* resp;
-        PerformanceTest* test;
-    };
-
-    void SendRequest() {
-        if (FLAGS_expected_qps > 0) {
-            while (g_token.load(butil::memory_order_relaxed) <= 0) {
-                bthread_usleep(10);
+    static void* RunTest(void* arg) {
+        auto* self = static_cast<PerformanceTest*>(arg);
+        const int64_t deadline = butil::monotonic_time_ns() +
+            static_cast<int64_t>(FLAGS_test_seconds) * 1000000000L;
+        uint64_t sent = 0;
+        test::PerfTestService_Stub stub(self->_channel);
+        while (!g_failed.load() &&
+               (FLAGS_test_iterations == 0 ||
+                sent < static_cast<uint64_t>(FLAGS_test_iterations))) {
+            std::vector<brpc::Controller> cntls(FLAGS_queue_depth);
+            std::vector<test::PerfTestRequest> requests(FLAGS_queue_depth);
+            std::vector<test::PerfTestResponse> responses(FLAGS_queue_depth);
+            int pending = 0;
+            for (; pending < FLAGS_queue_depth; ++pending) {
+                if ((FLAGS_test_iterations > 0 &&
+                     sent >= static_cast<uint64_t>(FLAGS_test_iterations)) ||
+                    !WaitForRequest(deadline)) {
+                    break;
+                }
+                requests[pending].set_echo_attachment(self->_echo_attachment);
+                cntls[pending].request_attachment().append(self->_attachment);
+                stub.Test(&cntls[pending], &requests[pending],
+                          &responses[pending], brpc::DoNothing());
+                ++sent;
             }
-            g_token.fetch_sub(1, butil::memory_order_relaxed);
-        }
-        RespClosure* closure = new RespClosure;
-        test::PerfTestRequest request;
-        closure->resp = new test::PerfTestResponse();
-        closure->cntl = new brpc::Controller();
-        request.set_echo_attachment(_echo_attachment);
-        closure->cntl->request_attachment().append(_attachment);
-        closure->test = this;
-        google::protobuf::Closure* done = brpc::NewCallback(&HandleResponse, 
closure);
-        test::PerfTestService_Stub stub(_channel);
-        stub.Test(closure->cntl, &request, closure->resp, done);
-    }
-
-    static void HandleResponse(RespClosure* closure) {
-        std::unique_ptr<brpc::Controller> cntl_guard(closure->cntl);
-        std::unique_ptr<test::PerfTestResponse> response_guard(closure->resp);
-        if (closure->cntl->Failed()) {
-            LOG(ERROR) << "RPC call failed: " << closure->cntl->ErrorText();
-            // RPCs in this example are expected to succeed. Silently ignoring
-            // failures would hide problems and invalidate the performance 
result.
-            closure->test->_stop = true;
-            return;
-        }
-
-        g_latency_recorder << closure->cntl->latency_us();
-        if (closure->resp->cpu_usage().size() > 0) {
-            g_server_cpu_recorder << atof(closure->resp->cpu_usage().c_str()) 
* 100;
-        }
-        g_total_bytes.fetch_add(closure->cntl->request_attachment().size(), 
butil::memory_order_relaxed);
-        g_total_cnt.fetch_add(1, butil::memory_order_relaxed);
-
-        cntl_guard.reset(nullptr);
-        response_guard.reset(nullptr);
-
-        if (closure->test->_iterations == 0 && FLAGS_test_iterations > 0) {
-            closure->test->_stop = true;
-            return;
-        }
-        --closure->test->_iterations;
-        uint64_t last = g_last_time.load(butil::memory_order_relaxed);
-        uint64_t now = butil::gettimeofday_us();
-        if (now > last && now - last > 100000) {
-            if (g_last_time.exchange(now, butil::memory_order_relaxed) == 
last) {
-                g_client_cpu_recorder << 
-                    
atof(bvar::Variable::describe_exposed("process_cpu_usage").c_str()) * 100;
+            for (int i = 0; i < pending; ++i) {
+                brpc::Join(cntls[i].call_id());

Review Comment:
   fixed
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to