20 #include <ripple/basics/BasicConfig.h>
21 #include <ripple/basics/ByteUtilities.h>
22 #include <ripple/basics/safe_cast.h>
23 #include <ripple/beast/unit_test.h>
24 #include <ripple/beast/unit_test/thread.hpp>
25 #include <ripple/beast/utility/temp_dir.h>
26 #include <ripple/beast/xor_shift_engine.h>
27 #include <ripple/nodestore/DummyScheduler.h>
28 #include <ripple/nodestore/Manager.h>
29 #include <ripple/unity/rocksdb.h>
30 #include <boost/algorithm/string.hpp>
39 #include <test/nodestore/TestBase.h>
40 #include <test/unit_test/SuiteJournal.h>
45 #ifndef NODESTORE_TIMING_DO_VERIFY
46 #define NODESTORE_TIMING_DO_VERIFY 0
59 config,
megabytes(4), scheduler, journal);
63 template <
class Generator>
67 using result_type =
typename Generator::result_type;
68 while (bytes >=
sizeof(result_type))
71 memcpy(buffer, &v,
sizeof(v));
72 buffer =
reinterpret_cast<std::uint8_t*
>(buffer) +
sizeof(v);
79 memcpy(buffer, &v, bytes);
171 for (
auto iter = config.
begin(); iter != config.
end(); ++iter)
172 s += (iter != config.
begin() ?
"," :
"") + iter->first +
"=" +
190 boost::split(v, s, boost::algorithm::is_any_of(
","));
199 template <
class Body>
212 template <
class... Args>
233 template <
class Body,
class... Args>
243 for (
std::size_t id = 0;
id < number_of_threads; ++id)
249 template <
class Body,
class... Args>
259 for (
std::size_t id = 0;
id < number_of_threads; ++id)
275 auto backend =
make_Backend(config, scheduler, journal);
276 BEAST_EXPECT(backend !=
nullptr);
287 explicit Body(suite& s,
Backend& backend)
288 : suite_(s), backend_(backend), seq_(1)
301 suite_.fail(e.
what());
316 #if NODESTORE_TIMING_DO_VERIFY
332 auto backend =
make_Backend(config, scheduler, journal);
333 BEAST_EXPECT(backend !=
nullptr);
355 , dist_(0, params.
items - 1)
366 obj = seq1_.
obj(dist_(gen_));
367 backend_.
fetch(obj->getHash().data(), &result);
368 suite_.expect(result &&
isSame(result, obj));
372 suite_.fail(e.
what());
378 parallel_for_id<Body>(
387 #if NODESTORE_TIMING_DO_VERIFY
403 auto backend =
make_Backend(config, scheduler, journal);
404 BEAST_EXPECT(backend !=
nullptr);
428 , dist_(0, params.
items - 1)
437 auto const key = seq2_.
key(i);
439 backend_.
fetch(key.data(), &result);
440 suite_.expect(!result);
444 suite_.fail(e.
what());
451 parallel_for_id<Body>(
460 #if NODESTORE_TIMING_DO_VERIFY
476 auto backend =
make_Backend(config, scheduler, journal);
477 BEAST_EXPECT(backend !=
nullptr);
505 , dist_(0, params.
items - 1)
516 auto const key = seq2_.
key(dist_(gen_));
518 backend_.
fetch(key.data(), &result);
519 suite_.expect(!result);
525 obj = seq1_.
obj(dist_(gen_));
526 backend_.
fetch(obj->getHash().data(), &result);
527 suite_.expect(result &&
isSame(result, obj));
532 suite_.fail(e.
what());
539 parallel_for_id<Body>(
548 #if NODESTORE_TIMING_DO_VERIFY
565 auto backend =
make_Backend(config, scheduler, journal);
566 BEAST_EXPECT(backend !=
nullptr);
567 backend->setDeletePath();
595 , older_(0, params.
items - 1)
604 if (rand_(gen_) < 200)
609 auto const j = older_(gen_);
612 backend_.
fetch(obj->getHash().data(), &result);
613 suite_.expect(result !=
nullptr);
614 suite_.expect(
isSame(result, obj));
618 p[0] = rand_(gen_) < 50 ? 0 : 1;
620 for (
int q = 0; q < 2; ++q)
628 auto const j = recent_(gen_);
630 backend_.
fetch(obj->getHash().data(), &result);
631 suite_.expect(!result ||
isSame(result, obj));
637 auto const j = i + params_.
items;
646 suite_.fail(e.
what());
653 parallel_for_id<Body>(
662 #if NODESTORE_TIMING_DO_VERIFY
684 (this->*f)(config, params, journal);
685 return std::chrono::duration_cast<duration_type>(
697 for (
auto const& test : tests)
698 if (w < test.first.size())
699 w = test.first.size();
700 log << threads <<
" Thread" << (threads > 1 ?
"s" :
"") <<
", "
705 for (
auto const& test : tests)
706 ss <<
" " << setw(w) << test.first;
713 for (
auto const& config_string : config_strings)
722 config.
set(
"path", tempDir.
path());
726 for (
auto const& test : tests)
729 do_test(test.second, config, params, journal));
739 testcase(
"Timing", beast::unit_test::abort_on_fail);
749 #if RIPPLE_ROCKSDB_AVAILABLE
750 ";type=rocksdb,open_files=2000,filter_bits=12,cache_mb=256,"
751 "file_size_mb=8,file_size_mult=2"
754 ";type=memory|path=NodeStore"
765 auto args = arg().empty() ? default_args : arg();
767 boost::split(config_strings, args, boost::algorithm::is_any_of(
";"));
768 for (
auto iter = config_strings.
begin(); iter != config_strings.
end();)
770 iter = config_strings.
erase(iter);
static std::string to_string(Section const &config)
Simple NodeStore Scheduler that just peforms the tasks synchronously.
void batch(std::size_t n, Batch &b, std::size_t size)
Holds a collection of configuration values.
T setprecision(T... args)
std::uniform_int_distribution< std::uint32_t > d_size_
const std::size_t default_repeat
void do_insert(Section const &config, Params const ¶ms, beast::Journal journal)
static std::shared_ptr< NodeObject > createObject(NodeObjectType type, Blob &&data, uint256 const &hash)
Create an object from fields.
std::discrete_distribution< std::uint32_t > d_type_
void operator()(Args &&... args)
A namespace for easy access to logging severity values.
std::atomic< std::size_t > & c_
virtual void store(std::shared_ptr< NodeObject > const &object)=0
Store a single object.
void do_fetch(Section const &config, Params const ¶ms, beast::Journal journal)
const_iterator begin() const
constexpr static std::size_t size()
void append(std::vector< std::string > const &lines)
Append a set of lines to this section.
std::unique_ptr< Backend > make_Backend(Section const &config, Scheduler &scheduler, beast::Journal journal)
const_iterator end() const
static void rngcpy(void *buffer, std::size_t bytes, Generator &g)
void do_tests(std::size_t threads, test_list const &tests, std::vector< std::string > const &config_strings)
void parallel_for(std::size_t const n, std::size_t number_of_threads, Args const &... args)
BEAST_DEFINE_TESTSUITE_MANUAL_PRIO(Timing, NodeStore, ripple, 1)
void do_mixed(Section const &config, Params const ¶ms, beast::Journal journal)
std::shared_ptr< NodeObject > obj(std::size_t n)
void Rethrow()
Rethrow the exception currently being handled.
void do_work(Section const &config, Params const ¶ms, beast::Journal journal)
constexpr auto megabytes(T value) noexcept
void seed(result_type seed)
A generic endpoint for log messages.
Scheduling for asynchronous backend activity.
void do_missing(Section const &config, Params const ¶ms, beast::Journal journal)
Sequence(std::uint8_t prefix)
std::string path() const
Get the native path for the temporary directory.
uint256 key(std::size_t n)
T emplace_back(T... args)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
void set(std::string const &key, std::string const &value)
Set a key/value pair.
virtual std::unique_ptr< Backend > make_Backend(Section const ¶meters, std::size_t burstSize, Scheduler &scheduler, beast::Journal journal)=0
Create a backend.
static Section parse(std::string s)
bool isSame(std::shared_ptr< NodeObject > const &lhs, std::shared_ptr< NodeObject > const &rhs)
Returns true if objects are identical.
static std::string to_string(duration_type const &d)
parallel_for_lambda(std::size_t n, std::atomic< std::size_t > &c)
void(Timing_test::*)(Section const &, Params const &, beast::Journal) test_func
beast::xor_shift_engine gen_
static Manager & instance()
Returns the instance of the manager singleton.
const std::size_t default_items
duration_type do_test(test_func f, Section const &config, Params const ¶ms, beast::Journal journal)
virtual Status fetch(void const *key, std::shared_ptr< NodeObject > *pObject)=0
Fetch a single object.
RAII temporary directory.
T & get(EitherAmount &amt)
void parallel_for_id(std::size_t const n, std::size_t number_of_threads, Args const &... args)
A backend used for the NodeStore.