2016-07-31 10:18:03 -05:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
|
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include <algorithm>
|
2016-08-01 21:21:06 -05:00
|
|
|
#include <chrono>
|
2016-07-31 10:18:03 -05:00
|
|
|
#include <cstdlib>
|
|
|
|
#include <cstring>
|
|
|
|
#include <fstream>
|
|
|
|
#include <iostream>
|
2016-08-01 21:21:06 -05:00
|
|
|
#include <thread>
|
2016-07-31 10:18:03 -05:00
|
|
|
|
|
|
|
#include <Poco/Net/HTTPRequest.h>
|
|
|
|
#include <Poco/Net/HTTPResponse.h>
|
|
|
|
#include <Poco/Thread.h>
|
|
|
|
#include <Poco/URI.h>
|
|
|
|
#include <Poco/Util/Application.h>
|
|
|
|
#include <Poco/Util/HelpFormatter.h>
|
|
|
|
#include <Poco/Util/Option.h>
|
|
|
|
#include <Poco/Util/OptionSet.h>
|
|
|
|
|
2016-07-31 13:17:52 -05:00
|
|
|
#include "TraceFile.hpp"
|
2016-07-31 10:18:03 -05:00
|
|
|
#include "test/helpers.hpp"
|
|
|
|
|
|
|
|
/// Stress testing and performance/scalability benchmarking tool.
|
|
|
|
class Stress: public Poco::Util::Application
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Stress();
|
|
|
|
|
2016-08-21 13:44:24 -05:00
|
|
|
static bool Benchmark;
|
2016-09-19 02:21:47 -05:00
|
|
|
static size_t Iterations;
|
2016-08-04 19:17:13 -05:00
|
|
|
static bool NoDelay;
|
2016-08-21 13:44:24 -05:00
|
|
|
unsigned _numClients;
|
2016-07-31 10:18:03 -05:00
|
|
|
std::string _serverURI;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void defineOptions(Poco::Util::OptionSet& options) override;
|
|
|
|
void handleOption(const std::string& name, const std::string& value) override;
|
|
|
|
int main(const std::vector<std::string>& args) override;
|
|
|
|
};
|
|
|
|
|
|
|
|
using Poco::Net::HTTPRequest;
|
|
|
|
using Poco::Net::HTTPResponse;
|
|
|
|
using Poco::Runnable;
|
|
|
|
using Poco::Thread;
|
|
|
|
using Poco::URI;
|
|
|
|
using Poco::Util::Application;
|
|
|
|
using Poco::Util::HelpFormatter;
|
|
|
|
using Poco::Util::Option;
|
|
|
|
using Poco::Util::OptionSet;
|
|
|
|
|
2016-08-21 22:34:02 -05:00
|
|
|
long percentile(std::vector<long>& v, const double percentile)
|
|
|
|
{
|
|
|
|
std::sort(v.begin(), v.end());
|
|
|
|
|
|
|
|
const auto N = v.size();
|
|
|
|
const double n = (N - 1) * percentile / 100.0 + 1;
|
|
|
|
if (n <= 1)
|
|
|
|
{
|
|
|
|
return v[0];
|
|
|
|
}
|
|
|
|
else if (n >= N)
|
|
|
|
{
|
|
|
|
return v[N - 1];
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto k = static_cast<int>(n);
|
|
|
|
const double d = n - k;
|
|
|
|
return v[k - 1] + d * (v[k] - v[k - 1]);
|
|
|
|
}
|
|
|
|
|
2016-08-13 23:01:13 -05:00
|
|
|
/// Connection class with WSD.
|
2016-08-04 09:31:11 -05:00
|
|
|
class Connection
|
2016-07-31 10:18:03 -05:00
|
|
|
{
|
|
|
|
public:
|
2016-08-04 09:31:11 -05:00
|
|
|
static
|
2016-08-21 19:18:37 -05:00
|
|
|
std::shared_ptr<Connection> create(const std::string& serverURI, const std::string& documentURL, const std::string& sessionId)
|
2016-08-04 09:31:11 -05:00
|
|
|
{
|
|
|
|
Poco::URI uri(serverURI);
|
2016-07-31 10:18:03 -05:00
|
|
|
|
2016-08-21 07:21:59 -05:00
|
|
|
std::unique_lock<std::mutex> lock(Mutex);
|
|
|
|
|
2016-08-04 09:31:11 -05:00
|
|
|
// Load a document and get its status.
|
2016-08-21 07:23:08 -05:00
|
|
|
std::cout << "NewSession [" << sessionId << "]: " << uri.toString() << "... ";
|
2016-10-03 22:43:44 -05:00
|
|
|
|
|
|
|
std::string encodedUri;
|
|
|
|
Poco::URI::encode(documentURL, ":/?", encodedUri);
|
|
|
|
Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_GET, "/lool/" + encodedUri + "/ws");
|
2016-08-04 09:31:11 -05:00
|
|
|
Poco::Net::HTTPResponse response;
|
2016-08-21 13:44:24 -05:00
|
|
|
auto ws = helpers::connectLOKit(uri, request, response, sessionId + ' ');
|
2016-09-02 15:35:44 -05:00
|
|
|
std::cout << "Connected.\n";
|
2016-08-21 19:18:37 -05:00
|
|
|
return std::shared_ptr<Connection>(new Connection(documentURL, sessionId, ws));
|
2016-08-04 09:31:11 -05:00
|
|
|
}
|
|
|
|
|
2016-08-21 19:18:37 -05:00
|
|
|
const std::string& getName() const { return _name; }
|
2016-11-10 02:47:25 -06:00
|
|
|
std::shared_ptr<LOOLWebSocket> getWS() const { return _ws; };
|
2016-08-21 19:18:37 -05:00
|
|
|
|
2016-08-21 13:44:24 -05:00
|
|
|
/// Send a command to the server.
|
2016-08-04 09:31:11 -05:00
|
|
|
void send(const std::string& data) const
|
2016-07-31 10:18:03 -05:00
|
|
|
{
|
2016-08-21 13:44:24 -05:00
|
|
|
helpers::sendTextFrame(_ws, data, _name);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Poll socket until expected prefix is fetched, or timeout.
|
|
|
|
std::vector<char> recv(const std::string& prefix)
|
|
|
|
{
|
|
|
|
return helpers::getResponseMessage(_ws, prefix, _name);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Request loading the document and wait for completion.
|
|
|
|
bool load()
|
|
|
|
{
|
|
|
|
send("load url=" + _documentURL);
|
|
|
|
return helpers::isDocumentLoaded(_ws, _name);
|
2016-07-31 10:18:03 -05:00
|
|
|
}
|
|
|
|
|
2016-08-04 09:31:11 -05:00
|
|
|
private:
|
2016-11-10 02:47:25 -06:00
|
|
|
Connection(const std::string& documentURL, const std::string& sessionId, std::shared_ptr<LOOLWebSocket>& ws) :
|
2016-08-04 09:31:11 -05:00
|
|
|
_documentURL(documentURL),
|
|
|
|
_sessionId(sessionId),
|
2016-08-21 13:44:24 -05:00
|
|
|
_name(sessionId + ' '),
|
2016-08-04 09:31:11 -05:00
|
|
|
_ws(ws)
|
2016-07-31 10:18:03 -05:00
|
|
|
{
|
2016-08-04 09:31:11 -05:00
|
|
|
}
|
2016-07-31 10:18:03 -05:00
|
|
|
|
2016-08-04 09:31:11 -05:00
|
|
|
private:
|
|
|
|
const std::string _documentURL;
|
|
|
|
const std::string _sessionId;
|
2016-08-21 13:44:24 -05:00
|
|
|
const std::string _name;
|
2016-11-10 02:47:25 -06:00
|
|
|
std::shared_ptr<LOOLWebSocket> _ws;
|
2016-08-21 07:21:59 -05:00
|
|
|
static std::mutex Mutex;
|
2016-08-04 09:31:11 -05:00
|
|
|
};
|
2016-07-31 10:18:03 -05:00
|
|
|
|
2016-08-21 07:21:59 -05:00
|
|
|
std::mutex Connection::Mutex;
|
|
|
|
|
2016-09-26 01:54:40 -05:00
|
|
|
//static constexpr auto FIRST_ROW_TILES = "tilecombine part=0 width=256 height=256 tileposx=0,3840,7680 tileposy=0,0,0 tilewidth=3840 tileheight=3840";
|
2016-09-25 10:32:50 -05:00
|
|
|
static constexpr auto FIRST_PAGE_TILES = "tilecombine part=0 width=256 height=256 tileposx=0,3840,7680,11520,0,3840,7680,11520,0,3840,7680,11520,0,3840,7680,11520 tileposy=0,0,0,0,3840,3840,3840,3840,7680,7680,7680,7680,11520,11520,11520,11520 tilewidth=3840 tileheight=3840";
|
|
|
|
static constexpr auto FIRST_PAGE_TILE_COUNT = 16;
|
|
|
|
|
2016-08-13 23:01:13 -05:00
|
|
|
/// Main thread class to replay a trace file.
|
2016-08-04 09:31:11 -05:00
|
|
|
class Worker: public Runnable
|
|
|
|
{
|
|
|
|
public:
|
2016-07-31 10:18:03 -05:00
|
|
|
|
2016-08-21 13:44:24 -05:00
|
|
|
Worker(Stress& app, const std::string& uri) :
|
2016-08-04 09:31:11 -05:00
|
|
|
_app(app),
|
2016-08-21 13:44:24 -05:00
|
|
|
_uri(uri)
|
2016-08-04 09:31:11 -05:00
|
|
|
{
|
|
|
|
}
|
2016-07-31 10:18:03 -05:00
|
|
|
|
2016-08-21 19:18:37 -05:00
|
|
|
std::vector<long> getLatencyStats() const { return _latencyStats; }
|
|
|
|
std::vector<long> getRenderingStats() const { return _renderingStats; }
|
|
|
|
std::vector<long> getCacheStats() const { return _cacheStats; }
|
|
|
|
|
2016-08-04 09:31:11 -05:00
|
|
|
void run() override
|
|
|
|
{
|
2016-07-31 10:18:03 -05:00
|
|
|
try
|
|
|
|
{
|
2016-08-21 13:44:24 -05:00
|
|
|
if (Stress::Benchmark)
|
|
|
|
{
|
|
|
|
benchmark();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
replay();
|
|
|
|
}
|
2016-08-04 11:17:22 -05:00
|
|
|
}
|
|
|
|
catch (const Poco::Exception &e)
|
|
|
|
{
|
2016-09-02 15:35:44 -05:00
|
|
|
std::cout << "Error: " << e.name() << ' '
|
2016-08-04 11:17:22 -05:00
|
|
|
<< e.message() << std::endl;
|
|
|
|
}
|
2016-08-21 07:23:08 -05:00
|
|
|
catch (const std::exception &e)
|
|
|
|
{
|
2016-09-02 15:35:44 -05:00
|
|
|
std::cout << "Error: " << e.what() << std::endl;
|
2016-08-21 07:23:08 -05:00
|
|
|
}
|
2016-08-04 11:17:22 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
2016-08-21 19:18:37 -05:00
|
|
|
bool modifyDoc(const std::shared_ptr<Connection>& con)
|
|
|
|
{
|
2016-09-25 10:32:50 -05:00
|
|
|
const auto startModify = std::chrono::steady_clock::now();
|
|
|
|
|
|
|
|
con->send("key type=input char=97 key=0"); // a
|
|
|
|
//con->send("key type=input char=0 key=1283"); // backspace
|
|
|
|
const bool success = !con->recv("invalidatetiles:").empty();
|
|
|
|
|
|
|
|
const auto now = std::chrono::steady_clock::now();
|
|
|
|
const auto deltaModify = std::chrono::duration_cast<std::chrono::microseconds>(now - startModify).count();
|
|
|
|
_latencyStats.push_back(deltaModify);
|
|
|
|
|
|
|
|
return success;
|
2016-08-21 22:34:02 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
bool renderTile(const std::shared_ptr<Connection>& con)
|
|
|
|
{
|
|
|
|
modifyDoc(con);
|
|
|
|
|
2016-09-25 10:32:50 -05:00
|
|
|
const auto start = std::chrono::steady_clock::now();
|
2016-08-21 22:34:02 -05:00
|
|
|
|
2016-09-25 10:32:50 -05:00
|
|
|
const auto expectedTilesCount = FIRST_PAGE_TILE_COUNT;
|
|
|
|
con->send(FIRST_PAGE_TILES);
|
2016-09-11 13:22:24 -05:00
|
|
|
for (int i = 0; i < expectedTilesCount; ++i)
|
2016-08-21 19:18:37 -05:00
|
|
|
{
|
2016-09-11 13:22:24 -05:00
|
|
|
if (helpers::getTileMessage(*con->getWS(), con->getName()).empty())
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2016-09-25 10:32:50 -05:00
|
|
|
}
|
2016-08-21 19:18:37 -05:00
|
|
|
|
2016-08-21 22:34:02 -05:00
|
|
|
const auto now = std::chrono::steady_clock::now();
|
2016-09-25 10:32:50 -05:00
|
|
|
const auto delta = std::chrono::duration_cast<std::chrono::microseconds>(now - start).count();
|
|
|
|
_renderingStats.push_back(delta / expectedTilesCount);
|
2016-08-21 22:34:02 -05:00
|
|
|
|
2016-08-21 19:18:37 -05:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-08-21 22:34:02 -05:00
|
|
|
bool fetchCachedTile(const std::shared_ptr<Connection>& con)
|
2016-08-21 19:18:37 -05:00
|
|
|
{
|
|
|
|
const auto start = std::chrono::steady_clock::now();
|
|
|
|
|
2016-09-25 10:32:50 -05:00
|
|
|
const auto expectedTilesCount = FIRST_PAGE_TILE_COUNT;
|
|
|
|
con->send(FIRST_PAGE_TILES);
|
2016-09-11 13:22:24 -05:00
|
|
|
for (int i = 0; i < expectedTilesCount; ++i)
|
2016-08-21 19:18:37 -05:00
|
|
|
{
|
2016-09-11 13:22:24 -05:00
|
|
|
if (helpers::getTileMessage(*con->getWS(), con->getName()).empty())
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2016-08-21 19:18:37 -05:00
|
|
|
}
|
|
|
|
|
2016-09-25 10:32:50 -05:00
|
|
|
const auto now = std::chrono::steady_clock::now();
|
|
|
|
const auto delta = std::chrono::duration_cast<std::chrono::microseconds>(now - start).count();
|
|
|
|
_cacheStats.push_back(delta / expectedTilesCount);
|
|
|
|
|
2016-08-21 19:18:37 -05:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-08-21 13:44:24 -05:00
|
|
|
void benchmark()
|
|
|
|
{
|
2016-09-02 16:50:59 -05:00
|
|
|
std::cout << "Running " << Stress::Iterations << " iterations of Benchmark." << std::endl;
|
2016-09-11 13:22:24 -05:00
|
|
|
|
|
|
|
_cacheStats.reserve(Stress::Iterations * 4);
|
|
|
|
_latencyStats.reserve(Stress::Iterations * 4);
|
|
|
|
_renderingStats.reserve(Stress::Iterations * 4);
|
|
|
|
|
2016-08-21 19:18:37 -05:00
|
|
|
static std::atomic<unsigned> SessionId;
|
|
|
|
const auto sessionId = ++SessionId;
|
|
|
|
auto connection = Connection::create(_app._serverURI, _uri, std::to_string(sessionId));
|
2016-08-21 13:44:24 -05:00
|
|
|
|
|
|
|
connection->load();
|
2016-08-21 19:18:37 -05:00
|
|
|
|
2016-09-19 02:21:47 -05:00
|
|
|
for (size_t i = 0; i < Stress::Iterations; ++i)
|
2016-08-21 19:18:37 -05:00
|
|
|
{
|
2016-08-21 22:34:02 -05:00
|
|
|
renderTile(connection);
|
2016-08-21 19:18:37 -05:00
|
|
|
|
2016-08-21 22:34:02 -05:00
|
|
|
fetchCachedTile(connection);
|
|
|
|
}
|
2016-08-21 13:44:24 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void replay()
|
2016-08-04 11:17:22 -05:00
|
|
|
{
|
2016-08-21 13:44:24 -05:00
|
|
|
TraceFileReader traceFile(_uri);
|
|
|
|
|
|
|
|
auto epochFile(traceFile.getEpoch());
|
2016-08-04 11:17:22 -05:00
|
|
|
auto epochCurrent(std::chrono::steady_clock::now());
|
2016-08-21 07:23:08 -05:00
|
|
|
|
2016-08-04 11:17:22 -05:00
|
|
|
for (;;)
|
|
|
|
{
|
2016-08-21 13:44:24 -05:00
|
|
|
const auto rec = traceFile.getNextRecord();
|
2016-08-04 11:17:22 -05:00
|
|
|
if (rec.Dir == TraceFileRecord::Direction::Invalid)
|
2016-08-01 21:21:06 -05:00
|
|
|
{
|
2016-08-04 11:17:22 -05:00
|
|
|
// End of trace file.
|
|
|
|
break;
|
|
|
|
}
|
2016-08-01 21:21:06 -05:00
|
|
|
|
2016-08-04 11:17:22 -05:00
|
|
|
const auto deltaCurrent = std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::steady_clock::now() - epochCurrent).count();
|
|
|
|
const auto deltaFile = rec.TimestampNs - epochFile;
|
2016-08-04 19:17:13 -05:00
|
|
|
const auto delay = (Stress::NoDelay ? 0 : deltaFile - deltaCurrent);
|
2016-08-04 11:17:22 -05:00
|
|
|
if (delay > 0)
|
|
|
|
{
|
2016-08-04 19:17:13 -05:00
|
|
|
if (delay > 1e6)
|
|
|
|
{
|
2016-09-02 15:35:44 -05:00
|
|
|
std::cout << "Sleeping for " << delay / 1000 << " ms.\n";
|
2016-08-04 19:17:13 -05:00
|
|
|
}
|
|
|
|
|
2016-08-04 11:17:22 -05:00
|
|
|
std::this_thread::sleep_for(std::chrono::microseconds(delay));
|
|
|
|
}
|
2016-08-01 21:21:06 -05:00
|
|
|
|
2016-08-04 11:17:22 -05:00
|
|
|
if (rec.Dir == TraceFileRecord::Direction::Event)
|
|
|
|
{
|
|
|
|
// Meta info about about an event.
|
|
|
|
static const std::string NewSession("NewSession: ");
|
|
|
|
static const std::string EndSession("EndSession: ");
|
2016-08-04 09:31:11 -05:00
|
|
|
|
2016-08-04 11:17:22 -05:00
|
|
|
if (rec.Payload.find(NewSession) == 0)
|
|
|
|
{
|
|
|
|
const auto& uri = rec.Payload.substr(NewSession.size());
|
2016-08-18 06:52:40 -05:00
|
|
|
auto it = _sessions.find(uri);
|
|
|
|
if (it != _sessions.end())
|
2016-08-04 09:31:11 -05:00
|
|
|
{
|
2016-08-04 11:17:22 -05:00
|
|
|
// Add a new session.
|
|
|
|
if (it->second.find(rec.SessionId) != it->second.end())
|
2016-08-04 09:31:11 -05:00
|
|
|
{
|
2016-09-02 15:35:44 -05:00
|
|
|
std::cout << "ERROR: session [" << rec.SessionId << "] already exists on doc [" << uri << "]\n";
|
2016-08-04 09:31:11 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-08-04 11:17:22 -05:00
|
|
|
it->second.emplace(rec.SessionId, Connection::create(_app._serverURI, uri, rec.SessionId));
|
2016-08-04 09:31:11 -05:00
|
|
|
}
|
|
|
|
}
|
2016-08-04 11:17:22 -05:00
|
|
|
else
|
2016-08-04 09:31:11 -05:00
|
|
|
{
|
2016-09-02 15:35:44 -05:00
|
|
|
std::cout << "New Document: " << uri << "\n";
|
2016-08-18 06:52:40 -05:00
|
|
|
_childToDoc.emplace(rec.Pid, uri);
|
|
|
|
_sessions[uri].emplace(rec.SessionId, Connection::create(_app._serverURI, uri, rec.SessionId));
|
2016-08-04 09:31:11 -05:00
|
|
|
}
|
|
|
|
}
|
2016-08-04 11:17:22 -05:00
|
|
|
else if (rec.Payload.find(EndSession) == 0)
|
2016-08-04 09:31:11 -05:00
|
|
|
{
|
2016-08-04 11:17:22 -05:00
|
|
|
const auto& uri = rec.Payload.substr(EndSession.size());
|
2016-08-18 06:52:40 -05:00
|
|
|
auto it = _sessions.find(uri);
|
|
|
|
if (it != _sessions.end())
|
2016-08-04 09:31:11 -05:00
|
|
|
{
|
2016-09-02 15:35:44 -05:00
|
|
|
std::cout << "EndSession [" << rec.SessionId << "]: " << uri << "\n";
|
2016-08-04 11:17:22 -05:00
|
|
|
|
|
|
|
it->second.erase(rec.SessionId);
|
|
|
|
if (it->second.empty())
|
2016-08-04 09:31:11 -05:00
|
|
|
{
|
2016-09-02 15:35:44 -05:00
|
|
|
std::cout << "End Doc [" << uri << "].\n";
|
2016-08-18 06:52:40 -05:00
|
|
|
_sessions.erase(it);
|
|
|
|
_childToDoc.erase(rec.Pid);
|
2016-08-04 09:31:11 -05:00
|
|
|
}
|
2016-08-04 11:17:22 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-09-02 15:35:44 -05:00
|
|
|
std::cout << "ERROR: Doc [" << uri << "] does not exist.\n";
|
2016-08-04 11:17:22 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (rec.Dir == TraceFileRecord::Direction::Incoming)
|
|
|
|
{
|
2016-08-18 06:52:40 -05:00
|
|
|
auto docIt = _childToDoc.find(rec.Pid);
|
|
|
|
if (docIt != _childToDoc.end())
|
2016-08-04 11:17:22 -05:00
|
|
|
{
|
|
|
|
const auto& uri = docIt->second;
|
2016-08-18 06:52:40 -05:00
|
|
|
auto it = _sessions.find(uri);
|
|
|
|
if (it != _sessions.end())
|
2016-08-04 11:17:22 -05:00
|
|
|
{
|
|
|
|
const auto sessionIt = it->second.find(rec.SessionId);
|
|
|
|
if (sessionIt != it->second.end())
|
2016-08-04 09:31:11 -05:00
|
|
|
{
|
2016-08-21 07:23:08 -05:00
|
|
|
// Send the command.
|
2016-08-04 11:17:22 -05:00
|
|
|
sessionIt->second->send(rec.Payload);
|
2016-08-04 09:31:11 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-09-02 15:35:44 -05:00
|
|
|
std::cout << "ERROR: Doc [" << uri << "] does not exist.\n";
|
2016-08-04 09:31:11 -05:00
|
|
|
}
|
|
|
|
}
|
2016-08-04 11:17:22 -05:00
|
|
|
else
|
|
|
|
{
|
2016-09-02 15:35:44 -05:00
|
|
|
std::cout << "ERROR: Unknown PID [" << rec.Pid << "] maps to no active document.\n";
|
2016-08-04 11:17:22 -05:00
|
|
|
}
|
2016-08-01 21:21:06 -05:00
|
|
|
}
|
2016-08-04 11:17:22 -05:00
|
|
|
|
|
|
|
epochCurrent = std::chrono::steady_clock::now();
|
|
|
|
epochFile = rec.TimestampNs;
|
2016-07-31 10:18:03 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
Stress& _app;
|
2016-08-21 13:44:24 -05:00
|
|
|
const std::string _uri;
|
2016-08-04 09:31:11 -05:00
|
|
|
|
|
|
|
/// LOK child process PID to Doc URI map.
|
2016-08-18 06:52:40 -05:00
|
|
|
std::map<unsigned, std::string> _childToDoc;
|
2016-08-04 09:31:11 -05:00
|
|
|
|
2016-08-18 06:52:40 -05:00
|
|
|
/// Doc URI to _sessions map. _sessions are maps of SessionID to Connection.
|
2016-08-21 19:18:37 -05:00
|
|
|
std::map<std::string, std::map<std::string, std::shared_ptr<Connection>>> _sessions;
|
|
|
|
|
|
|
|
std::vector<long> _latencyStats;
|
|
|
|
std::vector<long> _renderingStats;
|
|
|
|
std::vector<long> _cacheStats;
|
2016-07-31 10:18:03 -05:00
|
|
|
};
|
|
|
|
|
2016-08-04 19:17:13 -05:00
|
|
|
bool Stress::NoDelay = false;
|
2016-08-21 13:44:24 -05:00
|
|
|
bool Stress::Benchmark = false;
|
2016-09-19 02:21:47 -05:00
|
|
|
size_t Stress::Iterations = 100;
|
2016-08-04 19:17:13 -05:00
|
|
|
|
2016-07-31 10:18:03 -05:00
|
|
|
Stress::Stress() :
|
2016-08-01 20:53:09 -05:00
|
|
|
_numClients(1),
|
2016-07-31 10:18:03 -05:00
|
|
|
#if ENABLE_SSL
|
|
|
|
_serverURI("https://127.0.0.1:" + std::to_string(DEFAULT_CLIENT_PORT_NUMBER))
|
|
|
|
#else
|
|
|
|
_serverURI("http://127.0.0.1:" + std::to_string(DEFAULT_CLIENT_PORT_NUMBER))
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void Stress::defineOptions(OptionSet& optionSet)
|
|
|
|
{
|
|
|
|
Application::defineOptions(optionSet);
|
|
|
|
|
|
|
|
optionSet.addOption(Option("help", "", "Display help information on command line arguments.")
|
|
|
|
.required(false).repeatable(false));
|
2016-08-21 13:44:24 -05:00
|
|
|
optionSet.addOption(Option("bench", "", "Performance benchmark. The argument is a document URL to load.")
|
|
|
|
.required(false).repeatable(false));
|
2016-09-02 16:50:59 -05:00
|
|
|
optionSet.addOption(Option("iter", "", "Number of iterations to use for Benchmarking.")
|
|
|
|
.required(false).repeatable(false)
|
|
|
|
.argument("iter"));
|
2016-08-04 19:17:13 -05:00
|
|
|
optionSet.addOption(Option("nodelay", "", "Replay at full speed disregarding original timing.")
|
|
|
|
.required(false).repeatable(false));
|
2016-07-31 10:18:03 -05:00
|
|
|
optionSet.addOption(Option("clientsperdoc", "", "Number of simultaneous clients on each doc.")
|
|
|
|
.required(false).repeatable(false)
|
|
|
|
.argument("concurrency"));
|
|
|
|
optionSet.addOption(Option("server", "", "URI of LOOL server")
|
|
|
|
.required(false).repeatable(false)
|
|
|
|
.argument("uri"));
|
|
|
|
}
|
|
|
|
|
|
|
|
void Stress::handleOption(const std::string& optionName,
|
|
|
|
const std::string& value)
|
|
|
|
{
|
|
|
|
Application::handleOption(optionName, value);
|
|
|
|
|
|
|
|
if (optionName == "help")
|
|
|
|
{
|
|
|
|
HelpFormatter helpFormatter(options());
|
|
|
|
|
|
|
|
helpFormatter.setCommand(commandName());
|
|
|
|
helpFormatter.setUsage("OPTIONS");
|
|
|
|
helpFormatter.setHeader("LibreOffice On-Line tool.");
|
2016-09-02 15:35:44 -05:00
|
|
|
helpFormatter.format(std::cerr);
|
2016-07-31 10:18:03 -05:00
|
|
|
std::exit(Application::EXIT_OK);
|
|
|
|
}
|
2016-08-21 13:44:24 -05:00
|
|
|
else if (optionName == "bench")
|
|
|
|
Stress::Benchmark = true;
|
2016-09-02 16:50:59 -05:00
|
|
|
else if (optionName == "iter")
|
2016-09-25 10:32:50 -05:00
|
|
|
Stress::Iterations = std::max(std::stoi(value), 1);
|
2016-08-04 19:17:13 -05:00
|
|
|
else if (optionName == "nodelay")
|
|
|
|
Stress::NoDelay = true;
|
2016-07-31 10:18:03 -05:00
|
|
|
else if (optionName == "clientsperdoc")
|
|
|
|
_numClients = std::max(std::stoi(value), 1);
|
|
|
|
else if (optionName == "server")
|
|
|
|
_serverURI = value;
|
|
|
|
else
|
|
|
|
{
|
2016-09-02 15:35:44 -05:00
|
|
|
std::cout << "Unknown option: " << optionName << std::endl;
|
2016-07-31 10:18:03 -05:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int Stress::main(const std::vector<std::string>& args)
|
|
|
|
{
|
|
|
|
std::vector<std::unique_ptr<Thread>> clients(_numClients * args.size());
|
|
|
|
|
2016-08-17 18:52:13 -05:00
|
|
|
if (args.size() == 0)
|
|
|
|
{
|
2016-08-21 13:44:24 -05:00
|
|
|
std::cerr << "Usage: loolstress [--bench] <tracefile | url> " << std::endl;
|
2016-08-17 18:52:13 -05:00
|
|
|
std::cerr << " Trace files may be plain text or gzipped (with .gz extension)." << std::endl;
|
|
|
|
std::cerr << " --help for full arguments list." << std::endl;
|
|
|
|
return Application::EXIT_NOINPUT;
|
|
|
|
}
|
2016-07-31 10:18:03 -05:00
|
|
|
|
2016-08-21 22:34:02 -05:00
|
|
|
std::vector<std::shared_ptr<Worker>> workers;
|
|
|
|
|
2016-07-31 10:18:03 -05:00
|
|
|
unsigned index = 0;
|
2016-12-23 00:03:08 -06:00
|
|
|
for (size_t i = 0; i < args.size(); ++i)
|
2016-07-31 10:18:03 -05:00
|
|
|
{
|
|
|
|
std::cout << "Arg: " << args[i] << std::endl;
|
|
|
|
for (unsigned j = 0; j < _numClients; ++j, ++index)
|
|
|
|
{
|
2016-08-21 22:34:02 -05:00
|
|
|
workers.emplace_back(new Worker(*this, args[i]));
|
2016-07-31 10:18:03 -05:00
|
|
|
clients[index].reset(new Thread());
|
2016-08-21 22:34:02 -05:00
|
|
|
clients[index]->start(*workers[workers.size() - 1]);
|
2016-07-31 10:18:03 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (const auto& client : clients)
|
|
|
|
{
|
|
|
|
client->join();
|
|
|
|
}
|
|
|
|
|
2016-08-21 22:34:02 -05:00
|
|
|
if (Stress::Benchmark)
|
|
|
|
{
|
|
|
|
std::vector<long> latencyStats;
|
|
|
|
std::vector<long> renderingStats;
|
|
|
|
std::vector<long> cachedStats;
|
|
|
|
|
|
|
|
for (const auto& worker : workers)
|
|
|
|
{
|
|
|
|
const auto latencyStat = worker->getLatencyStats();
|
|
|
|
latencyStats.insert(latencyStats.end(), latencyStat.begin(), latencyStat.end());
|
|
|
|
|
|
|
|
const auto renderingStat = worker->getRenderingStats();
|
|
|
|
renderingStats.insert(renderingStats.end(), renderingStat.begin(), renderingStat.end());
|
|
|
|
|
|
|
|
const auto cachedStat = worker->getCacheStats();
|
|
|
|
cachedStats.insert(cachedStats.end(), cachedStat.begin(), cachedStat.end());
|
|
|
|
}
|
|
|
|
|
2016-09-11 13:22:24 -05:00
|
|
|
if (!latencyStats.empty() && !renderingStats.empty() && !cachedStats.empty())
|
|
|
|
{
|
|
|
|
std::cerr << "\nResults:\n";
|
2016-09-25 10:32:50 -05:00
|
|
|
std::cerr << "Iterations: " << Stress::Iterations << "\n";
|
2016-09-11 13:22:24 -05:00
|
|
|
|
|
|
|
std::cerr << "Latency best: " << latencyStats[0] << " microsecs, 95th percentile: " << percentile(latencyStats, 95) << " microsecs." << std::endl;
|
|
|
|
std::cerr << "Tile best: " << renderingStats[0] << " microsecs, rendering 95th percentile: " << percentile(renderingStats, 95) << " microsecs." << std::endl;
|
|
|
|
std::cerr << "Cached best: " << cachedStats[0] << " microsecs, tile 95th percentile: " << percentile(cachedStats, 95) << " microsecs." << std::endl;
|
2016-08-21 22:34:02 -05:00
|
|
|
|
2016-09-11 13:22:24 -05:00
|
|
|
const auto renderingTime = std::accumulate(renderingStats.begin(), renderingStats.end(), 0L);
|
|
|
|
const double renderedPixels = 256 * 256 * renderingStats.size();
|
|
|
|
const auto pixelsPerSecRendered = renderedPixels / renderingTime;
|
|
|
|
std::cerr << "Rendering power: " << pixelsPerSecRendered << " MPixels/sec." << std::endl;
|
2016-08-21 22:34:02 -05:00
|
|
|
|
2016-09-11 13:22:24 -05:00
|
|
|
const auto cacheTime = std::accumulate(cachedStats.begin(), cachedStats.end(), 0L);
|
|
|
|
const double cachePixels = 256 * 256 * cachedStats.size();
|
|
|
|
const auto pixelsPerSecCached = cachePixels / cacheTime;
|
|
|
|
std::cerr << "Cache power: " << pixelsPerSecCached << " MPixels/sec." << std::endl;
|
|
|
|
}
|
2016-08-21 22:34:02 -05:00
|
|
|
}
|
|
|
|
|
2016-07-31 10:18:03 -05:00
|
|
|
return Application::EXIT_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
POCO_APP_MAIN(Stress)
|
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|