Skip to content

Commit

Permalink
Add config options steemit#1891
Browse files Browse the repository at this point in the history
  • Loading branch information
mvandeberg committed Mar 21, 2018
1 parent bbbf912 commit fb9aec2
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 14 deletions.
22 changes: 10 additions & 12 deletions libraries/chain/database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@ void database::open( const open_args& args )
auto last_block_num = _block_log.head()->block_num();
args.benchmark.second(last_block_num, get_abstract_index_cntr());
}

_shared_file_full_threshold = args.shared_file_full_threshold;
_shared_file_scale_rate = args.shared_file_scale_rate;
}
FC_CAPTURE_LOG_AND_RETHROW( (args.data_dir)(args.shared_mem_dir)(args.shared_file_size) )
}
Expand Down Expand Up @@ -2630,22 +2633,17 @@ void database::check_free_memory( bool force_print, uint32_t current_block_num )
uint64_t free_mem = get_free_memory();
uint64_t max_mem = get_max_memory();

//idump( (free_mem)(max_mem) );

uint16_t full_threshold = 90 * STEEM_1_PERCENT;
uint16_t scale_factor = 25 * STEEM_1_PERCENT;

if( BOOST_UNLIKELY( full_threshold != 0 && scale_factor != 0 && free_mem < ( ( uint128_t( STEEM_100_PERCENT - full_threshold ) * max_mem ) / STEEM_100_PERCENT ).to_uint64() ) )
if( BOOST_UNLIKELY( _shared_file_full_threshold != 0 && _shared_file_scale_rate != 0 && free_mem < ( ( uint128_t( STEEM_100_PERCENT - _shared_file_full_threshold ) * max_mem ) / STEEM_100_PERCENT ).to_uint64() ) )
{
uint64_t new_max = ( uint128_t( max_mem * scale_factor ) / STEEM_100_PERCENT ).to_uint64() + max_mem;
uint64_t new_max = ( uint128_t( max_mem * _shared_file_scale_rate ) / STEEM_100_PERCENT ).to_uint64() + max_mem;

wlog( "Memory is almost full, increasing to ${mem}G", ("mem", new_max / (1024*1024*1024)) );
wlog( "Memory is almost full, increasing to ${mem}M", ("mem", new_max / (1024*1024)) );

resize( new_max );

uint32_t free_gb = uint32_t( get_free_memory() / (1024*1024*1024) );
wlog( "Free memory is now ${free}G", ("free", get_free_memory() / (1024*1024*1024)) );
_last_free_gb_printed = free_gb;
uint32_t free_mb = uint32_t( get_free_memory() / (1024*1024) );
wlog( "Free memory is now ${free}M", ("free", free_mb) );
_last_free_gb_printed = free_mb / 1024;
}
else
{
Expand All @@ -2658,7 +2656,7 @@ void database::check_free_memory( bool force_print, uint32_t current_block_num )

if( BOOST_UNLIKELY( free_gb == 0 ) )
{
uint32_t free_mb = uint32_t( get_free_memory() / (1024*1024) );
uint32_t free_mb = uint32_t( free_mem / (1024*1024) );

#ifdef IS_TEST_NET
if( !disable_low_mem_warning )
Expand Down
5 changes: 5 additions & 0 deletions libraries/chain/include/steem/chain/database.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ namespace steem { namespace chain {
fc::path shared_mem_dir;
uint64_t initial_supply = STEEM_INIT_SUPPLY;
uint64_t shared_file_size = 0;
uint16_t shared_file_full_threshold = 0;
uint16_t shared_file_scale_rate = 0;
uint32_t chainbase_flags = 0;
bool do_validate_invariants = false;

Expand Down Expand Up @@ -529,6 +531,9 @@ namespace steem { namespace chain {
/// For Initial value see appropriate comment where get_smt_next_identifier is implemented.
uint32_t _next_available_nai = SMT_MIN_NON_RESERVED_NAI;

uint16_t _shared_file_full_threshold = 0;
uint16_t _shared_file_scale_rate = 0;

flat_map< std::string, std::shared_ptr< custom_operation_interpreter > > _custom_operation_interpreters;
std::string _json_schema;

Expand Down
14 changes: 12 additions & 2 deletions libraries/plugins/chain/chain_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ class chain_plugin_impl
void stop_write_processing();

uint64_t shared_memory_size = 0;
uint16_t shared_file_full_threshold = 0;
uint16_t shared_file_scale_rate = 0;
bfs::path shared_memory_dir;
bool replay = false;
bool resync = false;
Expand Down Expand Up @@ -234,7 +236,11 @@ void chain_plugin::set_program_options(options_description& cli, options_descrip
cfg.add_options()
("shared-file-dir", bpo::value<bfs::path>()->default_value("blockchain"),
"the location of the chain shared memory files (absolute path or relative to application data dir)")
("shared-file-size", bpo::value<string>()->default_value("54G"), "Size of the shared memory file. Default: 54G")
("shared-file-size", bpo::value<string>()->default_value("24G"), "Size of the shared memory file. Default: 24G. If running a full node, increase this value to 200G.")
("shared-file-full-threshold", bpo::value<uint16_t>()->default_value(0),
"A 2 precision percentage (0-10000) that defines the threshold for when to autoscale the shared memory file. Setting this to 0 disables autoscaling. Recommended value for consensus node is 9500 (95%). Full node is 9900 (99%)" )
("shared-file-scale-rate", bpo::value<uint16_t>()->default_value(0),
"A 2 precision percentage (0-10000) that defines how quickly to scale the shared memory file. When autoscaling occurs the file's size will be increased by this percent. Setting this to 0 disables autoscaling. Recommended value is between 1000-2000 (10-20%)" )
("checkpoint,c", bpo::value<vector<string>>()->composing(), "Pairs of [BLOCK_NUM,BLOCK_ID] that should be enforced as checkpoints.")
("flush-state-interval", bpo::value<uint32_t>(),
"flush shared memory changes to disk every N blocks")
Expand Down Expand Up @@ -265,7 +271,9 @@ void chain_plugin::plugin_initialize(const variables_map& options) {
my->shared_memory_dir = sfd;
}

my->shared_memory_size = fc::parse_size( options.at( "shared-file-size" ).as< string >() );
my->shared_memory_size = fc::parse_size( options.at( "shared-file-size" ).as< string >() );
my->shared_file_full_threshold = options.at( "shared-file-full-threshold" ).as< uint16_t >();
my->shared_file_scale_rate = options.at( "shared-file-scale_rate" ).as< uint16_t >();

my->replay = options.at( "replay-blockchain").as<bool>();
my->resync = options.at( "resync-blockchain").as<bool>();
Expand Down Expand Up @@ -341,6 +349,8 @@ void chain_plugin::plugin_startup()
db_open_args.shared_mem_dir = my->shared_memory_dir;
db_open_args.initial_supply = STEEM_INIT_SUPPLY;
db_open_args.shared_file_size = my->shared_memory_size;
db_open_args.shared_file_full_threshold = my->shared_file_full_threshold;
db_open_args.shared_file_scale_rate = my->shared_file_scale_rate;
db_open_args.do_validate_invariants = my->validate_invariants;
db_open_args.stop_replay_at = my->stop_replay_at;

Expand Down

0 comments on commit fb9aec2

Please sign in to comment.