Change NodeStore::Backend tests to reflect observed patterns:

Empirical evidence shows a database access pattern with few hits
and many misses (objects that don't exist). This changes the timing
tests so they more accurately reflect rippled's actual usage:
* Add read missing keys test
* Increase numObjectsToTest to 1,000,000
* Alter PredictableObjectFactory to seed RNG once only
* Make NodeStoreTiming a manual test
This commit is contained in:
Donovan Hide
2014-10-22 21:24:29 +01:00
committed by Vinnie Falco
parent 5b7f172d03
commit 44c68d6174
5 changed files with 41 additions and 24 deletions

View File

@@ -43,7 +43,7 @@ public:
// Create a batch
Batch batch;
createPredictableBatch (batch, 0, numObjectsToTest, seedValue);
createPredictableBatch (batch, numObjectsToTest, seedValue);
beast::Journal j;

View File

@@ -31,15 +31,15 @@ public:
testcase ("batch");
Batch batch1;
createPredictableBatch (batch1, 0, numObjectsToTest, seedValue);
createPredictableBatch (batch1, numObjectsToTest, seedValue);
Batch batch2;
createPredictableBatch (batch2, 0, numObjectsToTest, seedValue);
createPredictableBatch (batch2, numObjectsToTest, seedValue);
expect (areBatchesEqual (batch1, batch2), "Should be equal");
Batch batch3;
createPredictableBatch (batch3, 1, numObjectsToTest, seedValue);
createPredictableBatch (batch3, numObjectsToTest, seedValue+1);
expect (! areBatchesEqual (batch1, batch3), "Should not be equal");
}
@@ -50,7 +50,7 @@ public:
testcase ("encoding");
Batch batch;
createPredictableBatch (batch, 0, numObjectsToTest, seedValue);
createPredictableBatch (batch, numObjectsToTest, seedValue);
EncodedBlob encoded;
for (int i = 0; i < batch.size (); ++i)

View File

@@ -37,7 +37,7 @@ public:
// Create a batch
Batch batch;
createPredictableBatch (batch, 0, numObjectsToTest, seedValue);
createPredictableBatch (batch, numObjectsToTest, seedValue);
beast::Journal j;
@@ -113,7 +113,7 @@ public:
// Create a batch
Batch batch;
createPredictableBatch (batch, 0, numObjectsToTest, seedValue);
createPredictableBatch (batch, numObjectsToTest, seedValue);
beast::Journal j;

View File

@@ -44,14 +44,12 @@ public:
{
public:
explicit PredictableObjectFactory (std::int64_t seedValue)
: m_seedValue (seedValue)
: r (seedValue)
{
}
NodeObject::Ptr createObject (int index)
NodeObject::Ptr createObject ()
{
beast::Random r (m_seedValue + index);
NodeObjectType type;
switch (r.nextInt (4))
{
@@ -79,20 +77,19 @@ public:
}
private:
std::int64_t const m_seedValue;
beast::Random r;
};
public:
// Create a predictable batch of objects
static void createPredictableBatch (Batch& batch, int startingIndex,
int numObjects, std::int64_t seedValue)
{
// Create a predictable batch of objects
static void createPredictableBatch(Batch& batch, int numObjects,
std::int64_t seedValue) {
batch.reserve (numObjects);
PredictableObjectFactory factory (seedValue);
for (int i = 0; i < numObjects; ++i)
batch.push_back (factory.createObject (startingIndex + i));
batch.push_back (factory.createObject ());
}
// Compare two batches for equality
@@ -152,6 +149,19 @@ public:
}
}
void fetchMissing(Backend& backend, Batch const& batch)
{
for (int i = 0; i < batch.size (); ++i)
{
NodeObject::Ptr object;
Status const status = backend.fetch (
batch [i]->getHash ().cbegin (), &object);
expect (status == notFound, "Should be notFound");
}
}
// Store all objects in a batch
static void storeBatch (Database& db, Batch const& batch)
{

View File

@@ -25,7 +25,7 @@ class NodeStoreTiming_test : public TestBase
public:
enum
{
numObjectsToTest = 10000
numObjectsToTest = 1000000
};
class Stopwatch
@@ -68,9 +68,11 @@ public:
// Create batches
NodeStore::Batch batch1;
createPredictableBatch (batch1, 0, numObjectsToTest, seedValue);
createPredictableBatch (batch1, numObjectsToTest, seedValue);
NodeStore::Batch batch2;
createPredictableBatch (batch2, 0, numObjectsToTest, seedValue);
createPredictableBatch (batch2, numObjectsToTest, seedValue);
NodeStore::Batch missingBatch;
createPredictableBatch (missingBatch, numObjectsToTest, seedValue+1);
beast::Journal j;
@@ -83,19 +85,24 @@ public:
// Individual write batch test
t.start ();
storeBatch (*backend, batch1);
log << " Single write: " << std::to_string (t.getElapsed ()) << " seconds";
log << " Single write: " << std::to_string (t.getElapsed ()) << " seconds";
// Bulk write batch test
t.start ();
backend->storeBatch (batch2);
log << " Batch write: " << std::to_string (t.getElapsed ()) << " seconds";
log << " Batch write: " << std::to_string (t.getElapsed ()) << " seconds";
// Read test
Batch copy;
t.start ();
fetchCopyOfBatch (*backend, &copy, batch1);
fetchCopyOfBatch (*backend, &copy, batch2);
log << " Batch read: " << std::to_string (t.getElapsed ()) << " seconds";
log << " Batch read: " << std::to_string (t.getElapsed ()) << " seconds";
// Read missing keys test
t.start ();
fetchMissing (*backend, missingBatch);
log << " Batch read missing: " << std::to_string (t.getElapsed ()) << " seconds";
}
//--------------------------------------------------------------------------
@@ -120,7 +127,7 @@ public:
}
};
BEAST_DEFINE_TESTSUITE(NodeStoreTiming,ripple_core,ripple);
BEAST_DEFINE_TESTSUITE_MANUAL(NodeStoreTiming,ripple_core,ripple);
}
}