Skip to content

Commit

Permalink
Server shutdown must wait for background models
Browse files Browse the repository at this point in the history
  • Loading branch information
kthui committed Jan 26, 2024
1 parent 6e91ff3 commit edd64b5
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/model_repository_manager/model_lifecycle.cc
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,14 @@ ModelLifeCycle::InflightStatus()
return inflight_status;
}

size_t
ModelLifeCycle::BackgroundModelsSize()
{
LOG_VERBOSE(2) << "BackgroundModelsSize()";
std::lock_guard<std::mutex> map_lock(map_mtx_);
return background_models_.size();
}

const ModelStateMap
ModelLifeCycle::ModelStates()
{
Expand Down
3 changes: 3 additions & 0 deletions src/model_repository_manager/model_lifecycle.h
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,9 @@ class ModelLifeCycle {
// that don't have in-flight inferences will not be included.
const std::set<std::tuple<ModelIdentifier, int64_t, size_t>> InflightStatus();

// Return the number of model(s) in the background.
size_t BackgroundModelsSize();

private:
struct ModelInfo {
ModelInfo(
Expand Down
6 changes: 6 additions & 0 deletions src/model_repository_manager/model_repository_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -981,6 +981,12 @@ ModelRepositoryManager::InflightStatus()
return model_life_cycle_->InflightStatus();
}

size_t
ModelRepositoryManager::BackgroundModelsSize()
{
return model_life_cycle_->BackgroundModelsSize();
}

const ModelStateMap
ModelRepositoryManager::LiveModelStates(bool strict_readiness)
{
Expand Down
3 changes: 3 additions & 0 deletions src/model_repository_manager/model_repository_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,9 @@ class ModelRepositoryManager {
/// if it doesn't have in-flight inferences.
const std::set<std::tuple<ModelIdentifier, int64_t, size_t>> InflightStatus();

/// \return the number of model(s) in the background.
size_t BackgroundModelsSize();

/// \param strict_readiness If true, only models that have at least one
/// ready version will be considered as live. Otherwise, the models that
/// have loading / unloading versions will also be live.
Expand Down
4 changes: 3 additions & 1 deletion src/server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,7 @@ InferenceServer::Stop(const bool force)
}
} else {
const auto& live_models = model_repository_manager_->LiveModelStates();
size_t bg_models_size = model_repository_manager_->BackgroundModelsSize();

LOG_INFO << "Timeout " << exit_timeout_iters << ": Found "
<< live_models.size() << " live models and "
Expand All @@ -355,7 +356,8 @@ InferenceServer::Stop(const bool force)
}
}

if ((live_models.size() == 0) && (inflight_request_counter_ == 0)) {
if ((live_models.size() == 0) && (bg_models_size == 0) &&
(inflight_request_counter_ == 0)) {
return Status::Success;
}
}
Expand Down

0 comments on commit edd64b5

Please sign in to comment.