Archived
server: report how long bringup took, as a raw figure
A restart's cost is the one number a reader needs in order to decide whether one is worth suffering, and any guess at it would decide the answer by itself. The server knows it exactly: the interval from process start to the socket listening, on this machine, with this model and this cache state. Emitted on /stats as startup_s, 0 until the server has listened. Raw figure only -- the page no longer consumes it. It is here because it is the missing half of any restart decision a human or a tool makes downstream, and because the decode-step advisory that did consume it was withdrawn the same day it shipped (see the following commit for what the live data showed). Trailing zero-defaulted field on both SchedMetrics structs plus the adapter copy; neither struct is ABI-pinned, so this is the sanctioned append. Authored at: Memoria Qwen 3.8 Flash-Next 125B MoE (xhigh) via Open WebUI (cherry picked from commit 76a9e2f7a28b8e034cfd56caa091792c68fe19b6)
This commit is contained in:
1 parent
ed2da8c9da
commit
d4998b1f75
7 files changed
+53
No files matched your search
@@ -2629,6 +2629,7 @@ int Engine::run_server() {
|
|||||||
|
|
||||||
/* Startup ends here; a quiet server from now on is an idle one. */
|
/* Startup ends here; a quiet server from now on is an idle one. */
|
||||||
startup_watch_.reset();
|
startup_watch_.reset();
|
||||||
|
srv.note_ready(startup_begin_ns_);
|
||||||
const int rc = srv.run();
|
const int rc = srv.run();
|
||||||
/* The watcher tests `watching` first, so clearing it ends the thread without a second stop;
|
/* The watcher tests `watching` first, so clearing it ends the thread without a second stop;
|
||||||
* run() has already torn the transport down. Joining costs up to one sleep interval. */
|
* run() has already torn the transport down. Joining costs up to one sleep interval. */
|
||||||
|
|||||||
@@ -98,6 +98,9 @@ private:
|
|||||||
/* serve()'s startup stall watch, released when the server listens (run_server) or the KL
|
/* serve()'s startup stall watch, released when the server listens (run_server) or the KL
|
||||||
* mode starts (run_kld). */
|
* mode starts (run_kld). */
|
||||||
std::unique_ptr<StallWatch> startup_watch_;
|
std::unique_ptr<StallWatch> startup_watch_;
|
||||||
|
/* rad_mono_ns at the top of start(), so serve() can report how long bringup took. The same
|
||||||
|
* span the startup watch covers (main.cpp creates it here and ends it at the listen). */
|
||||||
|
uint64_t startup_begin_ns_ = 0;
|
||||||
std::vector<std::thread> rank_threads_;
|
std::vector<std::thread> rank_threads_;
|
||||||
|
|
||||||
Config cfg_;
|
Config cfg_;
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
* Separate from engine.cpp (the hot step loop), with which it shares only the Engine's fields.
|
* Separate from engine.cpp (the hot step loop), with which it shares only the Engine's fields.
|
||||||
*/
|
*/
|
||||||
#include "engine_priv.h"
|
#include "engine_priv.h"
|
||||||
|
#include "rad_internal.h"
|
||||||
#include "engine_hostmem.h"
|
#include "engine_hostmem.h"
|
||||||
#include "gen/driver.h"
|
#include "gen/driver.h"
|
||||||
#include "gen/audio_driver.h"
|
#include "gen/audio_driver.h"
|
||||||
@@ -3124,6 +3125,7 @@ int Engine::configure_kv() {
|
|||||||
|
|
||||||
/* ================================================================== start */
|
/* ================================================================== start */
|
||||||
int Engine::start() {
|
int Engine::start() {
|
||||||
|
startup_begin_ns_ = rad_mono_ns();
|
||||||
std::vector<int> devs;
|
std::vector<int> devs;
|
||||||
std::string inventory;
|
std::string inventory;
|
||||||
std::string devnote;
|
std::string devnote;
|
||||||
|
|||||||
@@ -125,6 +125,9 @@ HttpResponse Server::handle_stats(const HttpRequest&) {
|
|||||||
o["model"] = opt_.model_id;
|
o["model"] = opt_.model_id;
|
||||||
o["version"] = opt_.version;
|
o["version"] = opt_.version;
|
||||||
o["uptime_s"] = unix_now() - started_at_;
|
o["uptime_s"] = unix_now() - started_at_;
|
||||||
|
/* How long this process took to come up, measured on this machine: the price of a restart,
|
||||||
|
* which the page needs to say whether a restart pays back. 0 before the server listens. */
|
||||||
|
o["startup_s"] = startup_s_;
|
||||||
o["in_flight"] = in_flight_.load(std::memory_order_relaxed);
|
o["in_flight"] = in_flight_.load(std::memory_order_relaxed);
|
||||||
o["queue_cap"] = queue_depth_;
|
o["queue_cap"] = queue_depth_;
|
||||||
o["now_ms"] = (int64_t)std::time(nullptr) * 1000;
|
o["now_ms"] = (int64_t)std::time(nullptr) * 1000;
|
||||||
|
|||||||
@@ -207,6 +207,16 @@ void Server::register_routes() {
|
|||||||
* number bounds the connections that may wait once the reserve is busy too. */
|
* number bounds the connections that may wait once the reserve is busy too. */
|
||||||
static const int64_t kSpareWorkers = 64;
|
static const int64_t kSpareWorkers = 64;
|
||||||
|
|
||||||
|
void Server::note_ready(uint64_t begin_ns) {
|
||||||
|
if (begin_ns == 0) return;
|
||||||
|
const uint64_t now = rad_mono_ns();
|
||||||
|
/* Only a start in the past is a duration. A stamp that arrives out of order is ignored rather
|
||||||
|
* than written as zero: the page divides by this figure, and a zero cost would price every
|
||||||
|
* restart as free. */
|
||||||
|
if (now <= begin_ns) return;
|
||||||
|
startup_s_ = (int64_t)((now - begin_ns) / 1000000000ull);
|
||||||
|
}
|
||||||
|
|
||||||
int Server::run() {
|
int Server::run() {
|
||||||
TransportOptions t;
|
TransportOptions t;
|
||||||
t.host = opt_.host;
|
t.host = opt_.host;
|
||||||
|
|||||||
@@ -191,6 +191,12 @@ public:
|
|||||||
/* The admission ceiling as resolved: ServerOptions::queue_depth, or 8 x max_seqs for 0. */
|
/* The admission ceiling as resolved: ServerOptions::queue_depth, or 8 x max_seqs for 0. */
|
||||||
int64_t queue_cap() const { return queue_depth_; }
|
int64_t queue_cap() const { return queue_depth_; }
|
||||||
|
|
||||||
|
/* Records how long bringup took, called by Engine::serve just before it starts listening
|
||||||
|
* (the same moment the startup watch ends). `begin_ns` is rad_mono_ns from the top of
|
||||||
|
* Engine::start(); 0 leaves the figure unset. run() blocks serving forever, so the value is
|
||||||
|
* handed in rather than taken inside it. */
|
||||||
|
void note_ready(uint64_t begin_ns);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct Generation;
|
struct Generation;
|
||||||
struct TranscriptionJob; /* speech.cpp */
|
struct TranscriptionJob; /* speech.cpp */
|
||||||
@@ -351,6 +357,9 @@ private:
|
|||||||
std::atomic<int64_t> speech_sessions_{0};
|
std::atomic<int64_t> speech_sessions_{0};
|
||||||
std::atomic<bool> stopping_{false};
|
std::atomic<bool> stopping_{false};
|
||||||
int64_t started_at_ = 0;
|
int64_t started_at_ = 0;
|
||||||
|
/* Seconds from the top of Engine::start() to the moment the server began listening -- the
|
||||||
|
* cost of a restart, measured on this machine rather than guessed. 0 until note_ready(). */
|
||||||
|
int64_t startup_s_ = 0;
|
||||||
|
|
||||||
/* Sinks whose HTTP side is gone but whose engine side may still be mid-step. Held until the
|
/* Sinks whose HTTP side is gone but whose engine side may still be mid-step. Held until the
|
||||||
* scheduler reports the request terminal, because Request::sink is a raw pointer and freeing
|
* scheduler reports the request terminal, because Request::sink is a raw pointer and freeing
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
* groups, where summing or picking the wrong group goes wrong silently.
|
* groups, where summing or picking the wrong group goes wrong silently.
|
||||||
*/
|
*/
|
||||||
#include "server_fakes.h"
|
#include "server_fakes.h"
|
||||||
|
#include "rad_internal.h" /* rad_mono_ns: a synthetic bringup start */
|
||||||
|
|
||||||
#include <set>
|
#include <set>
|
||||||
|
|
||||||
@@ -246,6 +247,30 @@ TEST(sessions_lists_each_conversation_and_what_the_tiers_did) {
|
|||||||
/* Every field the page's script reads from /stats (in its update and the request table) and from
|
/* Every field the page's script reads from /stats (in its update and the request table) and from
|
||||||
* /sessions (its loader and the session rows) is one the routes emit for a populated engine. A
|
* /sessions (its loader and the session rows) is one the routes emit for a populated engine. A
|
||||||
* rename on either side otherwise blanks a panel and reports nothing. */
|
* rename on either side otherwise blanks a panel and reports nothing. */
|
||||||
|
/* The price of a restart, measured rather than guessed: whatever decides whether a restart is
|
||||||
|
* worth suffering needs this figure, and a guessed cost would decide the answer by itself. The
|
||||||
|
* page stopped consuming it on 2026-10-18, when the payback clause it fed was withdrawn -- the
|
||||||
|
* field stays because it is the missing half of that decision made downstream, by a human or a
|
||||||
|
* tool. A test runs in microseconds, so a real note_ready() would compute 0 -- indistinguishable
|
||||||
|
* from "never called". Passing a synthetic start exercises the arithmetic through the real route. */
|
||||||
|
TEST(stats_reports_how_long_bringup_took_once_the_server_listens) {
|
||||||
|
Dash d(false);
|
||||||
|
/* Before the server has listened, there is no measured cost to report. */
|
||||||
|
CHECK_EQ(d.get("/stats").value("startup_s", (int64_t)-1), (int64_t)0);
|
||||||
|
|
||||||
|
d.srv->note_ready(rad_mono_ns() - 47ull * 1000000000ull);
|
||||||
|
CHECK_EQ(d.get("/stats").value("startup_s", (int64_t)-1), (int64_t)47);
|
||||||
|
|
||||||
|
/* A start in the future is not a negative cost: the figure is a duration, and a page that
|
||||||
|
* divided by it would otherwise be handed a sign flip. */
|
||||||
|
d.srv->note_ready(rad_mono_ns() + 10ull * 1000000000ull);
|
||||||
|
CHECK_EQ(d.get("/stats").value("startup_s", (int64_t)-1), (int64_t)47);
|
||||||
|
|
||||||
|
/* 0 means "not yet", so it must not overwrite a measured figure. */
|
||||||
|
d.srv->note_ready(0);
|
||||||
|
CHECK_EQ(d.get("/stats").value("startup_s", (int64_t)-1), (int64_t)47);
|
||||||
|
}
|
||||||
|
|
||||||
TEST(every_field_the_page_reads_is_one_the_routes_emit) {
|
TEST(every_field_the_page_reads_is_one_the_routes_emit) {
|
||||||
Dash d(false);
|
Dash d(false);
|
||||||
HttpResponse page = d.srv->router().call("GET", "/");
|
HttpResponse page = d.srv->router().call("GET", "/");
|
||||||
|
|||||||
Reference in new issue
Block a user