Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix rpc_press can't send request equably #1763

Merged
merged 4 commits into from
Jun 20, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 6 additions & 21 deletions tools/rpc_press/rpc_press_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,14 +219,8 @@ void RpcPress::sync_client() {
}
const int thread_index = g_thread_count.fetch_add(1, butil::memory_order_relaxed);
int msg_index = thread_index;
std::deque<int64_t> timeq;
size_t MAX_QUEUE_SIZE = (size_t)req_rate;
if (MAX_QUEUE_SIZE < 100) {
MAX_QUEUE_SIZE = 100;
} else if (MAX_QUEUE_SIZE > 2000) {
MAX_QUEUE_SIZE = 2000;
}
timeq.push_back(butil::gettimeofday_us());
int64_t last_expected_time = butil::gettimeofday_us();
const int64_t interval = (int64_t) (1000000 / req_rate);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

如果req_rate > 100000 (虽然实际上极少出现),会导致interval变成0
而原来的代码还能处理这种情况

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

如果req_rate > 100000,确实有你说的这个问题。但是考虑到单线程发送1百万qps是几乎不可能的,我在新代码中设置了单线程发送qps的上限为1百万,这也是一个合理的限制。同时使用nanosecond来计算interval,这样可以使高qps情况下interval计算更为准确。

while (!_stop) {
brpc::Controller* cntl = new brpc::Controller;
msg_index = (msg_index + _options.test_thread_num) % _msgs.size();
Expand All @@ -248,20 +242,11 @@ void RpcPress::sync_client() {
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 expected_time = last_expected_time + interval;
if (end_time < expected_time) {
usleep(expected_time - end_time);
}
last_expected_time = expected_time;
}
}
}
Expand Down