1
0
Fork 0

added collection dropping & creation

This commit is contained in:
Jan Steemann 2012-09-28 15:11:14 +02:00
parent 134449d872
commit aad951e2ab
3 changed files with 126 additions and 4 deletions

View File

@ -68,6 +68,18 @@ namespace triagens {
virtual ~BenchmarkOperation () {
}
////////////////////////////////////////////////////////////////////////////////
/// @brief the name of the underlying collection
////////////////////////////////////////////////////////////////////////////////
virtual string collectionName () = 0;
////////////////////////////////////////////////////////////////////////////////
/// @brief whether or not the test uses a collection
////////////////////////////////////////////////////////////////////////////////
virtual const bool useCollection () const = 0;
////////////////////////////////////////////////////////////////////////////////
/// @brief return the URL of the operation to execute
////////////////////////////////////////////////////////////////////////////////

View File

@ -72,7 +72,9 @@ namespace triagens {
////////////////////////////////////////////////////////////////////////////////
BenchmarkThread (BenchmarkOperation* operation,
ConditionVariable* condition,
ConditionVariable* condition,
void (*callback) (),
int threadNumber,
const unsigned long batchSize,
BenchmarkCounter<unsigned long>* operationsCounter,
Endpoint* endpoint,
@ -81,6 +83,8 @@ namespace triagens {
: Thread("arangob"),
_operation(operation),
_startCondition(condition),
_callback(callback),
_threadNumber(threadNumber),
_batchSize(batchSize),
_operationsCounter(operationsCounter),
_endpoint(endpoint),
@ -139,6 +143,8 @@ namespace triagens {
_client = new SimpleHttpClient(_connection, 10.0, true);
_client->setUserNamePassword("/", _username, _password);
// test the connection
map<string, string> headerFields;
SimpleHttpResult* result = _client->request(HttpRequest::HTTP_REQUEST_GET,
"/_api/version",
@ -155,6 +161,42 @@ namespace triagens {
}
delete result;
// if we're the first thread, wipe the existing collection
if (_threadNumber == 0 && _operation->useCollection()) {
result = _client->request(HttpRequest::HTTP_REQUEST_DELETE,
"/_api/collection/" + _operation->collectionName(),
"",
0,
headerFields);
if (result == 0 || (result->getHttpReturnCode() != 200 && result->getHttpReturnCode() != 404)) {
cerr << "could not wipe existing collection " << _operation->collectionName() << endl;
exit(EXIT_FAILURE);
}
else {
delete result;
}
// now create the collection
string payload = "{\"name\":\"" + _operation->collectionName() + "\"}";
result = _client->request(HttpRequest::HTTP_REQUEST_POST,
"/_api/collection",
payload.c_str(),
payload.size(),
headerFields);
if (result == 0 || (result->getHttpReturnCode() != 200 && result->getHttpReturnCode() != 201)) {
cerr << "could not create collection " << _operation->collectionName() << endl;
exit(EXIT_FAILURE);
}
else {
delete result;
}
}
_callback();
// wait for start condition to be broadcasted
{
@ -353,6 +395,18 @@ namespace triagens {
ConditionVariable* _startCondition;
////////////////////////////////////////////////////////////////////////////////
/// @brief start callback function
////////////////////////////////////////////////////////////////////////////////
void (*_callback) ();
////////////////////////////////////////////////////////////////////////////////
/// @brief our thread number
////////////////////////////////////////////////////////////////////////////////
int _threadNumber;
////////////////////////////////////////////////////////////////////////////////
/// @brief batch size
////////////////////////////////////////////////////////////////////////////////

View File

@ -31,6 +31,8 @@
#include "build.h"
#include "ArangoShell/ArangoClient.h"
#include "Basics/Mutex.h"
#include "Basics/MutexLocker.h"
#include "Basics/ProgramOptions.h"
#include "Basics/ProgramOptionsDescription.h"
#include "Basics/StringUtils.h"
@ -71,6 +73,18 @@ using namespace triagens::arangob;
ArangoClient BaseClient;
////////////////////////////////////////////////////////////////////////////////
/// @brief started counter
////////////////////////////////////////////////////////////////////////////////
static volatile int Started = 0;
////////////////////////////////////////////////////////////////////////////////
/// @brief mutex for start counter
////////////////////////////////////////////////////////////////////////////////
Mutex StartMutex;
////////////////////////////////////////////////////////////////////////////////
/// @brief concurrency
////////////////////////////////////////////////////////////////////////////////
@ -126,6 +140,14 @@ struct VersionTest : public BenchmarkOperation {
~VersionTest () {
}
string collectionName () {
return "";
}
const bool useCollection () const {
return false;
}
const string& url () {
static string url = "/_api/version";
@ -170,6 +192,14 @@ struct SmallDocumentCreationTest : public BenchmarkOperation {
~SmallDocumentCreationTest () {
}
string collectionName () {
return Collection;
}
const bool useCollection () const {
return true;
}
const string& url () {
return _url;
@ -232,6 +262,14 @@ struct BigDocumentCreationTest : public BenchmarkOperation {
~BigDocumentCreationTest () {
TRI_Free(TRI_UNKNOWN_MEM_ZONE, _buffer);
}
string collectionName () {
return Collection;
}
const bool useCollection () const {
return true;
}
const string& url () {
return _url;
@ -271,6 +309,21 @@ struct BigDocumentCreationTest : public BenchmarkOperation {
/// @{
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
/// @brief update the number of ready threads. this is a callback function
/// that is called by each thread after it is created
////////////////////////////////////////////////////////////////////////////////
static void UpdateStartCounter () {
MUTEX_LOCKER(StartMutex);
++Started;
}
static int GetStartCounter () {
MUTEX_LOCKER(StartMutex);
return Started;
}
////////////////////////////////////////////////////////////////////////////////
/// @brief parses the program options
////////////////////////////////////////////////////////////////////////////////
@ -368,7 +421,9 @@ int main (int argc, char* argv[]) {
endpoints.push_back(endpoint);
BenchmarkThread* thread = new BenchmarkThread(testCase,
&startCondition,
&startCondition,
&UpdateStartCounter,
i,
(unsigned long) BatchSize,
&operationsCounter,
endpoint,
@ -381,8 +436,9 @@ int main (int argc, char* argv[]) {
}
// give all threads a chance to start so they will not miss the broadcast
usleep(500000);
while (GetStartCounter() < Concurrency) {
usleep(5000);
}
Timing timer(Timing::TI_WALLCLOCK);