From dcacc5af0ad1679a276bb4bd4b3015e64bae9adf Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Mon, 16 Apr 2018 14:24:56 -0700 Subject: [PATCH] ircd::m::vm: Add db::txn allocation reservation options. --- include/ircd/m/vm.h | 20 ++++++++++++++++---- ircd/m/vm.cc | 16 ++++++++++++++-- 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/include/ircd/m/vm.h b/include/ircd/m/vm.h index a76d9d7b8..e61ed41da 100644 --- a/include/ircd/m/vm.h +++ b/include/ircd/m/vm.h @@ -41,14 +41,15 @@ namespace ircd::m::vm /// struct ircd::m::vm::eval { - const vm::opts *opts {&default_opts}; - db::txn txn{*dbs::events}; + const vm::opts *opts; + db::txn txn; fault operator()(const event &); eval(const event &, const vm::opts & = default_opts); - eval(const vm::opts &); - eval() = default; + eval(const vm::opts & = default_opts); + eval(eval &&) = delete; + eval(const eval &) = delete; friend string_view reflect(const fault &); }; @@ -126,6 +127,17 @@ struct ircd::m::vm::opts /// TODO: Y bool head_must_exist {false}; + /// Evaluators can set this value to optimize the creation of the database + /// transaction where the event will be stored. This value should be set + /// to the amount of space the event consumes; the JSON-serialized size is + /// a good value here. + size_t reserve_bytes {1024}; + + /// This value is added to reserve_bytes to account for indexing overhead + /// in the database transaction allocation. Most evaluators have little + /// reason to ever adjust this. + size_t reserve_index {1536}; + /// Mask of faults that are not thrown as exceptions out of eval(). If /// masked, the fault is returned from eval(). By default, the EXISTS /// fault is masked which means existing events won't kill eval loops diff --git a/ircd/m/vm.cc b/ircd/m/vm.cc index 69d921011..2d442feb4 100644 --- a/ircd/m/vm.cc +++ b/ircd/m/vm.cc @@ -173,6 +173,7 @@ ircd::m::vm::commit(const event &event, auto opts_{opts}; opts_.verify = false; + opts_.reserve_bytes = serialized(event); // Some functionality on this server may create an event on behalf // of remote users. It's safe for us to mask this here, but eval'ing @@ -227,13 +228,24 @@ ircd::m::vm::notify_hook }; ircd::m::vm::eval::eval(const vm::opts &opts) -:opts{&opts} +:opts +{ + &opts +} +,txn +{ + *dbs::events, db::txn::opts + { + opts.reserve_bytes + opts.reserve_index, // reserve_bytes + 0, // max_bytes (no max) + } +} { } ircd::m::vm::eval::eval(const event &event, const vm::opts &opts) -:opts{&opts} +:eval{opts} { operator()(event); }