mirror of
https://codeberg.org/anoncontributorxmr/monero.git
synced 2024-12-26 07:07:57 +00:00
add a --max-concurrency flag
It sets the max number of threads to use for a parallel job. This is different that the number of total threads, since monero binaries typically start a lot of them.
This commit is contained in:
parent
bdb93cbf3d
commit
513a658c87
8 changed files with 47 additions and 7 deletions
|
@ -135,7 +135,7 @@ const unsigned int DB_BUFFER_LENGTH = 32 * MB;
|
||||||
const unsigned int DB_DEF_CACHESIZE = 256 * MB;
|
const unsigned int DB_DEF_CACHESIZE = 256 * MB;
|
||||||
|
|
||||||
#if defined(BDB_BULK_CAN_THREAD)
|
#if defined(BDB_BULK_CAN_THREAD)
|
||||||
const unsigned int DB_BUFFER_COUNT = boost::thread::hardware_concurrency();
|
const unsigned int DB_BUFFER_COUNT = tools::get_max_concurrency();
|
||||||
#else
|
#else
|
||||||
const unsigned int DB_BUFFER_COUNT = 1;
|
const unsigned int DB_BUFFER_COUNT = 1;
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -422,4 +422,27 @@ std::string get_nix_version_display_string()
|
||||||
umask(mode);
|
umask(mode);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
boost::mutex max_concurrency_lock;
|
||||||
|
unsigned max_concurrency = boost::thread::hardware_concurrency();
|
||||||
|
}
|
||||||
|
|
||||||
|
void set_max_concurrency(unsigned n)
|
||||||
|
{
|
||||||
|
if (n < 1)
|
||||||
|
n = boost::thread::hardware_concurrency();
|
||||||
|
unsigned hwc = boost::thread::hardware_concurrency();
|
||||||
|
if (n > hwc)
|
||||||
|
n = hwc;
|
||||||
|
boost::lock_guard<boost::mutex> lock(max_concurrency_lock);
|
||||||
|
max_concurrency = n;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned get_max_concurrency()
|
||||||
|
{
|
||||||
|
boost::lock_guard<boost::mutex> lock(max_concurrency_lock);
|
||||||
|
return max_concurrency;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -160,4 +160,7 @@ namespace tools
|
||||||
};
|
};
|
||||||
|
|
||||||
void set_strict_default_file_permissions(bool strict);
|
void set_strict_default_file_permissions(bool strict);
|
||||||
|
|
||||||
|
void set_max_concurrency(unsigned n);
|
||||||
|
unsigned get_max_concurrency();
|
||||||
}
|
}
|
||||||
|
|
|
@ -2124,7 +2124,7 @@ bool Blockchain::check_tx_inputs(const transaction& tx, tx_verification_context
|
||||||
std::vector < uint64_t > results;
|
std::vector < uint64_t > results;
|
||||||
results.resize(tx.vin.size(), 0);
|
results.resize(tx.vin.size(), 0);
|
||||||
|
|
||||||
int threads = boost::thread::hardware_concurrency();
|
int threads = tools::get_max_concurrency();
|
||||||
|
|
||||||
boost::asio::io_service ioservice;
|
boost::asio::io_service ioservice;
|
||||||
boost::thread_group threadpool;
|
boost::thread_group threadpool;
|
||||||
|
@ -3001,7 +3001,7 @@ bool Blockchain::prepare_handle_incoming_blocks(const std::list<block_complete_e
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
bool blocks_exist = false;
|
bool blocks_exist = false;
|
||||||
uint64_t threads = boost::thread::hardware_concurrency();
|
uint64_t threads = tools::get_max_concurrency();
|
||||||
|
|
||||||
if (blocks_entry.size() > 1 && threads > 1 && m_max_prepare_blocks_threads > 1)
|
if (blocks_entry.size() > 1 && threads > 1 && m_max_prepare_blocks_threads > 1)
|
||||||
{
|
{
|
||||||
|
@ -3200,7 +3200,7 @@ bool Blockchain::prepare_handle_incoming_blocks(const std::list<block_complete_e
|
||||||
// [output] stores all transactions for each tx_out_index::hash found
|
// [output] stores all transactions for each tx_out_index::hash found
|
||||||
std::vector<std::unordered_map<crypto::hash, cryptonote::transaction>> transactions(amounts.size());
|
std::vector<std::unordered_map<crypto::hash, cryptonote::transaction>> transactions(amounts.size());
|
||||||
|
|
||||||
threads = boost::thread::hardware_concurrency();
|
threads = tools::get_max_concurrency();
|
||||||
if (!m_db->can_thread_bulk_indices())
|
if (!m_db->can_thread_bulk_indices())
|
||||||
threads = 1;
|
threads = 1;
|
||||||
|
|
||||||
|
|
|
@ -59,6 +59,11 @@ namespace daemon_args
|
||||||
"os-version"
|
"os-version"
|
||||||
, "OS for which this executable was compiled"
|
, "OS for which this executable was compiled"
|
||||||
};
|
};
|
||||||
|
const command_line::arg_descriptor<unsigned> arg_max_concurrency = {
|
||||||
|
"max-concurrency"
|
||||||
|
, "Max number of threads to use for a parallel job"
|
||||||
|
, 0
|
||||||
|
};
|
||||||
} // namespace daemon_args
|
} // namespace daemon_args
|
||||||
|
|
||||||
#endif // DAEMON_COMMAND_LINE_ARGS_H
|
#endif // DAEMON_COMMAND_LINE_ARGS_H
|
||||||
|
|
|
@ -81,6 +81,7 @@ int main(int argc, char const * argv[])
|
||||||
bf::path default_log = default_data_dir / std::string(CRYPTONOTE_NAME ".log");
|
bf::path default_log = default_data_dir / std::string(CRYPTONOTE_NAME ".log");
|
||||||
command_line::add_arg(core_settings, daemon_args::arg_log_file, default_log.string());
|
command_line::add_arg(core_settings, daemon_args::arg_log_file, default_log.string());
|
||||||
command_line::add_arg(core_settings, daemon_args::arg_log_level);
|
command_line::add_arg(core_settings, daemon_args::arg_log_level);
|
||||||
|
command_line::add_arg(core_settings, daemon_args::arg_max_concurrency);
|
||||||
|
|
||||||
daemonizer::init_options(hidden_options, visible_options);
|
daemonizer::init_options(hidden_options, visible_options);
|
||||||
daemonize::t_executor::init_options(core_settings);
|
daemonize::t_executor::init_options(core_settings);
|
||||||
|
@ -260,6 +261,9 @@ int main(int argc, char const * argv[])
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (command_line::has_arg(vm, daemon_args::arg_max_concurrency))
|
||||||
|
tools::set_max_concurrency(command_line::get_arg(vm, daemon_args::arg_max_concurrency));
|
||||||
|
|
||||||
_note_c("dbg/main", "Moving from main() into the daemonize now.");
|
_note_c("dbg/main", "Moving from main() into the daemonize now.");
|
||||||
|
|
||||||
return daemonizer::daemonize(argc, argv, daemonize::t_executor{}, vm);
|
return daemonizer::daemonize(argc, argv, daemonize::t_executor{}, vm);
|
||||||
|
|
|
@ -110,6 +110,7 @@ namespace
|
||||||
const command_line::arg_descriptor<bool> arg_non_deterministic = {"non-deterministic", sw::tr("Create non-deterministic view and spend keys"), false};
|
const command_line::arg_descriptor<bool> arg_non_deterministic = {"non-deterministic", sw::tr("Create non-deterministic view and spend keys"), false};
|
||||||
const command_line::arg_descriptor<int> arg_daemon_port = {"daemon-port", sw::tr("Use daemon instance at port <arg> instead of 18081"), 0};
|
const command_line::arg_descriptor<int> arg_daemon_port = {"daemon-port", sw::tr("Use daemon instance at port <arg> instead of 18081"), 0};
|
||||||
const command_line::arg_descriptor<uint32_t> arg_log_level = {"log-level", "", LOG_LEVEL_0};
|
const command_line::arg_descriptor<uint32_t> arg_log_level = {"log-level", "", LOG_LEVEL_0};
|
||||||
|
const command_line::arg_descriptor<uint32_t> arg_max_concurrency = {"max-concurrency", "Max number of threads to use for a parallel job", 0};
|
||||||
const command_line::arg_descriptor<std::string> arg_log_file = {"log-file", sw::tr("Specify log file"), ""};
|
const command_line::arg_descriptor<std::string> arg_log_file = {"log-file", sw::tr("Specify log file"), ""};
|
||||||
const command_line::arg_descriptor<bool> arg_testnet = {"testnet", sw::tr("For testnet. Daemon must also be launched with --testnet flag"), false};
|
const command_line::arg_descriptor<bool> arg_testnet = {"testnet", sw::tr("For testnet. Daemon must also be launched with --testnet flag"), false};
|
||||||
const command_line::arg_descriptor<bool> arg_restricted = {"restricted-rpc", sw::tr("Restricts RPC to view-only commands"), false};
|
const command_line::arg_descriptor<bool> arg_restricted = {"restricted-rpc", sw::tr("Restricts RPC to view-only commands"), false};
|
||||||
|
@ -1689,7 +1690,7 @@ bool simple_wallet::start_mining(const std::vector<std::string>& args)
|
||||||
req.miner_address = m_wallet->get_account().get_public_address_str(m_wallet->testnet());
|
req.miner_address = m_wallet->get_account().get_public_address_str(m_wallet->testnet());
|
||||||
|
|
||||||
bool ok = true;
|
bool ok = true;
|
||||||
size_t max_mining_threads_count = (std::max)(boost::thread::hardware_concurrency(), static_cast<unsigned>(2));
|
size_t max_mining_threads_count = (std::max)(tools::get_max_concurrency(), static_cast<unsigned>(2));
|
||||||
if (0 == args.size())
|
if (0 == args.size())
|
||||||
{
|
{
|
||||||
req.threads_count = 1;
|
req.threads_count = 1;
|
||||||
|
@ -3289,6 +3290,7 @@ int main(int argc, char* argv[])
|
||||||
command_line::add_arg(desc_params, arg_daemon_port);
|
command_line::add_arg(desc_params, arg_daemon_port);
|
||||||
command_line::add_arg(desc_params, arg_command);
|
command_line::add_arg(desc_params, arg_command);
|
||||||
command_line::add_arg(desc_params, arg_log_level);
|
command_line::add_arg(desc_params, arg_log_level);
|
||||||
|
command_line::add_arg(desc_params, arg_max_concurrency);
|
||||||
|
|
||||||
bf::path default_log {log_space::log_singletone::get_default_log_folder()};
|
bf::path default_log {log_space::log_singletone::get_default_log_folder()};
|
||||||
std::string log_file_name = log_space::log_singletone::get_default_log_file();
|
std::string log_file_name = log_space::log_singletone::get_default_log_file();
|
||||||
|
@ -3374,6 +3376,9 @@ int main(int argc, char* argv[])
|
||||||
LOG_LEVEL_4
|
LOG_LEVEL_4
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if(command_line::has_arg(vm, arg_max_concurrency))
|
||||||
|
tools::set_max_concurrency(command_line::get_arg(vm, arg_max_concurrency));
|
||||||
|
|
||||||
message_writer(epee::log_space::console_color_white, true) << "Monero '" << MONERO_RELEASE_NAME << "' (v" << MONERO_VERSION_FULL << ")";
|
message_writer(epee::log_space::console_color_white, true) << "Monero '" << MONERO_RELEASE_NAME << "' (v" << MONERO_VERSION_FULL << ")";
|
||||||
|
|
||||||
if(command_line::has_arg(vm, arg_log_level))
|
if(command_line::has_arg(vm, arg_log_level))
|
||||||
|
|
|
@ -213,7 +213,7 @@ void wallet2::process_new_transaction(const cryptonote::transaction& tx, uint64_
|
||||||
|
|
||||||
tx_pub_key = pub_key_field.pub_key;
|
tx_pub_key = pub_key_field.pub_key;
|
||||||
bool r = true;
|
bool r = true;
|
||||||
int threads = boost::thread::hardware_concurrency();
|
int threads = tools::get_max_concurrency();
|
||||||
if (miner_tx && m_refresh_type == RefreshNoCoinbase)
|
if (miner_tx && m_refresh_type == RefreshNoCoinbase)
|
||||||
{
|
{
|
||||||
// assume coinbase isn't for us
|
// assume coinbase isn't for us
|
||||||
|
@ -603,7 +603,7 @@ void wallet2::process_blocks(uint64_t start_height, const std::list<cryptonote::
|
||||||
size_t current_index = start_height;
|
size_t current_index = start_height;
|
||||||
blocks_added = 0;
|
blocks_added = 0;
|
||||||
|
|
||||||
int threads = boost::thread::hardware_concurrency();
|
int threads = tools::get_max_concurrency();
|
||||||
if (threads > 1)
|
if (threads > 1)
|
||||||
{
|
{
|
||||||
std::vector<crypto::hash> round_block_hashes(threads);
|
std::vector<crypto::hash> round_block_hashes(threads);
|
||||||
|
|
Loading…
Reference in a new issue