mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
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:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user