Skip to content

Commit 591095e

Browse files
Merge pull request #9 from stxyang/main
enable "start_stats_thread" in lua interface "start_server"
2 parents 58c8c9e + 590e1f1 commit 591095e

2 files changed

Lines changed: 34 additions & 19 deletions

File tree

asio_util.cc

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -475,19 +475,27 @@ void start_statistic_thread(std::vector<uint64_t>& totalReqsReceived,
475475
uint64_t total_unmatched_responses_till_now = 0;
476476
uint64_t counter = 0;
477477

478+
const size_t billion_width = 10 + 6;
479+
const size_t million_width = 7 + 2;
478480
auto req_name_width = get_req_name_max_size(config_schema);
479-
auto resp_name_width = get_resp_name_max_size(config_schema);
481+
auto resp_name_width = get_resp_name_max_size(config_schema) + 1;
480482
size_t request_width = 0;
481483

482484
auto period_start = std::chrono::steady_clock::now();
483485
while (true)
484486
{
485487
std::stringstream SStream;
486488
std::this_thread::sleep_for(std::chrono::seconds(1));
487-
if (counter % 10 == 0)
488-
{
489-
SStream << "req-name, resp-name, msg-total, throttled-total, rps, throttled-rps" << std::endl;
490-
}
489+
// if (counter % 10 == 0)
490+
// {
491+
SStream << std::endl << std::setw(req_name_width) << "req-name"
492+
<< "," << std::setw(resp_name_width) << "resp-name"
493+
<< "," << std::setw(billion_width) << "msg-total"
494+
<< "," << std::setw(billion_width) << "throttled-total"
495+
<< "," << std::setw(million_width) << "rps"
496+
<< "," << std::setw(billion_width) << "throttled-rps"
497+
<< std::endl;
498+
// }
491499
counter++;
492500

493501
auto resp_sent_till_last = resp_sent_till_now;
@@ -549,31 +557,31 @@ void start_statistic_thread(std::vector<uint64_t>& totalReqsReceived,
549557
{
550558
SStream << std::setw(req_name_width) << config_schema.service[req_index].request.name
551559
<< "," << std::setw(resp_name_width) << config_schema.service[req_index].responses[resp_index].name
552-
<< "," << std::setw(req_name_width) << resp_sent_till_now[req_index][resp_index]
553-
<< "," << std::setw(req_name_width) << resp_throttled_till_now[req_index][resp_index]
554-
<< "," << std::setw(req_name_width) << ((resp_sent_till_now[req_index][resp_index] -
560+
<< "," << std::setw(billion_width) << resp_sent_till_now[req_index][resp_index]
561+
<< "," << std::setw(billion_width) << resp_throttled_till_now[req_index][resp_index]
562+
<< "," << std::setw(million_width) << ((resp_sent_till_now[req_index][resp_index] -
555563
resp_sent_till_last[req_index][resp_index])*std::milli::den) / period_duration
556-
<< "," << std::setw(req_name_width) << ((resp_throttled_till_now[req_index][resp_index] -
564+
<< "," << std::setw(billion_width) << ((resp_throttled_till_now[req_index][resp_index] -
557565
resp_throttled_till_last[req_index][resp_index])*std::milli::den) / period_duration
558566
<< std::endl;
559567
}
560568
}
561569
SStream << std::setw(req_name_width) << "SUM"
562570
<< "," << std::setw(resp_name_width) << "SUM"
563-
<< "," << std::setw(req_name_width) << total_resp_sent_till_now
564-
<< "," << std::setw(req_name_width) << total_resp_throttled_till_now
565-
<< "," << std::setw(req_name_width) << ((total_resp_sent_till_now - total_resp_sent_till_last)*std::milli::den) /
571+
<< "," << std::setw(billion_width) << total_resp_sent_till_now
572+
<< "," << std::setw(billion_width) << total_resp_throttled_till_now
573+
<< "," << std::setw(million_width) << ((total_resp_sent_till_now - total_resp_sent_till_last)*std::milli::den) /
566574
period_duration
567-
<< "," << std::setw(req_name_width) << ((total_resp_throttled_till_now - total_resp_throttled_till_last)
575+
<< "," << std::setw(billion_width) << ((total_resp_throttled_till_now - total_resp_throttled_till_last)
568576
*std::milli::den) / period_duration
569577
<< std::endl;
570578

571579
SStream << std::setw(req_name_width) << "UNMATCHED"
572580
<< "," << std::setw(resp_name_width) << "---"
573-
<< "," << std::setw(req_name_width) << total_unmatched_responses_till_now
574-
<< "," << std::setw(req_name_width) << "---"
575-
<< "," << std::setw(req_name_width) << ((total_unmatched_responses_till_now - total_unmatched_responses_till_last)*std::milli::den) / period_duration
576-
<< "," << std::setw(req_name_width) << "---"
581+
<< "," << std::setw(billion_width) << total_unmatched_responses_till_now
582+
<< "," << std::setw(billion_width) << "---"
583+
<< "," << std::setw(million_width) << ((total_unmatched_responses_till_now - total_unmatched_responses_till_last)*std::milli::den) / period_duration
584+
<< "," << std::setw(billion_width) << "---"
577585
<< std::endl;
578586
if (config_schema.statistics_file.empty())
579587
{
@@ -644,6 +652,7 @@ void start_server(const std::string& config_file_name, bool start_stats_thread,
644652
}
645653
if (start_stats_thread)
646654
{
655+
std::cerr << "start_statistic_thread" << std::endl;
647656
start_statistic_thread(totalReqsReceived, respStats, totalUnMatchedResponses, config_schema);
648657
}
649658

h2load_lua.cc

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -991,6 +991,7 @@ H2Server_Config_Schema config_schema;
991991
int start_server(lua_State* L)
992992
{
993993
std::string config_file_name;
994+
bool b_start_stats = false;
994995
int top = lua_gettop(L);
995996
for (int i = 0; i < top; i++)
996997
{
@@ -1003,6 +1004,11 @@ int start_server(lua_State* L)
10031004
config_file_name.assign(str, len);
10041005
break;
10051006
}
1007+
case LUA_TBOOLEAN:
1008+
{
1009+
b_start_stats = lua_toboolean(L, -1);
1010+
break;
1011+
}
10061012
default:
10071013
{
10081014
std::cerr << __FUNCTION__ << ": invalid parameter passed in" << std::endl;
@@ -1022,13 +1028,13 @@ int start_server(lua_State* L)
10221028

10231029
std::promise<void> ready_promise;
10241030

1025-
auto thread_func = [config_file_name, &ready_promise]()
1031+
auto thread_func = [config_file_name, &ready_promise, b_start_stats]()
10261032
{
10271033
auto init_cbk = [&ready_promise]()
10281034
{
10291035
ready_promise.set_value();
10301036
};
1031-
start_server(config_file_name, true, init_cbk);
1037+
start_server(config_file_name, b_start_stats, init_cbk);
10321038
};
10331039
std::thread serverThread(thread_func);
10341040
auto bootstrap_thread_id = serverThread.get_id();

0 commit comments

Comments
 (0)