Test suite for RWebWindow communication performance.
#include <iostream>
#include <chrono>
std::shared_ptr<ROOT::RWebWindow> window;
int num_clients = 1;
bool window_terminated = false;
bool call_show = true;
bool batch_mode = false;
int current_counter = 0;
auto start_tm = std::chrono::high_resolution_clock::now();
auto firstmsg_tm = start_tm;
auto stop_tm = start_tm;
std::string round_trip = "<not defined>";
void ProcessData(unsigned connid, const std::string &arg)
{
if (arg.find("PING:") == 0) {
window->Send(connid, arg);
} else if (arg == "first") {
firstmsg_tm = std::chrono::high_resolution_clock::now();
std::vector<std::string> clients;
for(
int n = 1;
n < num_clients; ++
n)
clients.emplace_back(".." + window->GetUrl(false));
} else if (arg.find("SHOW:") == 0) {
std::string msg = arg.substr(5);
if (!batch_mode)
std::cout << msg << std::endl;
if (msg.find("Cnt:") == 0) {
int counter = std::stoi(msg.substr(4));
if (counter > 0)
current_counter = counter;
}
auto p = msg.find(
"round-trip:");
if (
p > 0) round_trip = msg.substr(
p);
} else if (arg == "halt") {
window_terminated = true;
window->TerminateROOT();
}
}
enum TestModes {
modeDefault = 0,
modeMinimalTimer = 1,
modeHttpThread = 2,
modeHttpWindowThread = 3,
modeCivetThread = 4
};
enum MajorModes {
majorDefault = 0,
majorLongpoll = 1
};
void ping(
int nclients = 1,
int test_mode = 0)
{
num_clients = nclients;
batch_mode =
gROOT->IsBatch();
if (test_mode < 0) test_mode = 0;
int major_mode = test_mode / 10;
test_mode = test_mode % 10;
if (test_mode > modeCivetThread)
test_mode = modeDefault;
if (num_clients < 1)
num_clients = 1;
else if (num_clients > 1000)
num_clients = 1000;
if (major_mode == majorLongpoll)
if (num_clients > 5)
if ((test_mode == modeHttpThread) || (test_mode == modeHttpWindowThread))
if (test_mode == modeMinimalTimer)
window->SetConnLimit(num_clients);
std::string fname = __FILE__;
auto pos = fname.find("ping.cxx");
if (pos > 0)
fname.resize(pos);
else
fname =
gROOT->GetTutorialsDir() + std::string(
"/webgui/ping/");
fname.append("ping.html");
window->SetDefaultPage("file:" + fname);
window->SetGeometry(300, 500);
window->SetDataCallBack(ProcessData);
if (test_mode == modeCivetThread)
window->UseServerThreads();
if (test_mode == modeHttpWindowThread)
window->StartThread();
if (call_show)
window->Show(batch_mode ? "headless" : "");
else
std::cout << "Window url is: " << window->GetUrl(true) << std::endl;
if (batch_mode) {
const int run_limit = 200;
const double fullrun_time = 100., startup_time = 70.;
start_tm = firstmsg_tm = std::chrono::high_resolution_clock::now();
window->WaitFor([=](double tm) { return (current_counter >= run_limit) || (tm > fullrun_time) || ((current_counter == 0) && (tm > startup_time)) ? 1 : 0; });
stop_tm = std::chrono::high_resolution_clock::now();
auto startuptime_int = std::chrono::duration_cast<std::chrono::milliseconds>(firstmsg_tm - start_tm);
auto runttime_int = std::chrono::duration_cast<std::chrono::milliseconds>(stop_tm - firstmsg_tm);
if (current_counter >= run_limit)
std::cout << "PING-PONG TEST COMPLETED " << round_trip;
else
std::cout << "PING-PONG TEST FAIL cnt:" << current_counter;
std::cout << " startup: " << startuptime_int.count() << "ms" << " run: " << runttime_int.count() << "ms" << std::endl;
}
}
winID h TVirtualViewer3D TVirtualGLPainter p
static std::shared_ptr< RWebWindow > Create()
Create new RWebWindow Using default RWebWindowsManager.
static TString ToJSON(const T *obj, Int_t compact=0, const char *member_name=nullptr)
virtual void SetValue(const char *name, const char *value, EEnvLevel level=kEnvChange, const char *type=nullptr)
Set the value of a resource or create a new resource.