mirror of https://gitee.com/bigwinds/arangodb
re-enabled benchmark client for single operations
This commit is contained in:
parent
df6008849d
commit
77bc98cd42
|
@ -25,8 +25,8 @@
|
||||||
/// @author Copyright 2012, triAGENS GmbH, Cologne, Germany
|
/// @author Copyright 2012, triAGENS GmbH, Cologne, Germany
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#ifndef TRIAGENS_V8_CLIENT_SHARED_COUNTER_H
|
#ifndef TRIAGENS_V8_CLIENT_BENCHMARK_COUNTER_H
|
||||||
#define TRIAGENS_V8_CLIENT_SHARED_COUNTER_H 1
|
#define TRIAGENS_V8_CLIENT_BENCHMARK_COUNTER_H 1
|
||||||
|
|
||||||
#include "Basics/Common.h"
|
#include "Basics/Common.h"
|
||||||
|
|
||||||
|
@ -39,7 +39,7 @@ namespace triagens {
|
||||||
namespace v8client {
|
namespace v8client {
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
// --SECTION-- class SharedCounter
|
// --SECTION-- class BenchmarkCounter
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
@ -52,15 +52,15 @@ namespace triagens {
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
class SharedCounter {
|
class BenchmarkCounter {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
/// @brief create a shared counter
|
/// @brief create the counter
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
SharedCounter (T initialValue, const T maxValue) :
|
BenchmarkCounter (T initialValue, const T maxValue) :
|
||||||
_mutex(),
|
_mutex(),
|
||||||
_value(initialValue),
|
_value(initialValue),
|
||||||
_maxValue(maxValue),
|
_maxValue(maxValue),
|
||||||
|
@ -68,10 +68,10 @@ namespace triagens {
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
/// @brief destroy a shared counter
|
/// @brief destroy the counter
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
~SharedCounter () {
|
~BenchmarkCounter () {
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -112,16 +112,22 @@ namespace triagens {
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
T next (const T value) {
|
T next (const T value) {
|
||||||
|
T realValue = value;
|
||||||
|
|
||||||
|
if (value == 0) {
|
||||||
|
realValue = 1;
|
||||||
|
}
|
||||||
|
|
||||||
MUTEX_LOCKER(this->_mutex);
|
MUTEX_LOCKER(this->_mutex);
|
||||||
|
|
||||||
T oldValue = _value;
|
T oldValue = _value;
|
||||||
if (oldValue + value > _maxValue) {
|
if (oldValue + realValue > _maxValue) {
|
||||||
_value = _maxValue;
|
_value = _maxValue;
|
||||||
return _maxValue - oldValue;
|
return _maxValue - oldValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
_value += value;
|
_value += realValue;
|
||||||
return value;
|
return realValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
|
@ -0,0 +1,112 @@
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
/// @brief interface definition for benchmark operations
|
||||||
|
///
|
||||||
|
/// @file
|
||||||
|
///
|
||||||
|
/// DISCLAIMER
|
||||||
|
///
|
||||||
|
/// Copyright 2004-2012 triagens GmbH, Cologne, Germany
|
||||||
|
///
|
||||||
|
/// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
/// you may not use this file except in compliance with the License.
|
||||||
|
/// You may obtain a copy of the License at
|
||||||
|
///
|
||||||
|
/// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
///
|
||||||
|
/// Unless required by applicable law or agreed to in writing, software
|
||||||
|
/// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
/// See the License for the specific language governing permissions and
|
||||||
|
/// limitations under the License.
|
||||||
|
///
|
||||||
|
/// Copyright holder is triAGENS GmbH, Cologne, Germany
|
||||||
|
///
|
||||||
|
/// @author Jan Steemann
|
||||||
|
/// @author Copyright 2012, triAGENS GmbH, Cologne, Germany
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#ifndef TRIAGENS_V8_CLIENT_BENCHMARK_OPERATION_H
|
||||||
|
#define TRIAGENS_V8_CLIENT_BENCHMARK_OPERATION_H 1
|
||||||
|
|
||||||
|
#include "Basics/Common.h"
|
||||||
|
#include "SimpleHttpClient/SimpleHttpClient.h"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
using namespace triagens::basics;
|
||||||
|
using namespace triagens::httpclient;
|
||||||
|
using namespace triagens::rest;
|
||||||
|
|
||||||
|
namespace triagens {
|
||||||
|
namespace v8client {
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
// --SECTION-- class BenchmarkOperation
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
/// @addtogroup V8Client
|
||||||
|
/// @{
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
/// @brief simple interface for benchmark operations
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
struct BenchmarkOperation {
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
/// @brief ctor, derived class can implemented something sensible
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
BenchmarkOperation () {
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
/// @brief dtor, derived class can implemented something sensible
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
virtual ~BenchmarkOperation () {
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
/// @brief return the URL of the operation to execute
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
virtual const string& url () = 0;
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
/// @brief return the HTTP method of the operation to execute
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
virtual const SimpleHttpClient::http_method type () = 0;
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
/// @brief return the payload (body) of the HTTP request to execute
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
virtual const char* payload (size_t* length) = 0;
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
/// @brief return the HTTP headers for the oepration to execute
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
virtual const map<string, string>& headers () = 0;
|
||||||
|
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
/// @}
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
// --SECTION-- END-OF-FILE
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Local Variables:
|
||||||
|
// mode: outline-minor
|
||||||
|
// outline-regexp: "^\\(/// @brief\\|/// {@inheritDoc}\\|/// @addtogroup\\|// --SECTION--\\|/// @\\}\\)"
|
||||||
|
// End:
|
|
@ -35,10 +35,11 @@
|
||||||
#include "Basics/ConditionLocker.h"
|
#include "Basics/ConditionLocker.h"
|
||||||
#include "Basics/ConditionVariable.h"
|
#include "Basics/ConditionVariable.h"
|
||||||
#include "Basics/Thread.h"
|
#include "Basics/Thread.h"
|
||||||
#include "V8Client/SharedCounter.h"
|
|
||||||
#include "SimpleHttpClient/SimpleClient.h"
|
#include "SimpleHttpClient/SimpleClient.h"
|
||||||
#include "SimpleHttpClient/SimpleHttpClient.h"
|
#include "SimpleHttpClient/SimpleHttpClient.h"
|
||||||
#include "SimpleHttpClient/GeneralClientConnection.h"
|
#include "SimpleHttpClient/GeneralClientConnection.h"
|
||||||
|
#include "V8Client/BenchmarkCounter.h"
|
||||||
|
#include "V8Client/BenchmarkOperation.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace triagens::basics;
|
using namespace triagens::basics;
|
||||||
|
@ -47,48 +48,7 @@ using namespace triagens::rest;
|
||||||
|
|
||||||
namespace triagens {
|
namespace triagens {
|
||||||
namespace v8client {
|
namespace v8client {
|
||||||
|
|
||||||
struct BenchmarkRequest {
|
|
||||||
BenchmarkRequest (const char* url,
|
|
||||||
map<string, string> params,
|
|
||||||
char* (*genFunc)(),
|
|
||||||
SimpleHttpClient::http_method type) :
|
|
||||||
url(url),
|
|
||||||
params(params),
|
|
||||||
genFunc(genFunc),
|
|
||||||
type(type),
|
|
||||||
ptr(0) {
|
|
||||||
};
|
|
||||||
|
|
||||||
~BenchmarkRequest () {
|
|
||||||
if (ptr) {
|
|
||||||
TRI_Free(TRI_UNKNOWN_MEM_ZONE, ptr);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void createString () {
|
|
||||||
if (genFunc == NULL) {
|
|
||||||
cerr << "invalid call to createString" << endl;
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
ptr = (void*) genFunc();
|
|
||||||
}
|
|
||||||
|
|
||||||
char* getString () {
|
|
||||||
return (char*) ptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t getStringLength () {
|
|
||||||
return strlen((char*) ptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
string url;
|
|
||||||
map<string, string> params;
|
|
||||||
char* (*genFunc)();
|
|
||||||
SimpleHttpClient::http_method type;
|
|
||||||
void* ptr;
|
|
||||||
};
|
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
// --SECTION-- class BenchmarkThread
|
// --SECTION-- class BenchmarkThread
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
@ -99,18 +59,18 @@ namespace triagens {
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
class BenchmarkThread : public Thread {
|
class BenchmarkThread : public Thread {
|
||||||
public:
|
|
||||||
typedef BenchmarkRequest (*GenFunc)();
|
|
||||||
|
|
||||||
BenchmarkThread (GenFunc generate,
|
public:
|
||||||
|
|
||||||
|
BenchmarkThread (BenchmarkOperation* operation,
|
||||||
ConditionVariable* condition,
|
ConditionVariable* condition,
|
||||||
const unsigned long batchSize,
|
const unsigned long batchSize,
|
||||||
SharedCounter<unsigned long>* operationsCounter,
|
BenchmarkCounter<unsigned long>* operationsCounter,
|
||||||
Endpoint* endpoint,
|
Endpoint* endpoint,
|
||||||
const string& username,
|
const string& username,
|
||||||
const string& password)
|
const string& password)
|
||||||
: Thread("arangob"),
|
: Thread("arangob"),
|
||||||
_generate(generate),
|
_operation(operation),
|
||||||
_startCondition(condition),
|
_startCondition(condition),
|
||||||
_batchSize(batchSize),
|
_batchSize(batchSize),
|
||||||
_operationsCounter(operationsCounter),
|
_operationsCounter(operationsCounter),
|
||||||
|
@ -174,7 +134,8 @@ namespace triagens {
|
||||||
}
|
}
|
||||||
|
|
||||||
delete result;
|
delete result;
|
||||||
|
|
||||||
|
// wait for start condition to be broadcasted
|
||||||
{
|
{
|
||||||
ConditionLocker guard(_startCondition);
|
ConditionLocker guard(_startCondition);
|
||||||
guard.wait();
|
guard.wait();
|
||||||
|
@ -187,125 +148,34 @@ namespace triagens {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_batchSize == 1) {
|
if (_batchSize < 1) {
|
||||||
executeRequest();
|
executeSingleRequest();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
executeRequest(numOps);
|
executeBatchRequest(numOps);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void executeRequest (const unsigned long numOperations) {
|
|
||||||
/*
|
|
||||||
PB_ArangoMessage messages;
|
|
||||||
PB_ArangoBatchMessage* batch;
|
|
||||||
PB_ArangoBlobRequest* blob;
|
|
||||||
PB_ArangoKeyValue* kv;
|
|
||||||
|
|
||||||
for (unsigned long i = 0; i < numOperations; ++i) {
|
void executeBatchRequest (const unsigned long numOperations) {
|
||||||
BenchmarkRequest r = _generate();
|
|
||||||
|
|
||||||
batch = messages.add_messages();
|
|
||||||
batch->set_type(PB_BLOB_REQUEST);
|
|
||||||
blob = batch->mutable_blobrequest();
|
|
||||||
|
|
||||||
blob->set_requesttype(getRequestType(r.type));
|
|
||||||
blob->set_url(r.url);
|
|
||||||
|
|
||||||
if (_useJson) {
|
|
||||||
r.createJson(blob);
|
|
||||||
blob->set_contenttype(PB_JSON_CONTENT);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
r.createString(blob);
|
|
||||||
blob->set_contenttype(PB_NO_CONTENT);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (map<string, string>::const_iterator it = r.params.begin(); it != r.params.end(); ++it) {
|
|
||||||
kv = blob->add_values();
|
|
||||||
kv->set_key((*it).first);
|
|
||||||
kv->set_value((*it).second);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t messageSize = messages.ByteSize();
|
|
||||||
char* message = new char[messageSize];
|
|
||||||
|
|
||||||
if (message == 0) {
|
|
||||||
cerr << "out of memory" << endl;
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (! messages.SerializeToArray(message, messageSize)) {
|
|
||||||
cerr << "out of memory" << endl;
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
|
|
||||||
map<string, string> headerFields;
|
|
||||||
headerFields["Content-Type"] = BinaryMessage::getContentType();
|
|
||||||
|
|
||||||
//std::cout << "body length: " << messageSize << ", hash: " << TRI_FnvHashPointer(message, (size_t) messageSize) << "\n";
|
|
||||||
|
|
||||||
Timing timer(Timing::TI_WALLCLOCK);
|
|
||||||
SimpleHttpResult* result = _client->request(SimpleHttpClient::POST, "/_api/batch", message, (size_t) messageSize, headerFields);
|
|
||||||
_time += ((double) timer.time()) / 1000000.0;
|
|
||||||
delete[] message;
|
|
||||||
|
|
||||||
if (result == 0) {
|
|
||||||
_operationsCounter->incFailures();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_endpoint->isBinary()) {
|
|
||||||
PB_ArangoMessage returnMessage;
|
|
||||||
|
|
||||||
if (! returnMessage.ParseFromArray(result->getBody().str().c_str(), result->getContentLength())) {
|
|
||||||
_operationsCounter->incFailures();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
for (int i = 0; i < returnMessage.messages_size(); ++i) {
|
|
||||||
if (returnMessage.messages(i).blobresponse().status() >= 400) {
|
|
||||||
_operationsCounter->incFailures();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if (result->getHttpReturnCode() >= 400) {
|
|
||||||
_operationsCounter->incFailures();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
delete result;
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void executeRequest () {
|
void executeSingleRequest () {
|
||||||
BenchmarkRequest r = _generate();
|
|
||||||
string url = r.url;
|
|
||||||
|
|
||||||
bool found = false;
|
|
||||||
for (map<string, string>::const_iterator i = r.params.begin(); i != r.params.end(); ++i) {
|
|
||||||
if (! found) {
|
|
||||||
url.append("?");
|
|
||||||
found = true;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
url.append("&");
|
|
||||||
}
|
|
||||||
|
|
||||||
url.append((*i).first);
|
|
||||||
url.append("=");
|
|
||||||
url.append((*i).second);
|
|
||||||
}
|
|
||||||
|
|
||||||
r.createString();
|
|
||||||
|
|
||||||
map<string, string> headerFields;
|
|
||||||
Timing timer(Timing::TI_WALLCLOCK);
|
Timing timer(Timing::TI_WALLCLOCK);
|
||||||
|
|
||||||
SimpleHttpResult* result = _client->request(r.type, url, r.getString(), r.getStringLength(), headerFields);
|
const SimpleHttpClient::http_method type = _operation->type();
|
||||||
|
const string url = _operation->url();
|
||||||
|
size_t payloadLength = 0;
|
||||||
|
const char* payload = _operation->payload(&payloadLength);
|
||||||
|
const map<string, string>& headers = _operation->headers();
|
||||||
|
|
||||||
|
SimpleHttpResult* result = _client->request(type,
|
||||||
|
url,
|
||||||
|
payload,
|
||||||
|
payloadLength,
|
||||||
|
headers);
|
||||||
_time += ((double) timer.time()) / 1000000.0;
|
_time += ((double) timer.time()) / 1000000.0;
|
||||||
|
|
||||||
if (result == 0) {
|
if (result == 0) {
|
||||||
|
@ -341,7 +211,11 @@ namespace triagens {
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
GenFunc _generate;
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
/// @brief the operation to benchmark
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
BenchmarkOperation* _operation;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
/// @brief condition variable
|
/// @brief condition variable
|
||||||
|
@ -356,10 +230,10 @@ namespace triagens {
|
||||||
const unsigned long _batchSize;
|
const unsigned long _batchSize;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
/// @brief shared operations counter
|
/// @brief benchmark counter
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
SharedCounter<unsigned long>* _operationsCounter;
|
BenchmarkCounter<unsigned long>* _operationsCounter;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
/// @brief endpoint to use
|
/// @brief endpoint to use
|
||||||
|
|
|
@ -44,8 +44,9 @@
|
||||||
#include "Rest/Initialise.h"
|
#include "Rest/Initialise.h"
|
||||||
#include "SimpleHttpClient/SimpleHttpClient.h"
|
#include "SimpleHttpClient/SimpleHttpClient.h"
|
||||||
#include "SimpleHttpClient/SimpleHttpResult.h"
|
#include "SimpleHttpClient/SimpleHttpResult.h"
|
||||||
|
#include "V8Client/BenchmarkCounter.h"
|
||||||
|
#include "V8Client/BenchmarkOperation.h"
|
||||||
#include "V8Client/BenchmarkThread.h"
|
#include "V8Client/BenchmarkThread.h"
|
||||||
#include "V8Client/SharedCounter.h"
|
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace triagens::basics;
|
using namespace triagens::basics;
|
||||||
|
@ -85,12 +86,43 @@ static int Operations = 1000;
|
||||||
/// @brief number of operations in one batch
|
/// @brief number of operations in one batch
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
static int BatchSize = 1;
|
static int BatchSize = 0;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
/// @}
|
/// @}
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
|
struct VersionTest : public BenchmarkOperation {
|
||||||
|
VersionTest ()
|
||||||
|
: BenchmarkOperation () {
|
||||||
|
}
|
||||||
|
|
||||||
|
~VersionTest () {
|
||||||
|
}
|
||||||
|
|
||||||
|
const string& url () {
|
||||||
|
static string url = "/_api/version";
|
||||||
|
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
|
||||||
|
const SimpleHttpClient::http_method type () {
|
||||||
|
return SimpleHttpClient::GET;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char* payload (size_t* length) {
|
||||||
|
static const char* payload = "";
|
||||||
|
*length = 0;
|
||||||
|
return payload;
|
||||||
|
}
|
||||||
|
|
||||||
|
const map<string, string>& headers () {
|
||||||
|
static const map<string, string> headers;
|
||||||
|
return headers;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
// --SECTION-- private functions
|
// --SECTION-- private functions
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
@ -110,7 +142,7 @@ static void ParseProgramOptions (int argc, char* argv[]) {
|
||||||
description
|
description
|
||||||
("concurrency", &Concurrency, "number of parallel connections")
|
("concurrency", &Concurrency, "number of parallel connections")
|
||||||
("requests", &Operations, "total number of operations")
|
("requests", &Operations, "total number of operations")
|
||||||
("batch-size", &BatchSize, "number of operations in one batch")
|
("batch-size", &BatchSize, "number of operations in one batch (0 disables batching")
|
||||||
;
|
;
|
||||||
|
|
||||||
BaseClient.setupGeneral(description);
|
BaseClient.setupGeneral(description);
|
||||||
|
@ -136,60 +168,6 @@ static void ParseProgramOptions (int argc, char* argv[]) {
|
||||||
/// @{
|
/// @{
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
char* SEmpty () {
|
|
||||||
return TRI_DuplicateStringZ(TRI_UNKNOWN_MEM_ZONE, "");
|
|
||||||
}
|
|
||||||
|
|
||||||
BenchmarkRequest VersionFunc () {
|
|
||||||
map<string, string> params;
|
|
||||||
BenchmarkRequest r("/_api/version", params, &SEmpty, SimpleHttpClient::GET);
|
|
||||||
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
|
|
||||||
char* SFunc1 () {
|
|
||||||
return TRI_DuplicateStringZ(TRI_UNKNOWN_MEM_ZONE, "{\"some value\" : 1}");
|
|
||||||
}
|
|
||||||
|
|
||||||
BenchmarkRequest InsertFunc1 () {
|
|
||||||
map<string, string> params;
|
|
||||||
params["createCollection"] = "true";
|
|
||||||
params["collection"] = "BenchmarkInsert";
|
|
||||||
|
|
||||||
BenchmarkRequest r("/_api/document", params, &SFunc1, SimpleHttpClient::POST);
|
|
||||||
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
|
|
||||||
char* SFunc2 () {
|
|
||||||
StringBuffer s(TRI_UNKNOWN_MEM_ZONE);
|
|
||||||
|
|
||||||
s.appendChar('{');
|
|
||||||
for (size_t i = 0; i < 1; ++i) {
|
|
||||||
s.appendText("\"some value");
|
|
||||||
s.appendInteger(i);
|
|
||||||
s.appendText("\":");
|
|
||||||
s.appendDecimal((double) i);
|
|
||||||
if (i < 0) {
|
|
||||||
s.appendChar(',');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
s.appendChar('}');
|
|
||||||
|
|
||||||
return TRI_DuplicateStringZ(TRI_UNKNOWN_MEM_ZONE, s.c_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
BenchmarkRequest InsertFunc2 () {
|
|
||||||
map<string, string> params;
|
|
||||||
params["createCollection"] = "true";
|
|
||||||
params["collection"] = "BenchmarkInsert";
|
|
||||||
|
|
||||||
BenchmarkRequest r("/_api/document", params, &SFunc2, SimpleHttpClient::POST);
|
|
||||||
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
/// @brief main
|
/// @brief main
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -220,16 +198,20 @@ int main (int argc, char* argv[]) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
SharedCounter<unsigned long> operationsCounter(0, (unsigned long) Operations);
|
BenchmarkCounter<unsigned long> operationsCounter(0, (unsigned long) Operations);
|
||||||
ConditionVariable startCondition;
|
ConditionVariable startCondition;
|
||||||
|
|
||||||
|
VersionTest benchmarkOperation;
|
||||||
|
|
||||||
vector<Endpoint*> endpoints;
|
vector<Endpoint*> endpoints;
|
||||||
vector<BenchmarkThread*> threads;
|
vector<BenchmarkThread*> threads;
|
||||||
|
|
||||||
|
// start client threads
|
||||||
for (int i = 0; i < Concurrency; ++i) {
|
for (int i = 0; i < Concurrency; ++i) {
|
||||||
Endpoint* endpoint = Endpoint::clientFactory(BaseClient.endpointString());
|
Endpoint* endpoint = Endpoint::clientFactory(BaseClient.endpointString());
|
||||||
endpoints.push_back(endpoint);
|
endpoints.push_back(endpoint);
|
||||||
|
|
||||||
BenchmarkThread* thread = new BenchmarkThread(&InsertFunc2,
|
BenchmarkThread* thread = new BenchmarkThread(&benchmarkOperation,
|
||||||
&startCondition,
|
&startCondition,
|
||||||
(unsigned long) BatchSize,
|
(unsigned long) BatchSize,
|
||||||
&operationsCounter,
|
&operationsCounter,
|
||||||
|
@ -240,12 +222,14 @@ int main (int argc, char* argv[]) {
|
||||||
threads.push_back(thread);
|
threads.push_back(thread);
|
||||||
thread->start();
|
thread->start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// give all threads a chance to start so they will not miss the broadcast
|
||||||
usleep(500000);
|
usleep(500000);
|
||||||
|
|
||||||
|
|
||||||
Timing timer(Timing::TI_WALLCLOCK);
|
Timing timer(Timing::TI_WALLCLOCK);
|
||||||
|
|
||||||
|
// broadcast the start signal to all threads
|
||||||
{
|
{
|
||||||
ConditionLocker guard(&startCondition);
|
ConditionLocker guard(&startCondition);
|
||||||
guard.broadcast();
|
guard.broadcast();
|
||||||
|
@ -269,8 +253,8 @@ int main (int argc, char* argv[]) {
|
||||||
}
|
}
|
||||||
|
|
||||||
cout << "Total number of operations: " << Operations << ", batch size: " << BatchSize << ", concurrency level: " << Concurrency << endl;
|
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 << "Total duration: " << fixed << time << " s" << endl;
|
||||||
cout << "Total request duration: " << fixed << requestTime << " s" << endl;
|
|
||||||
cout << "Duration per operation: " << fixed << (time / Operations) << " 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 << "Duration per operation per thread: " << fixed << (time / (double) Operations * (double) Concurrency) << " s" << endl << endl;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue