MCPcopy Create free account
hub / github.com/apache/brpc / PerfTest

Function PerfTest

test/brpc_load_balancer_unittest.cpp:248–304  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

246
247template<typename DBD>
248void PerfTest(int thread_num, bool modify_during_reading) {
249 g_started = false;
250 g_stopped = false;
251 DBD dbd;
252 for (int i = 0; i < 1024; ++i) {
253 dbd.Modify(AddMapN, i);
254 }
255 pthread_t threads[thread_num];
256 std::vector<PerfArgs<DBD>> args(thread_num);
257 for (int i = 0; i < thread_num; ++i) {
258 args[i].dbd = &dbd;
259 ASSERT_EQ(0, pthread_create(&threads[i], NULL, read_dbd<DBD>, &args[i]));
260 }
261 while (true) {
262 bool all_ready = true;
263 for (int i = 0; i < thread_num; ++i) {
264 if (!args[i].ready) {
265 all_ready = false;
266 break;
267 }
268 }
269 if (all_ready) {
270 break;
271 }
272 usleep(1000);
273 }
274 g_started = true;
275 char prof_name[32];
276 snprintf(prof_name, sizeof(prof_name), "doubly_buffered_data_%d.prof", ++g_prof_name_counter);
277 ProfilerStart(prof_name);
278 int64_t run_ms = 5 * 1000;
279 if (modify_during_reading) {
280 int64_t start = butil::cpuwide_time_ms();
281 int i = 1;
282 while (butil::cpuwide_time_ms() - start < run_ms) {
283 ASSERT_TRUE(dbd.Modify(AddMapN, i++));
284 usleep(1000);
285 }
286 } else {
287 usleep(run_ms * 1000);
288 }
289 ProfilerStop();
290 g_stopped = true;
291 int64_t wait_time = 0;
292 int64_t count = 0;
293 for (int i = 0; i < thread_num; ++i) {
294 pthread_join(threads[i], NULL);
295 wait_time += args[i].elapse_ns;
296 count += args[i].counter;
297 }
298 LOG(INFO) << butil::class_name<DBD>()
299 << " thread_num=" << thread_num
300 << " modify_during_reading=" << modify_during_reading
301 << " count=" << count
302 << " average_time=" << wait_time / (double)count
303 << " qps=" << (double)count / wait_time * (1000 * 1000 * 1000);
304}
305

Callers

nothing calls this directly

Calls 5

snprintfFunction · 0.85
ProfilerStartFunction · 0.85
cpuwide_time_msFunction · 0.85
ProfilerStopFunction · 0.85
ModifyMethod · 0.80

Tested by

no test coverage detected