mirror of
https://gitee.com/fasiondog/hikyuu.git
synced 2024-12-02 03:48:19 +08:00
调整公共线程池线程数可配
This commit is contained in:
parent
cae2add39e
commit
6c3fd9f0d1
@ -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,10 +512,12 @@ void StockManager::loadAllZhBond10() {
|
||||
}
|
||||
|
||||
void StockManager::loadHistoryFinanceField() {
|
||||
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;
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -531,10 +534,12 @@ vector<std::pair<size_t, string>> StockManager::getHistoryFinanceAllFields() con
|
||||
}
|
||||
|
||||
void StockManager::loadHistoryFinance() {
|
||||
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(); });
|
||||
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(); });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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) {
|
||||
|
@ -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);
|
||||
|
@ -28,6 +28,7 @@ namespace hku {
|
||||
*/
|
||||
class HKU_API Strategy {
|
||||
CLASS_LOGGER_IMP(Strategy)
|
||||
PARAMETER_SUPPORT
|
||||
|
||||
public:
|
||||
Strategy();
|
||||
|
Loading…
Reference in New Issue
Block a user