diff options
author | Arne H Juul <arnej@yahoo-inc.com> | 2017-05-09 09:27:43 +0200 |
---|---|---|
committer | Arne H Juul <arnej@yahoo-inc.com> | 2017-05-09 09:27:43 +0200 |
commit | dd297ac2a96710fbbc53cd3de896f3b6b89f24df (patch) | |
tree | cd5088909980dfca76945a7baf4e420ec35680a2 /fbench | |
parent | e6bbaaa02004e41c0504e0cdaab8fd3863e74847 (diff) |
let UrlReader own line and content buffers
Diffstat (limited to 'fbench')
-rw-r--r-- | fbench/src/fbench/client.cpp | 52 | ||||
-rw-r--r-- | fbench/src/fbench/client.h | 3 |
2 files changed, 31 insertions, 24 deletions
diff --git a/fbench/src/fbench/client.cpp b/fbench/src/fbench/client.cpp index 3ea3e5719b9..3141b07482d 100644 --- a/fbench/src/fbench/client.cpp +++ b/fbench/src/fbench/client.cpp @@ -16,9 +16,6 @@ Client::Client(ClientArguments *args) _reader(new FileReader()), _output(), _linebufsize(args->_maxLineSize), - _linebuf(new char[_linebufsize]), - _contentbufsize(16 * args->_maxLineSize), - _contentbuf(NULL), _stop(false), _done(false), _thread() @@ -29,8 +26,6 @@ Client::Client(ClientArguments *args) Client::~Client() { - delete [] _contentbuf; - delete [] _linebuf; } void Client::runMe(Client * me) { @@ -42,20 +37,36 @@ class UrlReader { FileReader &_reader; const ClientArguments &_args; int _restarts; - char *_leftOvers; + int _linebufsize; + int _contentbufsize; int _leftOversLen; + char *_linebuf; + char *_contentbuf; + char *_leftOvers; public: UrlReader(FileReader& reader, const ClientArguments &args) : _reader(reader), _args(args), _restarts(0), - _leftOvers(NULL), _leftOversLen(0) - {} - int nextUrl(char *buf, int bufLen); - int getContent(char *buf, int bufLen); + _linebufsize(args._maxLineSize), + _contentbufsize(0), _leftOversLen(0), + _linebuf(new char[_linebufsize]), + _contentbuf(0), _leftOvers(0) + { + if (_args._usePostMode) { + _contentbufsize = 16 * _linebufsize; + _contentbuf = new char[_contentbufsize]; + } + } + int nextUrl(); + int getContent(); + char *url() const { return _linebuf; } + char *contents() const { return _contentbuf; } ~UrlReader() {} }; -int UrlReader::nextUrl(char *buf, int buflen) +int UrlReader::nextUrl() { + char *buf = _linebuf; + int buflen = _linebufsize; if (_leftOvers) { if (_leftOversLen < buflen) { strncpy(buf, _leftOvers, _leftOversLen); @@ -105,8 +116,10 @@ int UrlReader::nextUrl(char *buf, int buflen) return 0; } -int UrlReader::getContent(char *buf, int bufLen) +int UrlReader::getContent() { + char *buf = _contentbuf; + int bufLen = _contentbufsize; int totLen = 0; while (totLen < bufLen) { int len = _reader.ReadLine(buf, bufLen); @@ -136,10 +149,6 @@ Client::run() int linelen; /// int reslen; - if (_args->_usePostMode) { - _contentbuf = new char[_contentbufsize]; - } - std::this_thread::sleep_for(std::chrono::milliseconds(_args->_delay)); // open query file @@ -178,7 +187,7 @@ Client::run() _cycleTimer->Start(); - linelen = urlSource.nextUrl(_linebuf, _linebufsize); + linelen = urlSource.nextUrl(); if (linelen > 0) { ++urlNumber; } else { @@ -190,17 +199,18 @@ Client::run() break; } if (linelen < _linebufsize) { + char *linebuf = urlSource.url(); if (_output) { _output->write("URL: ", strlen("URL: ")); - _output->write(_linebuf, linelen); + _output->write(linebuf, linelen); _output->write("\n\n", 2); } if (linelen + (int)_args->_queryStringToAppend.length() < _linebufsize) { - strcat(_linebuf, _args->_queryStringToAppend.c_str()); + strcat(linebuf, _args->_queryStringToAppend.c_str()); } - int cLen = _args->_usePostMode ? urlSource.getContent(_contentbuf, _contentbufsize) : 0; + int cLen = _args->_usePostMode ? urlSource.getContent() : 0; _reqTimer->Start(); - auto fetch_status = _http->Fetch(_linebuf, _output.get(), _args->_usePostMode, _contentbuf, cLen); + auto fetch_status = _http->Fetch(linebuf, _output.get(), _args->_usePostMode, urlSource.contents(), 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 4b33edb8939..9a3fcfe651a 100644 --- a/fbench/src/fbench/client.h +++ b/fbench/src/fbench/client.h @@ -168,9 +168,6 @@ private: std::unique_ptr<FileReader> _reader; std::unique_ptr<std::ofstream> _output; int _linebufsize; - char *_linebuf; - int _contentbufsize; - char *_contentbuf; std::atomic<bool> _stop; std::atomic<bool> _done; std::thread _thread; |