MCPcopy Create free account
hub / github.com/baidu/babylon / run_loop

Function run_loop

example/use-execution-queue/example.cpp:58–96  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

56}
57
58void run_loop() {
59 size_t times = 0;
60 int64_t expect_us = 0;
61 while (expect_us < 10000) {
62 ++times;
63 expect_us = 1000000L * times * FLAGS_concurrency / FLAGS_qps;
64 }
65 ::std::cerr << "expect_us " << expect_us << " times " << times << ::std::endl;
66
67 void (*run_once)(int64_t);
68 if (FLAGS_mode == "babylon") {
69 run_once = run_once_babylon;
70 } else if (FLAGS_mode == "bthread") {
71 run_once = run_once_bthread;
72 } else {
73 return;
74 }
75
76 ::std::vector<::babylon::Future<void>> futures;
77 for (size_t i = 0; i < FLAGS_concurrency; ++i) {
78 futures.emplace_back(::babylon::BthreadExecutor::instance().execute([&] {
79 while (!::brpc::IsAskedToQuit()) {
80 auto begin = ::butil::monotonic_time_ns();
81 for (size_t j = 0; j < times; ++j) {
82 run_once(::butil::monotonic_time_ns());
83 }
84 auto end = ::butil::monotonic_time_ns();
85 auto use_us = (end - begin) / 1000;
86 if (use_us < expect_us) {
87 ::usleep(expect_us - use_us);
88 }
89 }
90 }));
91 }
92
93 for (auto& future : futures) {
94 future.get();
95 }
96}
97
98int main(int argc, char* argv[]) {
99 ::gflags::ParseCommandLineFlags(&argc, &argv, true);

Callers 1

mainFunction · 0.70

Calls 4

run_onceFunction · 0.85
emplace_backMethod · 0.80
executeMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected