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

如何获取coro_http_client调接口 耗时 #443

Closed
chanwoood opened this issue Nov 20, 2023 · 3 comments
Closed

如何获取coro_http_client调接口 耗时 #443

chanwoood opened this issue Nov 20, 2023 · 3 comments

Comments

@chanwoood
Copy link

通过多个协程去请求服务端:

  coro_http_client client;
  std::vector<async_simple::coro::Lazy<resp_data>> futures;
  for (int i = 0; i < 10; ++i) {
    futures.push_back(client.async_get("http://www.baidu.com/"));
  }

  auto out = co_await async_simple::coro::collectAll(std::move(futures));

  for (auto &item : out) {
    auto result = item.value();
    CHECK(result.status == 200);
  }

这种情况下,如何获取每个接口调用各自耗时呢

@qicosmos
Copy link
Owner

可能得在client.async_get外面套一层计时的代码。
类似于

time begin
client.async_get
time end

elapsed = end - begin

@chanwoood
Copy link
Author

chanwoood commented Nov 20, 2023

可能得在client.async_get外面套一层计时的代码。 类似于

time begin
client.async_get
time end

elapsed = end - begin

多个协程去请求服务端情况下,在外层计时,只能得到所有接口调用总耗时,得不到每个接口单独调用耗时

@chanwoood
Copy link
Author

我自己改了点源码:在 struct resp_data 加个成员变量,async_request 加入计时就可以了。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants