Skip to content

Commit

Permalink
Merge pull request #9 from stxyang/main
Browse files Browse the repository at this point in the history
enable "start_stats_thread" in lua interface "start_server"
  • Loading branch information
wallyatgithub authored Oct 16, 2022
2 parents 58c8c9e + 590e1f1 commit 591095e
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 19 deletions.
43 changes: 26 additions & 17 deletions asio_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -475,19 +475,27 @@ void start_statistic_thread(std::vector<uint64_t>& totalReqsReceived,
uint64_t total_unmatched_responses_till_now = 0;
uint64_t counter = 0;

const size_t billion_width = 10 + 6;
const size_t million_width = 7 + 2;
auto req_name_width = get_req_name_max_size(config_schema);
auto resp_name_width = get_resp_name_max_size(config_schema);
auto resp_name_width = get_resp_name_max_size(config_schema) + 1;
size_t request_width = 0;

auto period_start = std::chrono::steady_clock::now();
while (true)
{
std::stringstream SStream;
std::this_thread::sleep_for(std::chrono::seconds(1));
if (counter % 10 == 0)
{
SStream << "req-name, resp-name, msg-total, throttled-total, rps, throttled-rps" << std::endl;
}
// if (counter % 10 == 0)
// {
SStream << std::endl << std::setw(req_name_width) << "req-name"
<< "," << std::setw(resp_name_width) << "resp-name"
<< "," << std::setw(billion_width) << "msg-total"
<< "," << std::setw(billion_width) << "throttled-total"
<< "," << std::setw(million_width) << "rps"
<< "," << std::setw(billion_width) << "throttled-rps"
<< std::endl;
// }
counter++;

auto resp_sent_till_last = resp_sent_till_now;
Expand Down Expand Up @@ -549,31 +557,31 @@ void start_statistic_thread(std::vector<uint64_t>& totalReqsReceived,
{
SStream << std::setw(req_name_width) << config_schema.service[req_index].request.name
<< "," << std::setw(resp_name_width) << config_schema.service[req_index].responses[resp_index].name
<< "," << std::setw(req_name_width) << resp_sent_till_now[req_index][resp_index]
<< "," << std::setw(req_name_width) << resp_throttled_till_now[req_index][resp_index]
<< "," << std::setw(req_name_width) << ((resp_sent_till_now[req_index][resp_index] -
<< "," << std::setw(billion_width) << resp_sent_till_now[req_index][resp_index]
<< "," << std::setw(billion_width) << resp_throttled_till_now[req_index][resp_index]
<< "," << std::setw(million_width) << ((resp_sent_till_now[req_index][resp_index] -
resp_sent_till_last[req_index][resp_index])*std::milli::den) / period_duration
<< "," << std::setw(req_name_width) << ((resp_throttled_till_now[req_index][resp_index] -
<< "," << std::setw(billion_width) << ((resp_throttled_till_now[req_index][resp_index] -
resp_throttled_till_last[req_index][resp_index])*std::milli::den) / period_duration
<< std::endl;
}
}
SStream << std::setw(req_name_width) << "SUM"
<< "," << std::setw(resp_name_width) << "SUM"
<< "," << std::setw(req_name_width) << total_resp_sent_till_now
<< "," << std::setw(req_name_width) << total_resp_throttled_till_now
<< "," << std::setw(req_name_width) << ((total_resp_sent_till_now - total_resp_sent_till_last)*std::milli::den) /
<< "," << std::setw(billion_width) << total_resp_sent_till_now
<< "," << std::setw(billion_width) << total_resp_throttled_till_now
<< "," << std::setw(million_width) << ((total_resp_sent_till_now - total_resp_sent_till_last)*std::milli::den) /
period_duration
<< "," << std::setw(req_name_width) << ((total_resp_throttled_till_now - total_resp_throttled_till_last)
<< "," << std::setw(billion_width) << ((total_resp_throttled_till_now - total_resp_throttled_till_last)
*std::milli::den) / period_duration
<< std::endl;

SStream << std::setw(req_name_width) << "UNMATCHED"
<< "," << std::setw(resp_name_width) << "---"
<< "," << std::setw(req_name_width) << total_unmatched_responses_till_now
<< "," << std::setw(req_name_width) << "---"
<< "," << std::setw(req_name_width) << ((total_unmatched_responses_till_now - total_unmatched_responses_till_last)*std::milli::den) / period_duration
<< "," << std::setw(req_name_width) << "---"
<< "," << std::setw(billion_width) << total_unmatched_responses_till_now
<< "," << std::setw(billion_width) << "---"
<< "," << std::setw(million_width) << ((total_unmatched_responses_till_now - total_unmatched_responses_till_last)*std::milli::den) / period_duration
<< "," << std::setw(billion_width) << "---"
<< std::endl;
if (config_schema.statistics_file.empty())
{
Expand Down Expand Up @@ -644,6 +652,7 @@ void start_server(const std::string& config_file_name, bool start_stats_thread,
}
if (start_stats_thread)
{
std::cerr << "start_statistic_thread" << std::endl;
start_statistic_thread(totalReqsReceived, respStats, totalUnMatchedResponses, config_schema);
}

Expand Down
10 changes: 8 additions & 2 deletions h2load_lua.cc
Original file line number Diff line number Diff line change
Expand Up @@ -991,6 +991,7 @@ H2Server_Config_Schema config_schema;
int start_server(lua_State* L)
{
std::string config_file_name;
bool b_start_stats = false;
int top = lua_gettop(L);
for (int i = 0; i < top; i++)
{
Expand All @@ -1003,6 +1004,11 @@ int start_server(lua_State* L)
config_file_name.assign(str, len);
break;
}
case LUA_TBOOLEAN:
{
b_start_stats = lua_toboolean(L, -1);
break;
}
default:
{
std::cerr << __FUNCTION__ << ": invalid parameter passed in" << std::endl;
Expand All @@ -1022,13 +1028,13 @@ int start_server(lua_State* L)

std::promise<void> ready_promise;

auto thread_func = [config_file_name, &ready_promise]()
auto thread_func = [config_file_name, &ready_promise, b_start_stats]()
{
auto init_cbk = [&ready_promise]()
{
ready_promise.set_value();
};
start_server(config_file_name, true, init_cbk);
start_server(config_file_name, b_start_stats, init_cbk);
};
std::thread serverThread(thread_func);
auto bootstrap_thread_id = serverThread.get_id();
Expand Down

0 comments on commit 591095e

Please sign in to comment.