调整公共线程池线程数可配

This commit is contained in:
fasiondog 2024-08-30 01:27:51 +08:00
parent cae2add39e
commit 6c3fd9f0d1
5 changed files with 49 additions and 15 deletions

View File

@ -480,6 +480,7 @@ void StockManager::loadAllHolidays() {
}
void StockManager::loadAllStockWeights() {
HKU_IF_RETURN(!m_hikyuuParam.tryGet<bool>("load_stock_weight", true), void());
HKU_INFO("Loading stock weight...");
if (m_context.isAll()) {
auto all_stkweight_dict = m_baseInfoDriver->getAllStockWeightList();
@ -511,12 +512,14 @@ void StockManager::loadAllZhBond10() {
}
void StockManager::loadHistoryFinanceField() {
if (m_hikyuuParam.tryGet<bool>("load_history_finance", true)) {
auto fields = m_baseInfoDriver->getHistoryFinanceField();
for (const auto& field : fields) {
m_field_ix_to_name[field.first - 1] = field.second;
m_field_name_to_ix[field.second] = field.first - 1;
}
}
}
vector<std::pair<size_t, string>> StockManager::getHistoryFinanceAllFields() const {
vector<std::pair<size_t, string>> ret;
@ -531,11 +534,13 @@ vector<std::pair<size_t, string>> StockManager::getHistoryFinanceAllFields() con
}
void StockManager::loadHistoryFinance() {
if (m_hikyuuParam.tryGet<bool>("load_history_finance", true)) {
auto* tg = getGlobalTaskGroup();
std::lock_guard<std::mutex> lock1(*m_stockDict_mutex);
for (auto iter = m_stockDict.begin(); iter != m_stockDict.end(); ++iter) {
tg->submit([=]() { iter->second.getHistoryFinance(); });
}
}
}
} // namespace hku

View File

@ -10,6 +10,7 @@
#include "hikyuu/GlobalInitializer.h"
#include "hikyuu/utilities/Log.h"
#include "GlobalTaskGroup.h"
#include "hikyuu/StockManager.h"
namespace hku {
@ -18,13 +19,17 @@ static TaskGroup* g_threadPool;
TaskGroup* getGlobalTaskGroup() {
static std::once_flag oc;
std::call_once(oc, [&]() {
auto cpu_num = std::thread::hardware_concurrency();
if (cpu_num >= 4) {
cpu_num -= 2;
} else if (cpu_num > 1) {
cpu_num--;
}
g_threadPool = new TaskGroup(cpu_num);
// auto cpu_num = std::thread::hardware_concurrency();
// if (cpu_num >= 4) {
// cpu_num -= 2;
// } else if (cpu_num > 1) {
// cpu_num--;
// }
const auto& param = StockManager::instance().getHikyuuParameter();
size_t worker_num =
param.tryGet<int>("commont_thread_pool_num", std::thread::hardware_concurrency());
HKU_INFO("work_num: {}", worker_num);
g_threadPool = new TaskGroup(worker_num);
});
return g_threadPool;
}

View File

@ -46,6 +46,20 @@ void HKU_API getConfigFromIni(const string& config_file_name, Parameter& basePar
hkuParam.set<string>("datadir", config.get("hikyuu", "datadir", "."));
hkuParam.set<string>("quotation_server",
config.get("hikyuu", "quotation_server", "ipc:///tmp/hikyuu_real.ipc"));
// 加载权息数据
hkuParam.set<bool>("load_stock_weight", config.getBool("hikyuu", "load_stock_weight", "True"));
// 加载历史财务数据
hkuParam.set<bool>("load_history_finance",
config.getBool("hikyuu", "load_history_finance", "True"));
// 公共线程池线程数量
size_t cpu_num = 2 * std::thread::hardware_concurrency();
if (cpu_num > 30) {
cpu_num = 30;
}
hkuParam.set<int>("commont_thread_pool_num", config.getInt("hikyuu", "commont_thread_pool_num",
fmt::format("{}", cpu_num)));
IniParser::StringListPtr option = config.getOptionList("baseinfo");
for (auto iter = option->begin(); iter != option->end(); ++iter) {

View File

@ -35,6 +35,15 @@ namespace hku {
void HKU_API hikyuu_init(const string& config_file_name, bool ignore_preload = false,
const StrategyContext& context = StrategyContext({"all"}));
/**
* @brief ini
* @param config_file_name ini
* @param baseParam [out]
* @param blockParam [out]
* @param kdataParam [out]
* @param preloadParam [out]
* @param hkuParam [out]
*/
void HKU_API getConfigFromIni(const string& config_file_name, Parameter& baseParam,
Parameter& blockParam, Parameter& kdataParam, Parameter& preloadParam,
Parameter& hkuParam);

View File

@ -28,6 +28,7 @@ namespace hku {
*/
class HKU_API Strategy {
CLASS_LOGGER_IMP(Strategy)
PARAMETER_SUPPORT
public:
Strategy();