summaryrefslogtreecommitdiffstats
path: root/fbench
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2021-06-21 09:21:32 +0000
committerHenning Baldersheim <balder@yahoo-inc.com>2021-06-21 09:21:32 +0000
commit31dcb4cf3448b7384f70b6ddaa82c42842fa35bd (patch)
tree62706692af7fb46827e83d737d19552408cbf9a0 /fbench
parent1fd7aa975463ffc97e13dbfc7a862703b623c356 (diff)
Compute percentage of zero hit queries.
Diffstat (limited to 'fbench')
-rw-r--r--fbench/src/fbench/client.cpp42
-rw-r--r--fbench/src/fbench/client.h25
-rw-r--r--fbench/src/fbench/fbench.cpp50
-rw-r--r--fbench/src/fbench/fbench.h50
4 files changed, 81 insertions, 86 deletions
diff --git a/fbench/src/fbench/client.cpp b/fbench/src/fbench/client.cpp
index c1b444e9a6b..040d9c69a9b 100644
--- a/fbench/src/fbench/client.cpp
+++ b/fbench/src/fbench/client.cpp
@@ -5,38 +5,32 @@
#include <util/clientstatus.h>
#include <httpclient/httpclient.h>
#include <util/filereader.h>
-#include <cassert>
#include <cstring>
#include <iostream>
#include <vespa/vespalib/encoding/base64.h>
using namespace vespalib;
-Client::Client(vespalib::CryptoEngine::SP engine, ClientArguments *args)
- : _args(args),
- _status(new ClientStatus()),
- _reqTimer(new Timer()),
- _cycleTimer(new Timer()),
- _masterTimer(new Timer()),
- _http(new HTTPClient(std::move(engine), _args->_hostname, _args->_port,
- _args->_keepAlive, _args->_headerBenchmarkdataCoverage,
- _args->_extraHeaders, _args->_authority)),
- _reader(new FileReader()),
+Client::Client(vespalib::CryptoEngine::SP engine, std::unique_ptr<ClientArguments> args)
+ : _args(std::move(args)),
+ _status(std::make_unique<ClientStatus>()),
+ _reqTimer(std::make_unique<Timer>()),
+ _cycleTimer(std::make_unique<Timer>()),
+ _masterTimer(std::make_unique<Timer>()),
+ _http(std::make_unique<HTTPClient>(std::move(engine), _args->_hostname, _args->_port, _args->_keepAlive,
+ _args->_headerBenchmarkdataCoverage, _args->_extraHeaders, _args->_authority)),
+ _reader(std::make_unique<FileReader>()),
_output(),
_linebufsize(args->_maxLineSize),
- _linebuf(new char[_linebufsize]),
+ _linebuf(std::make_unique<char[]>(_linebufsize)),
_stop(false),
_done(false),
_thread()
{
- assert(args != NULL);
_cycleTimer->SetMax(_args->_cycle);
}
-Client::~Client()
-{
- delete [] _linebuf;
-}
+Client::~Client() = default;
void Client::runMe(Client * me) {
me->run();
@@ -173,15 +167,15 @@ Client::run()
std::this_thread::sleep_for(std::chrono::milliseconds(_args->_delay));
// open query file
- snprintf(inputFilename, 1024, _args->_filenamePattern, _args->_myNum);
+ snprintf(inputFilename, 1024, _args->_filenamePattern.c_str(), _args->_myNum);
if (!_reader->Open(inputFilename)) {
printf("Client %d: ERROR: could not open file '%s' [read mode]\n",
_args->_myNum, inputFilename);
_status->SetError("Could not open query file.");
return;
}
- if (_args->_outputPattern != NULL) {
- snprintf(outputFilename, 1024, _args->_outputPattern, _args->_myNum);
+ if ( ! _args->_outputPattern.empty()) {
+ snprintf(outputFilename, 1024, _args->_outputPattern.c_str(), _args->_myNum);
_output = std::make_unique<std::ofstream>(outputFilename, std::ofstream::out | std::ofstream::binary);
if (_output->fail()) {
printf("Client %d: ERROR: could not open file '%s' [write mode]\n",
@@ -208,7 +202,7 @@ Client::run()
_cycleTimer->Start();
- linelen = urlSource.nextUrl(_linebuf, _linebufsize);
+ linelen = urlSource.nextUrl(_linebuf.get(), _linebufsize);
if (linelen > 0) {
++urlNumber;
} else {
@@ -222,11 +216,11 @@ Client::run()
if (linelen < _linebufsize) {
if (_output) {
_output->write("URL: ", strlen("URL: "));
- _output->write(_linebuf, linelen);
+ _output->write(_linebuf.get(), linelen);
_output->write("\n\n", 2);
}
if (linelen + (int)_args->_queryStringToAppend.length() < _linebufsize) {
- strcat(_linebuf, _args->_queryStringToAppend.c_str());
+ strcat(_linebuf.get(), _args->_queryStringToAppend.c_str());
}
int cLen = _args->_usePostMode ? urlSource.nextContent() : 0;
@@ -239,7 +233,7 @@ Client::run()
}
_reqTimer->Start();
- auto fetch_status = _http->Fetch(_linebuf, _output.get(), _args->_usePostMode, content, cLen);
+ auto fetch_status = _http->Fetch(_linebuf.get(), _output.get(), _args->_usePostMode, content, cLen);
_reqTimer->Stop();
_status->AddRequestStatus(fetch_status.RequestStatus());
if (fetch_status.Ok() && fetch_status.TotalHitCount() == 0)
diff --git a/fbench/src/fbench/client.h b/fbench/src/fbench/client.h
index 70d83f71971..3349a112fa2 100644
--- a/fbench/src/fbench/client.h
+++ b/fbench/src/fbench/client.h
@@ -21,23 +21,17 @@ struct ClientArguments
int _myNum;
/**
- * The total number of clients controlled by the parent fbench
- * application
- **/
- int _totNum;
-
- /**
* Pattern that combined with the client number will become the name
* of the file containing the urls this client should request.
**/
- const char *_filenamePattern;
+ std::string _filenamePattern;
/**
* Pattern that combined with the client number will become the name
* of the file this client should dump url content to. If this
* pattern is set to NULL no output file is generated.
**/
- const char *_outputPattern;
+ std::string _outputPattern;
/**
* The server the client should fetch urls from.
@@ -116,9 +110,9 @@ struct ClientArguments
std::string _extraHeaders;
std::string _authority;
- ClientArguments(int myNum, int totNum,
- const char *filenamePattern,
- const char *outputPattern,
+ ClientArguments(int myNum,
+ const std::string & filenamePattern,
+ const std::string & outputPattern,
const char *hostname, int port,
long cycle, long delay,
int ignoreCount, int byteLimit,
@@ -129,7 +123,6 @@ struct ClientArguments
const std::string & queryStringToAppend, const std::string & extraHeaders,
const std::string &authority, bool postMode)
: _myNum(myNum),
- _totNum(totNum),
_filenamePattern(filenamePattern),
_outputPattern(outputPattern),
_hostname(hostname),
@@ -181,13 +174,11 @@ private:
std::unique_ptr<FileReader> _reader;
std::unique_ptr<std::ofstream> _output;
int _linebufsize;
- char *_linebuf;
+ std::unique_ptr<char[]> _linebuf;
std::atomic<bool> _stop;
std::atomic<bool> _done;
std::thread _thread;
- Client(const Client &);
- Client &operator=(const Client &);
static void runMe(Client * client);
void run();
@@ -197,7 +188,9 @@ public:
* The client arguments given to this method becomes the
* responsibility of the client.
**/
- Client(vespalib::CryptoEngine::SP engine, ClientArguments *args);
+ Client(vespalib::CryptoEngine::SP engine, std::unique_ptr<ClientArguments> args);
+ Client(const Client &) = delete;
+ Client &operator=(const Client &) = delete;
/**
* Delete objects owned by this client, including the client arguments.
diff --git a/fbench/src/fbench/fbench.cpp b/fbench/src/fbench/fbench.cpp
index 57efb8a47e0..1ba49e9897a 100644
--- a/fbench/src/fbench/fbench.cpp
+++ b/fbench/src/fbench/fbench.cpp
@@ -1,4 +1,8 @@
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+
+#include "fbench.h"
+#include "client.h"
+
#include <util/timer.h>
#include <httpclient/httpclient.h>
#include <util/filereader.h>
@@ -9,8 +13,6 @@
#include <vespa/vespalib/net/tls/tls_crypto_engine.h>
#include <vespa/vespalib/io/mapped_file_input.h>
#include <vespa/vespalib/util/size_literals.h>
-#include "client.h"
-#include "fbench.h"
#include <cstring>
#include <cmath>
#include <csignal>
@@ -19,7 +21,8 @@
namespace {
-std::string maybe_load(const std::string &file_name, bool &failed) {
+std::string
+maybe_load(const std::string &file_name, bool &failed) {
std::string content;
if (!file_name.empty()) {
vespalib::MappedFileInput file(file_name);
@@ -42,8 +45,8 @@ FBench::FBench()
_clients(),
_ignoreCount(0),
_cycle(0),
- _filenamePattern(NULL),
- _outputPattern(NULL),
+ _filenamePattern(),
+ _outputPattern(),
_byteLimit(0),
_restartLimit(0),
_maxLineSize(0),
@@ -58,8 +61,6 @@ FBench::FBench()
FBench::~FBench()
{
_clients.clear();
- free(_filenamePattern);
- free(_outputPattern);
}
bool
@@ -121,11 +122,13 @@ FBench::InitBenchmark(int numClients, int ignoreCount, int cycle,
_ignoreCount = ignoreCount;
_cycle = cycle;
- free(_filenamePattern);
- _filenamePattern = strdup(filenamePattern);
- free(_outputPattern);
- _outputPattern = (outputPattern == NULL) ?
- NULL : strdup(outputPattern);
+ _filenamePattern = filenamePattern;
+ if (outputPattern != nullptr) {
+ _outputPattern = outputPattern;
+ } else {
+ _outputPattern.clear();
+ }
+
_queryStringToAppend = queryStringToAppend;
_extraHeaders = extraHeaders;
_authority = authority;
@@ -154,15 +157,12 @@ FBench::CreateClients()
off_end = _queryfileOffset[i+1];
}
client = std::make_unique<Client>(_crypto_engine,
- new ClientArguments(i, _clients.size(), _filenamePattern,
- _outputPattern, _hostnames[i % _hostnames.size()].c_str(),
- _ports[i % _ports.size()], _cycle,
- random() % spread, _ignoreCount,
- _byteLimit, _restartLimit, _maxLineSize,
- _keepAlive, _base64Decode,
- _headerBenchmarkdataCoverage,
- off_beg, off_end,
- _singleQueryFile, _queryStringToAppend, _extraHeaders, _authority, _usePostMode));
+ std::make_unique<ClientArguments>(i, _filenamePattern, _outputPattern,
+ _hostnames[i % _hostnames.size()].c_str(),
+ _ports[i % _ports.size()], _cycle,random() % spread,
+ _ignoreCount, _byteLimit, _restartLimit, _maxLineSize, _keepAlive,
+ _base64Decode, _headerBenchmarkdataCoverage, off_beg, off_end,
+ _singleQueryFile, _queryStringToAppend, _extraHeaders, _authority, _usePostMode));
++i;
}
}
@@ -278,6 +278,8 @@ FBench::PrintSummary()
printf("utilization: %8.2f %%\n",
(maxRate > 0) ? 100 * (actualRate / maxRate) : 0);
printf("zero hit queries: %8ld\n", status._zeroHitQueries);
+ printf("zero hit percentage: %8.2f %%\n",
+ (status._requestCnt > 0) ? 100.0*(double(status._zeroHitQueries)/status._requestCnt) : 0.0);
printf("http request status breakdown:\n");
for (const auto& entry : status._requestStatusDistribution)
printf(" %8u : %8u \n", entry.first, entry.second);
@@ -345,7 +347,7 @@ FBench::Main(int argc, char *argv[])
const int minLineSize = 1024;
const char *queryFilePattern = "query%03d.txt";
- const char *outputFilePattern = NULL;
+ const char *outputFilePattern = nullptr;
std::string queryStringToAppend;
std::string extraHeaders;
std::string ca_certs_file_name; // -T
@@ -599,8 +601,8 @@ main(int argc, char** argv)
sigemptyset(&act.sa_mask);
act.sa_flags = 0;
- sigaction(SIGINT, &act, NULL);
- sigaction(SIGPIPE, &act, NULL);
+ sigaction(SIGINT, &act, nullptr);
+ sigaction(SIGPIPE, &act, nullptr);
FBench myApp;
return myApp.Main(argc, argv);
diff --git a/fbench/src/fbench/fbench.h b/fbench/src/fbench/fbench.h
index 362a463a4f1..e66fc28683d 100644
--- a/fbench/src/fbench/fbench.h
+++ b/fbench/src/fbench/fbench.h
@@ -1,6 +1,14 @@
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#pragma once
+#include <vector>
+#include <string>
+#include <memory>
+
+class Client;
+
+namespace vespalib { class CryptoEngine; }
+
/**
* This is the application class of the fbench program. It controls
* the operation of the test clients and collects overall results.
@@ -10,29 +18,27 @@
class FBench
{
private:
- vespalib::CryptoEngine::SP _crypto_engine;
- std::vector<Client::UP> _clients;
- int _numClients;
- int _ignoreCount;
- int _cycle;
+ std::shared_ptr<vespalib::CryptoEngine> _crypto_engine;
+ std::vector<std::unique_ptr<Client>> _clients;
+ int _ignoreCount;
+ int _cycle;
std::vector<std::string> _hostnames;
- std::vector<int> _ports;
- char *_filenamePattern;
- char *_outputPattern;
- int _byteLimit;
- int _restartLimit;
- int _maxLineSize;
- bool _keepAlive;
- bool _base64Decode;
- bool _usePostMode;
- bool _headerBenchmarkdataCoverage;
- int _seconds;
- std::vector<uint64_t> _queryfileOffset;
- int _numberOfQueries;
- bool _singleQueryFile;
- std::string _queryStringToAppend;
- std::string _extraHeaders;
- std::string _authority;
+ std::vector<int> _ports;
+ std::string _filenamePattern;
+ std::string _outputPattern;
+ int _byteLimit;
+ int _restartLimit;
+ int _maxLineSize;
+ bool _keepAlive;
+ bool _base64Decode;
+ bool _usePostMode;
+ bool _headerBenchmarkdataCoverage;
+ int _seconds;
+ std::vector<uint64_t> _queryfileOffset;
+ bool _singleQueryFile;
+ std::string _queryStringToAppend;
+ std::string _extraHeaders;
+ std::string _authority;
bool init_crypto_engine(const std::string &ca_certs_file_name,
const std::string &cert_chain_file_name,