From d92f359bdab0020f3e0042a282820ab384236469 Mon Sep 17 00:00:00 2001 From: Jan Steemann Date: Tue, 25 Sep 2012 12:55:10 +0200 Subject: [PATCH] more test cases --- arangosh/V8Client/BenchmarkOperation.h | 2 +- arangosh/V8Client/BenchmarkThread.h | 26 +++++++- arangosh/V8Client/arangob.cpp | 87 +++++++++++++++++++++++--- 3 files changed, 103 insertions(+), 12 deletions(-) diff --git a/arangosh/V8Client/BenchmarkOperation.h b/arangosh/V8Client/BenchmarkOperation.h index e570bfec33..727bf2c8cf 100644 --- a/arangosh/V8Client/BenchmarkOperation.h +++ b/arangosh/V8Client/BenchmarkOperation.h @@ -84,7 +84,7 @@ namespace triagens { /// @brief return the payload (body) of the HTTP request to execute //////////////////////////////////////////////////////////////////////////////// - virtual const char* payload (size_t* length) = 0; + virtual const char* payload (size_t*, const size_t) = 0; //////////////////////////////////////////////////////////////////////////////// /// @brief return the HTTP headers for the oepration to execute diff --git a/arangosh/V8Client/BenchmarkThread.h b/arangosh/V8Client/BenchmarkThread.h index 3e139b82f5..8fe5326d36 100644 --- a/arangosh/V8Client/BenchmarkThread.h +++ b/arangosh/V8Client/BenchmarkThread.h @@ -87,6 +87,8 @@ namespace triagens { _password(password), _client(0), _connection(0), + _offset(0), + _counter(0), _time(0.0) { } @@ -207,7 +209,7 @@ namespace triagens { const HttpRequest::HttpRequestType type = _operation->type(); const string url = _operation->url(); size_t payloadLength = 0; - const char* payload = _operation->payload(&payloadLength); + const char* payload = _operation->payload(&payloadLength, _offset + _counter++); const map& headers = _operation->headers(); // headline, e.g. POST /... HTTP/1.1 @@ -258,7 +260,7 @@ namespace triagens { const HttpRequest::HttpRequestType type = _operation->type(); const string url = _operation->url(); size_t payloadLength = 0; - const char* payload = _operation->payload(&payloadLength); + const char* payload = _operation->payload(&payloadLength, _offset + _counter++); const map& headers = _operation->headers(); Timing timer(Timing::TI_WALLCLOCK); @@ -295,6 +297,14 @@ namespace triagens { public: +//////////////////////////////////////////////////////////////////////////////// +/// @brief set the threads offset value +//////////////////////////////////////////////////////////////////////////////// + + void setOffset (size_t offset) { + _offset = offset; + } + //////////////////////////////////////////////////////////////////////////////// /// @brief return the total time accumulated by the thread //////////////////////////////////////////////////////////////////////////////// @@ -372,6 +382,18 @@ namespace triagens { triagens::httpclient::GeneralClientConnection* _connection; +//////////////////////////////////////////////////////////////////////////////// +/// @brief thread offset value +//////////////////////////////////////////////////////////////////////////////// + + size_t _offset; + +//////////////////////////////////////////////////////////////////////////////// +/// @brief thread counter value +//////////////////////////////////////////////////////////////////////////////// + + size_t _counter; + //////////////////////////////////////////////////////////////////////////////// /// @brief time //////////////////////////////////////////////////////////////////////////////// diff --git a/arangosh/V8Client/arangob.cpp b/arangosh/V8Client/arangob.cpp index c10b028e25..6f22971ce3 100644 --- a/arangosh/V8Client/arangob.cpp +++ b/arangosh/V8Client/arangob.cpp @@ -37,6 +37,7 @@ #include "BasicsC/init.h" #include "BasicsC/logging.h" #include "BasicsC/strings.h" +#include "BasicsC/string-buffer.h" #include "BasicsC/terminal-utils.h" #include "Logger/Logger.h" #include "Rest/Endpoint.h" @@ -86,7 +87,7 @@ struct VersionTest : public BenchmarkOperation { return HttpRequest::HTTP_REQUEST_GET; } - const char* payload (size_t* length) { + const char* payload (size_t* length, const size_t counter) { static const char* payload = ""; *length = 0; return payload; @@ -103,7 +104,7 @@ struct VersionTest : public BenchmarkOperation { //////////////////////////////////////////////////////////////////////////////// // ----------------------------------------------------------------------------- -// --SECTION-- document creation test +// --SECTION-- small document creation test // ----------------------------------------------------------------------------- //////////////////////////////////////////////////////////////////////////////// @@ -129,7 +130,7 @@ struct SmallDocumentCreationTest : public BenchmarkOperation { return HttpRequest::HTTP_REQUEST_POST; } - const char* payload (size_t* length) { + const char* payload (size_t* length, const size_t counter) { static const char* payload = "{\"test\":1}"; *length = 10; return payload; @@ -141,6 +142,68 @@ struct SmallDocumentCreationTest : public BenchmarkOperation { } }; +// ----------------------------------------------------------------------------- +// --SECTION-- big document creation test +// ----------------------------------------------------------------------------- + +//////////////////////////////////////////////////////////////////////////////// +/// @addtogroup V8Shell +/// @{ +//////////////////////////////////////////////////////////////////////////////// + +struct BigDocumentCreationTest : public BenchmarkOperation { + BigDocumentCreationTest () + : BenchmarkOperation () { + + const size_t n = 100; + + _buffer = TRI_CreateStringBuffer(TRI_UNKNOWN_MEM_ZONE); + TRI_AppendCharStringBuffer(_buffer, '{'); + + for (size_t i = 1; i <= n; ++i) { + TRI_AppendStringStringBuffer(_buffer, "\"test"); + TRI_AppendUInt32StringBuffer(_buffer, (uint32_t) i); + TRI_AppendStringStringBuffer(_buffer, "\":\"some test value\""); + if (i != n) { + TRI_AppendCharStringBuffer(_buffer, ','); + } + } + + TRI_AppendCharStringBuffer(_buffer, '}'); + + _length = TRI_LengthStringBuffer(_buffer); + } + + ~BigDocumentCreationTest () { + TRI_Free(TRI_UNKNOWN_MEM_ZONE, _buffer); + } + + const string& url () { + static string url = "/_api/document?collection=ArangoBenchmark&createCollection=true"; + + return url; + } + + const HttpRequest::HttpRequestType type () { + return HttpRequest::HTTP_REQUEST_POST; + } + + const char* payload (size_t* length, const size_t counter) { + *length = _length; + return (const char*) _buffer->_buffer; + } + + const map& headers () { + static const map headers; + return headers; + } + + + TRI_string_buffer_t* _buffer; + + size_t _length; +}; + //////////////////////////////////////////////////////////////////////////////// /// @} //////////////////////////////////////////////////////////////////////////////// @@ -261,7 +324,7 @@ int main (int argc, char* argv[]) { BenchmarkCounter operationsCounter(0, (unsigned long) Operations); ConditionVariable startCondition; - SmallDocumentCreationTest benchmarkOperation; + BigDocumentCreationTest benchmarkOperation; vector endpoints; vector threads; @@ -280,6 +343,7 @@ int main (int argc, char* argv[]) { BaseClient.password()); threads.push_back(thread); + thread->setOffset(i * (Operations / Concurrency)); thread->start(); } @@ -312,11 +376,16 @@ int main (int argc, char* argv[]) { requestTime += threads[i]->getTime(); } - cout << "Total number of operations: " << Operations << ", batch size: " << BatchSize << ", concurrency level: " << Concurrency << endl; - cout << "Request/response duration: " << fixed << requestTime << " s" << endl; - cout << "Total duration: " << fixed << time << " s" << endl; - cout << "Duration per operation: " << fixed << (time / Operations) << " s" << endl; - cout << "Duration per operation per thread: " << fixed << (time / (double) Operations * (double) Concurrency) << " s" << endl << endl; + cout << endl; + + cout << "Total number of operations: " << Operations << ", batch size: " << BatchSize << ", concurrency level (threads): " << Concurrency << endl; + cout << "Total request/response duration (sum of all threads): " << fixed << requestTime << " s" << endl; + cout << "Request/response duration (per thread): " << fixed << (requestTime / (double) Concurrency) << " s" << endl; + cout << "Time needed per operation: " << fixed << (time / Operations) << " s" << endl; + cout << "Time needed per operation per thread: " << fixed << (time / (double) Operations * (double) Concurrency) << " s" << endl; + cout << "Elapsed time since start: " << fixed << time << " s" << endl; + + cout << endl; if (operationsCounter.failures() > 0) { cout << "WARNING: " << operationsCounter.failures() << " request(s) failed!!" << endl << endl;