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;