wwbmmm commented on code in PR #1763:
URL: https://github.com/apache/incubator-brpc/pull/1763#discussion_r874297877


##########
tools/rpc_press/rpc_press_impl.cpp:
##########
@@ -247,21 +242,12 @@ void RpcPress::sync_client() {
         if (_options.test_req_rate <= 0) { 
             brpc::Join(cid1);
         } else {
-            int64_t end_time = butil::gettimeofday_us();
-            int64_t expected_elp = 0;
-            int64_t actual_elp = 0;
-            timeq.push_back(end_time);
-            if (timeq.size() > MAX_QUEUE_SIZE) {
-                actual_elp = end_time - timeq.front();
-                timeq.pop_front();
-                expected_elp = (int64_t)(1000000 * timeq.size() / req_rate);
-            } else {
-                actual_elp = end_time - timeq.front();
-                expected_elp = (int64_t)(1000000 * (timeq.size() - 1) / 
req_rate);
-            }
-            if (actual_elp < expected_elp) {
-                usleep(expected_elp - actual_elp);
+            int64_t end_time = butil::monotonic_time_ns();
+            int64_t expected_time = last_expected_time + interval;
+            if (end_time < expected_time) {
+                
std::this_thread::sleep_for(std::chrono::nanoseconds(expected_time - end_time));

Review Comment:
   这里用usleep((expected_time - end_time)/1000)就可以,不用引入std的依赖



-- 
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