| 227 | response.stream_body = [threads, inner = std::move(inner)](HttpStreamWriter & writer) { |
| 228 | const ScopedOmpNumThreads stream_omp_threads(threads); |
| 229 | inner(writer); |
| 230 | }; |
| 231 | } |
| 232 | return response; |
| 233 | } |
| 234 | |
| 235 | HttpResponse ServerState::handle_health() const { |
| 236 | size_t model_count = 0; |
| 237 | { |
| 238 | std::lock_guard<std::mutex> lock(models_mutex_); |
| 239 | model_count = models_.size(); |
| 240 | } |
| 241 | return json_response( |
| 242 | "{\"status\":\"ok\",\"backend\":\"" + std::string(backend_name(config_.backend)) + |
| 243 | "\",\"models\":" + std::to_string(model_count) + |
| 244 | ",\"ui\":" + (config_.ui_enabled ? "true" : "false") + |
| 245 | ",\"ui_management\":" + (config_.ui_management ? "true" : "false") + |
| 246 | ",\"version\":" + json_quote(minitts::app::build_version()) + |
| 247 | ",\"git\":" + json_quote(minitts::app::build_git_sha()) + |
| 248 | ",\"git_date\":" + json_quote(minitts::app::build_git_date()) + "}"); |
| 249 | } |
| 250 | |
| 251 | void ServerState::load_models() { |
| 252 | int eager_loaded = 0; |
| 253 | for (auto & config : config_.models) { |
| 254 | configured_models_.emplace(config.id, config); |
| 255 | auto loaded = make_model(std::move(config)); |
| 256 | if (!model_index_.emplace(loaded->config.id, models_.size()).second) { |
| 257 | throw std::runtime_error("duplicate server model id: " + loaded->config.id); |
| 258 | } |
| 259 | if (!loaded->config.lazy) { |
| 260 | if (config_.max_loaded_models > 0 && eager_loaded >= config_.max_loaded_models) { |
| 261 | // Loading it now would immediately evict an earlier entry, so an |
| 262 | // over-limit config would churn through doomed loads at startup. |
| 263 | // Register the id and defer the load to the model's first request. |
| 264 | std::cerr << "model '" << loaded->config.id |
| 265 | << "' registered but not loaded (max_loaded_models=" |
| 266 | << config_.max_loaded_models << " reached); it loads on first use\n"; |
| 267 | } else { |
| 268 | ensure_model_loaded_locked(*loaded); |
| 269 | ++eager_loaded; |
| 270 | // Models-completed boundary for trace-log consumers driving a |
| 271 | // load progress bar: one step per resident model. The final |
| 272 | // 1.0 is emitted once below. Opt-in (--load-progress 1). |
| 273 | if (engine::core::load_progress_enabled() && |
| 274 | eager_loaded < static_cast<int>(config_.models.size())) { |
| 275 | engine::debug::trace_log_scalar( |
| 276 | "server.load.progress", |
| 277 | static_cast<double>(eager_loaded) / static_cast<double>(config_.models.size())); |
| 278 | } |
| 279 | } |
| 280 | } |
| 281 | models_.push_back(std::move(loaded)); |
| 282 | } |
| 283 | if (engine::core::load_progress_enabled() && |
| 284 | !config_.models.empty() && eager_loaded == static_cast<int>(config_.models.size())) { |
| 285 | // Every configured model is resident and the listening banner follows |
| 286 | // immediately: complete the models-completed curve at 1.0. |
no test coverage detected