Skip to content

Commit

Permalink
Dynamic block size for custom allocator (API change):
Browse files Browse the repository at this point in the history
This changes the internal arena allocator to dynamically adjust
the block size based on the allocation throughput. It removes
the requirement that callers specify the alloc size.

Public interfaces that previously required an allocation size
hint, now no longer require the hint. It is sufficient to simply
delete the parameter from call sites.
  • Loading branch information
vinniefalco committed Sep 8, 2016
1 parent 1f9d380 commit 90117d5
Show file tree
Hide file tree
Showing 12 changed files with 304 additions and 130 deletions.
3 changes: 1 addition & 2 deletions README.md
Expand Up @@ -96,8 +96,7 @@ int main()
0.5f,
ec);
store db;
db.open(dat_path, key_path, log_path,
16 * 1024 * 1024, ec);
db.open(dat_path, key_path, log_path, ec);
char data = 0;
// Insert
for(key_type i = 0; i < N; ++i)
Expand Down
1 change: 0 additions & 1 deletion doc/master.qbk
Expand Up @@ -123,7 +123,6 @@ database is created.

[endsect]


[endsect]

[section:types Type Requirements]
Expand Down
4 changes: 2 additions & 2 deletions examples/example.cpp
Expand Up @@ -6,6 +6,7 @@
//

#include <nudb/nudb.hpp>
#include <cstddef>
#include <cstdint>

int main()
Expand All @@ -26,8 +27,7 @@ int main()
0.5f,
ec);
store db;
db.open(dat_path, key_path, log_path,
16 * 1024 * 1024, ec);
db.open(dat_path, key_path, log_path, ec);
char data = 0;
// Insert
for(key_type i = 0; i < N; ++i)
Expand Down
3 changes: 1 addition & 2 deletions extras/nudb/test/test_store.hpp
Expand Up @@ -265,8 +265,7 @@ basic_test_store(std::size_t keySize_, std::size_t blockSize_,
, openf_(
[this, args...](error_code& ec)
{
db.open(dp, kp, lp,
16 * 1024 * 1024, ec, args...);
db.open(dp, kp, lp, ec, args...);
})
, dp(td_.file("nudb.dat"))
, kp(td_.file("nudb.key"))
Expand Down
21 changes: 4 additions & 17 deletions include/nudb/basic_store.hpp
Expand Up @@ -12,10 +12,9 @@
#include <nudb/type_traits.hpp>
#include <nudb/detail/cache.hpp>
#include <nudb/detail/gentex.hpp>
#include <nudb/detail/mutex.hpp>
#include <nudb/detail/pool.hpp>
#include <boost/optional.hpp>
#include <boost/thread/lock_types.hpp>
#include <boost/thread/shared_mutex.hpp>
#include <chrono>
#include <mutex>
#include <thread>
Expand Down Expand Up @@ -56,12 +55,6 @@ class basic_store
using clock_type =
std::chrono::steady_clock;

using shared_lock_type =
boost::shared_lock<boost::shared_mutex>;

using unique_lock_type =
boost::unique_lock<boost::shared_mutex>;

struct state
{
File df;
Expand Down Expand Up @@ -89,8 +82,7 @@ class basic_store
state(File&& df_, File&& kf_, File&& lf_,
path_type const& dp_, path_type const& kp_,
path_type const& lp_,
detail::key_file_header const& kh_,
std::size_t arenaBlockSize);
detail::key_file_header const& kh_);
};

bool open_ = false;
Expand Down Expand Up @@ -319,10 +311,6 @@ class basic_store
@param log_path The path to the log file.
@param arenaBlockSize A hint to the size of the blocks
used to allocate memory for buffering insertions. A reasonable
value is one thousand times the size of the average value.
@param ec Set to the error, if any occurred.
@param args Optional arguments passed to @b File constructors.
Expand All @@ -334,7 +322,6 @@ class basic_store
path_type const& dat_path,
path_type const& key_path,
path_type const& log_path,
std::size_t arenaBlockSize,
error_code& ec,
Args&&... args);

Expand Down Expand Up @@ -429,7 +416,7 @@ class basic_store

bool
exists(detail::nhash_t h, void const* key,
shared_lock_type* lock, detail::bucket b, error_code& ec);
detail::shared_lock_type* lock, detail::bucket b, error_code& ec);

void
split(detail::bucket& b1, detail::bucket& b2,
Expand All @@ -442,7 +429,7 @@ class basic_store
detail::cache& c0, void* buf, error_code& ec);

void
commit(error_code& ec);
commit(detail::unique_lock_type& m, error_code& ec);

void
run();
Expand Down

0 comments on commit 90117d5

Please sign in to comment.