Introduce partitioned unordered maps:

This commit implements partitioned unordered maps and makes it possible
to traverse such a map in parallel, allowing for more efficient use of
CPU resources.

The `CachedSLEs`, `TaggedCache`, and `KeyCache` classes make use of the
new functionality, which should improve performance.
This commit is contained in:
Mark Travis
2021-09-17 15:48:33 -07:00
committed by seelabs
parent 7edfbbd8bd
commit 19018e8959
26 changed files with 1089 additions and 770 deletions

View File

@@ -17,10 +17,13 @@
*/
//==============================================================================
#include <ripple/basics/KeyCache.h>
#include <ripple/basics/TaggedCache.h>
#include <ripple/basics/chrono.h>
#include <ripple/beast/clock/manual_clock.h>
#include <ripple/beast/unit_test.h>
#include <ripple/beast/utility/Journal.h>
#include <ripple/protocol/Protocol.h>
#include <test/unit_test/SuiteJournal.h>
namespace ripple {
@@ -35,32 +38,31 @@ public:
clock.set(0);
using Key = std::string;
using Cache = KeyCache<Key>;
using Cache = TaggedCache<Key, int, true>;
test::SuiteJournal j("KeyCacheTest", *this);
// Insert an item, retrieve it, and age it so it gets purged.
{
Cache c("test", clock, 1, 2s);
Cache c("test", LedgerIndex(1), 2s, clock, j);
BEAST_EXPECT(c.size() == 0);
BEAST_EXPECT(c.insert("one"));
BEAST_EXPECT(!c.insert("one"));
BEAST_EXPECT(c.size() == 1);
BEAST_EXPECT(c.exists("one"));
BEAST_EXPECT(c.touch_if_exists("one"));
++clock;
c.sweep();
BEAST_EXPECT(c.size() == 1);
BEAST_EXPECT(c.exists("one"));
++clock;
c.sweep();
BEAST_EXPECT(c.size() == 0);
BEAST_EXPECT(!c.exists("one"));
BEAST_EXPECT(!c.touch_if_exists("one"));
}
// Insert two items, have one expire
{
Cache c("test", clock, 2, 2s);
Cache c("test", LedgerIndex(2), 2s, clock, j);
BEAST_EXPECT(c.insert("one"));
BEAST_EXPECT(c.size() == 1);
@@ -73,12 +75,11 @@ public:
++clock;
c.sweep();
BEAST_EXPECT(c.size() == 1);
BEAST_EXPECT(c.exists("two"));
}
// Insert three items (1 over limit), sweep
{
Cache c("test", clock, 2, 3s);
Cache c("test", LedgerIndex(2), 3s, clock, j);
BEAST_EXPECT(c.insert("one"));
++clock;

View File

@@ -21,6 +21,7 @@
#include <ripple/basics/chrono.h>
#include <ripple/beast/clock/manual_clock.h>
#include <ripple/beast/unit_test.h>
#include <ripple/protocol/Protocol.h>
#include <test/unit_test/SuiteJournal.h>
namespace ripple {
@@ -48,7 +49,7 @@ public:
TestStopwatch clock;
clock.set(0);
using Key = int;
using Key = LedgerIndex;
using Value = std::string;
using Cache = TaggedCache<Key, Value>;

View File

@@ -21,9 +21,9 @@
#include <ripple/beast/clock/manual_clock.h>
#include <ripple/beast/unit_test.h>
#include <ripple/consensus/Validations.h>
#include <test/csf/Validation.h>
#include <memory>
#include <test/csf/Validation.h>
#include <test/unit_test/SuiteJournal.h>
#include <tuple>
#include <type_traits>
#include <vector>
@@ -703,6 +703,7 @@ class Validations_test : public beast::unit_test::suite
{
// Verify expiring clears out validations stored by ledger
testcase("Expire validations");
SuiteJournal j("Validations_test", *this);
LedgerHistoryHelper h;
TestHarness harness(h.oracle);
Node const a = harness.makeNode();
@@ -713,10 +714,10 @@ class Validations_test : public beast::unit_test::suite
Ledger const ledgerA = h["a"];
BEAST_EXPECT(ValStatus::current == harness.add(a.validate(ledgerA)));
BEAST_EXPECT(harness.vals().numTrustedForLedger(ledgerA.id()) == 1);
harness.vals().expire();
harness.vals().expire(j);
BEAST_EXPECT(harness.vals().numTrustedForLedger(ledgerA.id()) == 1);
harness.clock().advance(harness.parms().validationSET_EXPIRES);
harness.vals().expire();
harness.vals().expire(j);
BEAST_EXPECT(harness.vals().numTrustedForLedger(ledgerA.id()) == 0);
// use setSeqToKeep to keep the validation from expire
@@ -725,7 +726,7 @@ class Validations_test : public beast::unit_test::suite
BEAST_EXPECT(harness.vals().numTrustedForLedger(ledgerB.id()) == 1);
harness.vals().setSeqToKeep(ledgerB.seq(), ledgerB.seq() + one);
harness.clock().advance(harness.parms().validationSET_EXPIRES);
harness.vals().expire();
harness.vals().expire(j);
BEAST_EXPECT(harness.vals().numTrustedForLedger(ledgerB.id()) == 1);
// change toKeep
harness.vals().setSeqToKeep(ledgerB.seq() + one, ledgerB.seq() + two);
@@ -736,7 +737,7 @@ class Validations_test : public beast::unit_test::suite
for (int i = 0; i < loops; ++i)
{
harness.clock().advance(harness.parms().validationFRESHNESS);
harness.vals().expire();
harness.vals().expire(j);
}
BEAST_EXPECT(harness.vals().numTrustedForLedger(ledgerB.id()) == 0);
@@ -746,7 +747,7 @@ class Validations_test : public beast::unit_test::suite
BEAST_EXPECT(harness.vals().numTrustedForLedger(ledgerC.id()) == 1);
harness.vals().setSeqToKeep(ledgerC.seq() - one, ledgerC.seq());
harness.clock().advance(harness.parms().validationSET_EXPIRES);
harness.vals().expire();
harness.vals().expire(j);
BEAST_EXPECT(harness.vals().numTrustedForLedger(ledgerC.id()) == 0);
}

View File

@@ -919,7 +919,7 @@ struct Peer
start()
{
// TODO: Expire validations less frequently?
validations.expire();
validations.expire(j);
scheduler.in(parms().ledgerGRANULARITY, [&]() { timerEntry(); });
startRound();
}

View File

@@ -46,7 +46,8 @@ public:
TestNodeFamily(beast::Journal j)
: fbCache_(std::make_shared<FullBelowCache>(
"App family full below cache",
clock_))
clock_,
j))
, tnCache_(std::make_shared<TreeNodeCache>(
"App family tree node cache",
65536,