1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387
|
/*
* Copyright 2009- ECMWF.
*
* This software is licensed under the terms of the Apache Licence version 2.0
* which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
* In applying this licence, ECMWF does not waive the privileges and immunities
* granted to it by virtue of its status as an intergovernmental organisation
* nor does it submit to any jurisdiction.
*/
#include <cstdlib>
#include <fstream>
#include <boost/test/unit_test.hpp>
#include "InvokeServer.hpp"
#include "SCPort.hpp"
#include "TestHelper.hpp"
#include "ecflow/client/ClientEnvironment.hpp"
#include "ecflow/client/ClientInvoker.hpp"
#include "ecflow/client/Rtt.hpp"
#include "ecflow/core/File.hpp"
#include "ecflow/core/Str.hpp"
#include "ecflow/core/Timer.hpp"
#include "ecflow/node/Defs.hpp"
#include "ecflow/node/Suite.hpp"
#include "ecflow/node/Task.hpp"
#include "ecflow/test/scaffold/Naming.hpp"
using namespace std;
using namespace ecf;
BOOST_AUTO_TEST_SUITE(S_Client)
BOOST_AUTO_TEST_SUITE(T_SinglePerf)
// ************************************************************************************
// Note: If you make edits to node tree, they will have no effect until the server is rebuilt
// ************************************************************************************
// These thresholds are based on the largest definition in the tests.
static int load_threshold_ms = 4500;
static int begin_threshold_ms = 550;
static double sync_full_threshold_s = 2.6;
static double full_threshold_s = 2.9;
static double suspend_threshold_s = 3.5;
static double resume_threshold_s = 3.5;
static double force_threshold_s = 8.5;
static double check_pt_threshold_s = 1.0;
static double client_cmds_threshold_s = 8.5;
static void sync_and_news_local(ClientInvoker& theClient) {
{
cout << " news_local() : ";
DurationTimer duration_timer;
theClient.news_local();
cout << duration_timer.elapsed_seconds();
}
{
cout << " sync_local() : ";
DurationTimer duration_timer;
theClient.sync_local();
cout << duration_timer.elapsed_seconds() << endl;
}
}
void time_load_and_downloads(ClientInvoker& theClient,
const std::string& host,
const std::string& port,
const std::string& directory) {
auto full_path = fs::absolute(directory);
BOOST_CHECK(fs::exists(full_path));
BOOST_CHECK(fs::is_directory(full_path));
int count = 10;
std::vector<std::string> paths;
// std::cout << "\nIn directory: " << full_path.directory_string() << "\n\n";
fs::directory_iterator end_iter;
for (fs::directory_iterator dir_itr(full_path); dir_itr != end_iter; ++dir_itr) {
try {
fs::path relPath(directory + "/" + dir_itr->path().filename().string());
// recurse down directories
if (is_directory(dir_itr->status())) {
time_load_and_downloads(theClient, host, port, relPath.string());
continue;
}
cout << "\n" << relPath.string() << " : file size " << fs::file_size(relPath) << endl;
{
DurationTimer duration_timer;
BOOST_REQUIRE_MESSAGE(theClient.loadDefs(relPath.string()) == 0,
"load defs failed \n"
<< theClient.errorMsg());
cout << " Load: " << duration_timer.elapsed_milliseconds() << "ms" << endl;
BOOST_CHECK_MESSAGE(duration_timer.elapsed_milliseconds() < load_threshold_ms,
"regression load(" << duration_timer.elapsed_milliseconds()
<< "), exceeded threshold of " << load_threshold_ms);
}
{
DurationTimer duration_timer;
BOOST_REQUIRE_MESSAGE(theClient.begin_all_suites() == 0, "begin failed \n" << theClient.errorMsg());
cout << " Begin: " << duration_timer.elapsed_milliseconds() << "ms" << endl;
BOOST_CHECK_MESSAGE(duration_timer.elapsed_milliseconds() < begin_threshold_ms,
"regression begin(" << duration_timer.elapsed_milliseconds()
<< "), exceeded threshold of " << begin_threshold_ms);
}
{
cout << " Download(news_local):";
cout.flush();
ClientInvoker client_news(host, port);
DurationTimer duration_timer;
for (int i = 0; i < count; i++) {
if (i == 0 || i != 1) {
client_news.news_local();
switch (client_news.server_reply().get_news()) {
case ServerReply::DO_FULL_SYNC:
cout << "FULL ";
break;
case ServerReply::NEWS:
cout << "NEWS ";
break;
case ServerReply::NO_NEWS:
cout << "NO_NEWS ";
break;
}
}
else if (i == 1) {
client_news.sync_local();
}
}
cout << ": 1:news_local(),2:sync_local(),n:news_local with the new Client: "
<< duration_timer.elapsed_milliseconds() << "(ms)" << endl;
}
{
cout << " Download(Sync): ";
cout.flush();
for (int i = 0; i < count; i++) {
DurationTimer duration_timer;
theClient.sync_local();
int ms = duration_timer.elapsed_milliseconds();
cout << ms << " ";
}
cout << ":(milli-seconds) sync_local() with the same Client. First call updates cache." << endl;
}
{
// On construction of Defs, hence should be slightly faster
cout << " Download(Sync-FULL): ";
cout.flush();
double total = 0;
for (int i = 0; i < count; i++) {
ClientInvoker client(host, port);
DurationTimer duration_timer;
client.sync_local();
int ms = duration_timer.elapsed_milliseconds();
cout << ms << " ";
total += ms;
}
double average = (double)(total) / ((double)count * 1000);
cout << ": Avg:" << average << "(sec) : sync_local() with *different* clients.uses cache!" << endl;
BOOST_CHECK_MESSAGE(average < sync_full_threshold_s,
"regression Sync-FULL(" << average << "), exceeded threshold of "
<< sync_full_threshold_s);
}
{
cout << " Download(FULL): ";
cout.flush();
double total = 0;
for (int i = 0; i < count; i++) {
ClientInvoker client(host, port);
DurationTimer duration_timer;
theClient.getDefs();
int ms = duration_timer.elapsed_milliseconds();
cout << ms << " ";
total += ms;
}
double average = (double)(total) / ((double)count * 1000);
cout << ": Avg:" << average << "(sec) : get_defs() from different client" << endl;
BOOST_CHECK_MESSAGE(average < full_threshold_s,
"regression FULL(sync)(" << average << ") exceeded threshold of "
<< full_threshold_s);
}
{
std::vector<task_ptr> all_tasks;
if (!theClient.defs()) {
theClient.sync_local();
}
theClient.defs()->get_all_tasks(all_tasks);
paths.clear();
paths.reserve(all_tasks.size());
for (size_t i = 0; i < all_tasks.size(); i++) {
paths.push_back(all_tasks[i]->absNodePath());
}
{
cout << " Suspend " << paths.size() << " tasks : ";
cout.flush();
DurationTimer duration_timer;
theClient.suspend(paths);
cout << duration_timer.elapsed_seconds();
sync_and_news_local(theClient);
}
{
cout << " Resume " << paths.size() << " tasks : ";
cout.flush();
DurationTimer duration_timer;
theClient.resume(paths);
cout << duration_timer.elapsed_seconds();
sync_and_news_local(theClient);
}
{
cout << " Suspend " << paths.size() << " tasks : ";
cout.flush();
theClient.set_auto_sync(true);
DurationTimer duration_timer;
theClient.suspend(paths);
cout << duration_timer.elapsed_seconds() << " : auto-sync" << endl;
BOOST_CHECK_MESSAGE(duration_timer.elapsed_seconds() < suspend_threshold_s,
"regression suspend(" << duration_timer.elapsed_seconds()
<< ") exceeded threshold of " << suspend_threshold_s);
theClient.set_auto_sync(false);
}
{
cout << " Resume " << paths.size() << " tasks : ";
cout.flush();
theClient.set_auto_sync(true);
DurationTimer duration_timer;
theClient.resume(paths);
cout << duration_timer.elapsed_seconds() << " : auto-sync" << endl;
BOOST_CHECK_MESSAGE(duration_timer.elapsed_seconds() < resume_threshold_s,
"regression resume(" << duration_timer.elapsed_seconds()
<< ") exceeded threshold of " << resume_threshold_s);
theClient.set_auto_sync(false);
}
{
cout << " check " << paths.size() << " tasks : ";
cout.flush();
DurationTimer duration_timer;
theClient.check(paths);
cout << duration_timer.elapsed_seconds();
sync_and_news_local(theClient);
}
{
cout << " kill " << paths.size() << " tasks : ";
cout.flush();
DurationTimer duration_timer;
theClient.kill(paths);
cout << duration_timer.elapsed_seconds();
sync_and_news_local(theClient);
}
{
// force complete on all tasks, on some suites(3199.def), can cause infinite recursion, i.e cause
// repeats to loop Hence we will call force aborted instead. Also AVOID active/submitted otherwise
// we spend a huge time adding zombies, for the subsequent force cmd below. Node: state change
// memento, will also persist duration time of state change.
cout << " force " << paths.size() << " tasks : ";
cout.flush();
DurationTimer duration_timer;
theClient.force(paths, "aborted");
cout << duration_timer.elapsed_seconds() << " force(aborted)";
sync_and_news_local(theClient);
}
{
cout << " force " << paths.size() << " tasks : ";
cout.flush();
theClient.set_auto_sync(true);
DurationTimer duration_timer;
theClient.force(
paths, "queued"); // can't use aborted again, as it already aborted, and hence will be ignored
cout << duration_timer.elapsed_seconds() << " : auto-sync : force(queued)" << endl;
BOOST_CHECK_MESSAGE(duration_timer.elapsed_seconds() < force_threshold_s,
"regression force(" << duration_timer.elapsed_seconds()
<< ") exceeded threshold of " << force_threshold_s);
theClient.set_auto_sync(false);
}
}
{
cout << " Check pt: ";
cout.flush();
double total = 0;
for (int i = 0; i < count; i++) {
DurationTimer duration_timer;
theClient.checkPtDefs();
int ms = duration_timer.elapsed_milliseconds();
cout << ms << " ";
total += ms;
}
double average = (double)(total) / ((double)count * 1000);
cout << ": Avg:" << average << "(s)" << endl;
BOOST_CHECK_MESSAGE(average < check_pt_threshold_s,
"regression in check_pt(" << average << ") exceeded threshold of "
<< check_pt_threshold_s);
}
{
cout << " client cmds: ";
cout.flush();
DurationTimer duration_timer;
size_t i;
for (i = 0; i < paths.size() && i < 2000; i++) {
theClient.suspend(paths[i]);
theClient.sync_local();
theClient.resume(paths[i]);
theClient.sync_local();
theClient.force(paths[i], "aborted");
theClient.sync_local();
theClient.alter(paths[i], "add", "variable", "XXXX", "XXXX");
theClient.sync_local();
theClient.requeue(paths[i]);
theClient.sync_local();
}
cout << i << " times " << duration_timer.elapsed_seconds()
<< "(s) (sync_local) with same client (suspend,resume,force,alter,requeue)" << endl;
BOOST_CHECK_MESSAGE(duration_timer.elapsed_seconds() < client_cmds_threshold_s,
"regression, exceeded threshold of " << client_cmds_threshold_s);
}
{
cout << " client cmds: ";
cout.flush();
theClient.set_auto_sync(true);
DurationTimer duration_timer;
size_t i;
for (i = 0; i < paths.size() && i < 2000; i++) {
theClient.suspend(paths[i]);
theClient.resume(paths[i]);
theClient.force(paths[i], "aborted");
theClient.alter(paths[i], "add", "variable", "ZZZZ", "XXXX");
theClient.requeue(paths[i]);
}
cout << i << " times " << duration_timer.elapsed_seconds()
<< "(s) (auto_sync ) with same client (suspend,resume,force,alter,requeue)" << endl;
BOOST_CHECK_MESSAGE(duration_timer.elapsed_seconds() < client_cmds_threshold_s,
"regression, exceeded threshold of " << client_cmds_threshold_s);
theClient.set_auto_sync(false);
}
{
DurationTimer duration_timer;
BOOST_REQUIRE_MESSAGE(theClient.delete_all(true) == 0,
"delete all defs failed \n"
<< theClient.errorMsg());
cout << " Delete: " << duration_timer.elapsed_milliseconds() << "ms" << endl;
}
}
catch (const std::exception& ex) {
std::cout << dir_itr->path().filename() << " " << ex.what() << std::endl;
}
}
}
BOOST_AUTO_TEST_CASE(test_perf_for_large_defs) {
ECF_NAME_THIS_TEST();
if (ecf::environment::has(ecf::environment::ECF_SSL)) {
load_threshold_ms = 8000; // 4500;
begin_threshold_ms = 800; // 400;
sync_full_threshold_s = 4.5; // 2.6;
full_threshold_s = 4.5; // 2.8;
suspend_threshold_s = 5.8; // 3.5;
resume_threshold_s = 6.5; // 3.5;
force_threshold_s = 15; // 8.5;
check_pt_threshold_s = 1.5; // 1.0;
client_cmds_threshold_s = 950; // 8.5;
}
if (auto ecf_test_defs_dir = ecf::environment::fetch("ECF_TEST_DEFS_DIR"); !ecf_test_defs_dir) {
std::cout << "Ignoring test! Environment variable ECF_TEST_DEFS_DIR is not defined\n";
}
else if (!fs::exists(ecf_test_defs_dir.value())) {
std::cout << "Ignoring test! Test definitions directory " << ecf_test_defs_dir.value() << " does not exist\n";
}
else {
/// This will remove checkpt and backup , to avoid server from loading it. (i.e from previous test)
InvokeServer invokeServer("Client:: ...test_perf_for_large_defs:", SCPort::next());
BOOST_REQUIRE_MESSAGE(invokeServer.server_started(),
"Server failed to start on " << invokeServer.host() << ":" << invokeServer.port());
ClientInvoker theClient(invokeServer.host(), invokeServer.port());
time_load_and_downloads(theClient, invokeServer.host(), invokeServer.port(), ecf_test_defs_dir.value());
}
}
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_SUITE_END()
|