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


##########
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: dev-unsubscr...@brpc.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@brpc.apache.org
For additional commands, e-mail: dev-h...@brpc.apache.org

Reply via email to