Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 40 additions & 4 deletions src/modelmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ Status ModelManager::start(const Config& config) {
SPDLOG_LOGGER_ERROR(modelmanager_logger, "Couldn't start model manager");
return status;
}
startWatcher(isStartedWithConfigFile());
evaluatePollingState();
if (resourcesCleanupIntervalMillisec > 0)
startCleaner();

Expand All @@ -212,6 +212,38 @@ void ModelManager::startWatcher(bool watchConfigFile) {
}
}

void ModelManager::evaluatePollingState() {
static const std::set<std::string> singleFileExtensions = {
".xml", ".onnx", ".pdmodel", ".pdiparams", ".pb", ".tflite"};
Comment on lines +216 to +217

versionPollingNeeded = false;
Comment on lines +215 to +219
for (const auto& [name, config] : servedModelConfigs) {
const std::string& basePath = config.getBasePath();
auto ext = std::filesystem::path(basePath).extension().string();
if (singleFileExtensions.count(ext) == 0) {
SPDLOG_LOGGER_TRACE(modelmanager_logger, "Model {} with path {} requires version polling", name, basePath);
versionPollingNeeded = true;
break;
}
}

if (watcherStarted) {
return;
}

bool needWatcher = versionPollingNeeded || isStartedWithConfigFile();
if (needWatcher && watcherIntervalMillisec > 0) {
if (versionPollingNeeded) {
SPDLOG_LOGGER_DEBUG(modelmanager_logger, "Filesystem version polling enabled - at least one model uses version directories");
} else {
SPDLOG_LOGGER_DEBUG(modelmanager_logger, "Filesystem version polling disabled - no model uses version directories");
}
startWatcher(isStartedWithConfigFile());
} else {
SPDLOG_LOGGER_DEBUG(modelmanager_logger, "Filesystem version polling disabled - no model uses version directories");
}
Comment on lines +242 to +244
}

void ModelManager::startCleaner() {
if ((!cleanerStarted)) {
std::future<void> exitSignal = cleanerExitTrigger.get_future();
Expand Down Expand Up @@ -1047,18 +1079,22 @@ Status ModelManager::configFileReloadNeeded(bool& isNeeded) {
void ModelManager::watcher(std::future<void> exitSignal, bool watchConfigFile) {
SPDLOG_LOGGER_INFO(modelmanager_logger, "Started model manager thread");
while (exitSignal.wait_for(std::chrono::milliseconds(this->watcherIntervalMillisec)) == std::future_status::timeout) {
SPDLOG_LOGGER_TRACE(modelmanager_logger, "Models configuration and filesystem check cycle begin");
std::unique_lock<std::recursive_mutex> loadingLock(configMtx);
if (watchConfigFile) {
SPDLOG_LOGGER_TRACE(modelmanager_logger, "Checking if config file changed");
bool isNeeded;
configFileReloadNeeded(isNeeded);
if (isNeeded) {
loadConfig();
evaluatePollingState();
}
Comment on lines 1086 to 1090
}
updateConfigurationWithoutConfigFile();
if (versionPollingNeeded) {
SPDLOG_LOGGER_TRACE(modelmanager_logger, "Models configuration and filesystem check cycle begin");
updateConfigurationWithoutConfigFile();
SPDLOG_LOGGER_TRACE(modelmanager_logger, "Models configuration and filesystem check cycle end");
}
loadingLock.unlock();
SPDLOG_LOGGER_TRACE(modelmanager_logger, "Models configuration and filesystem check cycle end");
}
SPDLOG_LOGGER_INFO(modelmanager_logger, "Stopped model manager thread");
}
Expand Down
7 changes: 7 additions & 0 deletions src/modelmanager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ class ModelManager : public ServableNameChecker, public MetricProvider, public M
private:
bool watcherStarted = false;
bool cleanerStarted = false;
bool versionPollingNeeded = false;

ModelManager(const ModelManager&) = delete;

Expand Down Expand Up @@ -128,6 +129,12 @@ class ModelManager : public ServableNameChecker, public MetricProvider, public M
*/
void watcher(std::future<void> exitSignal, bool watchConfigFile);

/**
* @brief Evaluates whether filesystem version polling is needed
* and starts the watcher thread if at least one model uses version directories
*/
void evaluatePollingState();
Comment on lines +132 to +136

/**
* @brief Cleaner thread for resources cleanup
*/
Expand Down
3 changes: 2 additions & 1 deletion src/test/configs/config_string.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
{"config": {
"name": "passthrough",
"base_path": "/ovms/src/test/passthrough_string",
"shape": "(-1)"}}
"shape": "(-1)",
"target_device": "CPU"}}
]
}