Archived
server: DELETE /sessions forgets one stored conversation
A client that deleted a conversation, or compacted it past a prefix, knows the
rest is dead before --prefix-cache-ttl does. DELETE /sessions/<label> (or
?label=, ?id=<engine id>) walks the session's chain from the tip inwards like
expiry: VRAM blocks to the pool, the host copy with them, the session's
snapshots to the store. ?keep_tokens=N keeps the chain's start in whole blocks.
Blocks another stored session shares (the system prompt) and blocks a live
request reads stay and are counted apart; the row is cut at the deepest block
that stayed, so a later release reaches it. A request of the same conversation
in flight is 409. IScheduler::release_session beside reset_prefix_cache,
PrefixCache::release_session over the tiers' session table (find_sessions,
shared_prefix_blocks, cut_session). Counters released{entries,snapshots} on
/sessions and /stats, prefix_cache_released_total{what} on /metrics.
This commit is contained in:
1 parent
123c439684
commit
3aded1bbf8
20 files changed
+722
-2
No files matched your search
@@ -107,6 +107,8 @@ inline SchedMetrics bridge_metrics(const rad::SchedMetrics& m) {
|
||||
o.hit_cut_tokens = m.hit_cut_tokens;
|
||||
o.prefix_expired = m.prefix_expired;
|
||||
o.prefix_ckpt_expired = m.prefix_ckpt_expired;
|
||||
o.prefix_released = m.prefix_released;
|
||||
o.prefix_ckpt_released = m.prefix_ckpt_released;
|
||||
|
||||
o.prefill_tps = m.prefill_tps;
|
||||
o.decode_tps = m.decode_tps;
|
||||
@@ -202,6 +204,24 @@ public:
|
||||
|
||||
int64_t reset_prefix_cache() override { return s_->reset_prefix_cache(); }
|
||||
|
||||
int release_session(const std::string& label, uint64_t id, int64_t keep_tokens,
|
||||
SessionReleased* out) override {
|
||||
SessionRelease r;
|
||||
const int rc = s_->release_session(label, id, keep_tokens, &r);
|
||||
if (out) {
|
||||
out->sessions = r.sessions;
|
||||
out->entries = r.entries;
|
||||
out->tokens = r.tokens;
|
||||
out->device_bytes = r.device_bytes;
|
||||
out->host_bytes = r.host_bytes;
|
||||
out->snapshots = r.snapshots;
|
||||
out->kept_tokens = r.kept_tokens;
|
||||
out->kept_shared = r.kept_shared;
|
||||
out->kept_live = r.kept_live;
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
/* The stored conversations. The tiers keep monotonic timestamps; idle and age are converted
|
||||
* to "seconds ago" here, so only the monotonic clock is authoritative. */
|
||||
TierCounters tier_counters() const override {
|
||||
|
||||
@@ -138,6 +138,8 @@ HttpResponse Server::handle_sessions(const HttpRequest&) {
|
||||
o["snapshot_store"] = { { "bytes_each", c.ck_bytes }, { "slots", c.ck_slots } };
|
||||
/* Entries and snapshots removed by --prefix-cache-ttl, from whichever tier held them. */
|
||||
o["expired"] = { { "entries", sm.prefix_expired }, { "snapshots", sm.prefix_ckpt_expired } };
|
||||
/* And the ones a client gave up on purpose (DELETE /sessions). */
|
||||
o["released"] = { { "entries", sm.prefix_released }, { "snapshots", sm.prefix_ckpt_released } };
|
||||
/* Step-thread time spent on tier moves; every request waits through it. */
|
||||
o["stall"] = { { "restores", c.restores }, { "restore_ms", (double)c.restore_ns / 1e6 },
|
||||
{ "flushes", c.flushes }, { "flush_ms", (double)c.flush_ns / 1e6 } };
|
||||
@@ -167,6 +169,83 @@ HttpResponse Server::handle_sessions(const HttpRequest&) {
|
||||
return HttpResponse::json_body(200, json_dump(o));
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------ DELETE /sessions
|
||||
*
|
||||
* A client that deletes a conversation, or replaces everything past a prefix of it, knows the
|
||||
* rest is dead before the TTL does. Named by the label it sent (`session_id`, or Anthropic's
|
||||
* `metadata.user_id`), or by the engine id `/sessions` shows. `keep_tokens` keeps the chain's
|
||||
* start. Shared blocks and blocks a live request reads stay; a request of the same conversation
|
||||
* in flight is a 409, since its close would publish the chain again. */
|
||||
HttpResponse Server::handle_session_release(const HttpRequest& req) {
|
||||
if (!deps_.sched)
|
||||
return error_response(err_not_implemented("the server has no engine attached"), req.peer);
|
||||
|
||||
const std::string label = req.param("label");
|
||||
uint64_t id = 0;
|
||||
const std::string id_s = req.param("id");
|
||||
if (!id_s.empty()) {
|
||||
if (id_s.find_first_not_of("0123456789") != std::string::npos || id_s.size() > 19)
|
||||
return error_response(err_bad("id", "expected the session's engine id, a decimal "
|
||||
"integer as /sessions reports it"), req.peer);
|
||||
id = std::stoull(id_s);
|
||||
if (id == 0) return error_response(err_bad("id", "0 names no session"), req.peer);
|
||||
}
|
||||
if (label.empty() && id == 0)
|
||||
return error_response(err_bad("label", "name the session: DELETE /sessions/<label>, "
|
||||
"?label=<label> or ?id=<engine id>"), req.peer);
|
||||
int64_t keep_tokens = 0;
|
||||
const std::string keep_s = req.param("keep_tokens");
|
||||
if (!keep_s.empty()) {
|
||||
if (keep_s.find_first_not_of("0123456789") != std::string::npos || keep_s.size() > 12)
|
||||
return error_response(err_bad("keep_tokens", "expected a non-negative integer: the "
|
||||
"prefix to keep, in tokens"), req.peer);
|
||||
keep_tokens = std::stoll(keep_s);
|
||||
}
|
||||
|
||||
SessionReleased r;
|
||||
const int rc = deps_.sched->release_session(label, id, keep_tokens, &r);
|
||||
if (rc == RAD_E_UNSUPPORTED)
|
||||
return error_response(err_not_implemented(
|
||||
"this engine has no prefix cache (started with --no-prefix-cache, or the model "
|
||||
"declares no cacheable KV group)"), req.peer);
|
||||
const std::string who = label.empty() ? "id " + std::to_string(id) : "'" + label + "'";
|
||||
if (rc == RAD_E_NOTFOUND) {
|
||||
ApiError e;
|
||||
e.status = 404;
|
||||
e.type = "not_found_error";
|
||||
e.param = label.empty() ? "id" : "label";
|
||||
e.message = "no stored session " + who + "; GET /sessions lists them";
|
||||
return error_response(e, req.peer);
|
||||
}
|
||||
if (rc == RAD_E_STATE) {
|
||||
ApiError e;
|
||||
e.status = 409;
|
||||
e.type = "conflict_error";
|
||||
e.code = "session_in_use";
|
||||
e.message = "a request of session " + who + " is queued or running; cancel it or wait "
|
||||
"for it to finish, then release again";
|
||||
return error_response(e, req.peer);
|
||||
}
|
||||
if (rc == RAD_E_INVAL)
|
||||
return error_response(err_bad("keep_tokens", rad_strerror(rc)), req.peer);
|
||||
if (rc < 0) return error_response(err_internal(rad_strerror(rc)), req.peer);
|
||||
|
||||
json o;
|
||||
if (!label.empty()) o["label"] = label;
|
||||
if (id != 0) o["id"] = id;
|
||||
o["keep_tokens"] = keep_tokens;
|
||||
o["sessions"] = r.sessions;
|
||||
o["entries"] = r.entries;
|
||||
o["tokens"] = r.tokens;
|
||||
o["device_bytes"] = r.device_bytes;
|
||||
o["host_bytes"] = r.host_bytes;
|
||||
o["snapshots"] = r.snapshots;
|
||||
o["kept"] = { { "tokens", r.kept_tokens }, { "shared", r.kept_shared },
|
||||
{ "live", r.kept_live } };
|
||||
metrics_.observe_http(200);
|
||||
return HttpResponse::json_body(200, json_dump(o));
|
||||
}
|
||||
|
||||
HttpResponse Server::handle_stats(const HttpRequest&) {
|
||||
json o;
|
||||
o["model"] = opt_.model_id;
|
||||
@@ -222,6 +301,8 @@ HttpResponse Server::handle_stats(const HttpRequest&) {
|
||||
o["ckpt_evictions"] = { { "retention", m.prefix_ckpt_retired },
|
||||
{ "store_full", m.prefix_ckpt_lru } };
|
||||
o["ckpt_refused"] = m.prefix_ckpt_refused;
|
||||
o["released"] = { { "entries", m.prefix_released },
|
||||
{ "snapshots", m.prefix_ckpt_released } };
|
||||
o["hit_cuts"] = { { "no_snapshot", m.hit_cut_no_snapshot },
|
||||
{ "windowed_group", m.hit_cut_window },
|
||||
{ "adopt_failed", m.hit_cut_adopt },
|
||||
|
||||
@@ -78,6 +78,7 @@ struct SchedMetrics {
|
||||
int64_t prefix_restore_cuts = 0;
|
||||
/* Removed by --prefix-cache-ttl, cumulative. Not evictions: nothing wanted the memory. */
|
||||
int64_t prefix_expired = 0, prefix_ckpt_expired = 0;
|
||||
int64_t prefix_released = 0, prefix_ckpt_released = 0;
|
||||
/* Decoupled prefix caching (spec §7.3). `prefix_hit_rate` is the attention hit rate, as in
|
||||
* vLLM. The linear side hits at a different granularity (whole checkpoints, not blocks), so
|
||||
* it is reported separately, with token counts and checkpoints written. */
|
||||
@@ -168,6 +169,17 @@ struct SessionOccupancy {
|
||||
int64_t host_cap_bytes = 0;
|
||||
};
|
||||
|
||||
/* What a release took out of the store and what it left (PrefixCache::release_session). The
|
||||
* kept counts are apart on purpose: `shared` blocks belong to another stored conversation too,
|
||||
* `live` ones to a request still reading them. */
|
||||
struct SessionReleased {
|
||||
int64_t sessions = 0;
|
||||
int64_t entries = 0, tokens = 0;
|
||||
int64_t device_bytes = 0, host_bytes = 0;
|
||||
int64_t snapshots = 0;
|
||||
int64_t kept_tokens = 0, kept_shared = 0, kept_live = 0;
|
||||
};
|
||||
|
||||
/* One in-flight request, for the live request table: shows which request is stuck, e.g. one
|
||||
* waiting on a prompt that will never fit, which no aggregate metric reveals. */
|
||||
struct RequestStat {
|
||||
@@ -225,6 +237,15 @@ public:
|
||||
* allocated), but it takes the scheduler's lock because a step may be inserting into the map. */
|
||||
virtual int64_t reset_prefix_cache() { return RAD_E_UNSUPPORTED; }
|
||||
|
||||
/* Forgets one stored conversation (DELETE /sessions): every row carrying `label`, or with
|
||||
* `id` nonzero the row of that engine id; `keep_tokens` leaves the chain's start standing.
|
||||
* RAD_E_NOTFOUND when nothing matches (404), RAD_E_STATE while a request of that
|
||||
* conversation is queued or running (409), RAD_E_UNSUPPORTED without a prefix cache (501). */
|
||||
virtual int release_session(const std::string& /*label*/, uint64_t /*id*/,
|
||||
int64_t /*keep_tokens*/, SessionReleased* /*out*/) {
|
||||
return RAD_E_UNSUPPORTED;
|
||||
}
|
||||
|
||||
/* The live request table, oldest first; returns the count. Default: none kept. */
|
||||
virtual int requests(std::vector<RequestStat>* /*out*/) const { return 0; }
|
||||
|
||||
|
||||
@@ -190,6 +190,8 @@ void Metrics::sample(const SchedMetrics& m) {
|
||||
c_prefix_ckpt_evict_.advance_to(m.prefix_ckpt_evictions);
|
||||
c_prefix_expired_.advance_to(m.prefix_expired);
|
||||
c_prefix_ckpt_expired_.advance_to(m.prefix_ckpt_expired);
|
||||
c_prefix_released_.advance_to(m.prefix_released);
|
||||
c_prefix_ckpt_released_.advance_to(m.prefix_ckpt_released);
|
||||
c_ckpt_retired_.advance_to(m.prefix_ckpt_retired);
|
||||
c_ckpt_lru_.advance_to(m.prefix_ckpt_lru);
|
||||
c_ckpt_refused_.advance_to(m.prefix_ckpt_refused);
|
||||
@@ -447,6 +449,13 @@ std::string Metrics::render() const {
|
||||
c_ckpt_retired_.get());
|
||||
labelled("radiance:prefix_cache_ckpt_evictions_by_reason_total", "reason", "store_full",
|
||||
c_ckpt_lru_.get());
|
||||
w.help("radiance:prefix_cache_released_total",
|
||||
"Prefix-cache entries and linear-state snapshots a client released on purpose "
|
||||
"(DELETE /sessions).", "counter");
|
||||
labelled("radiance:prefix_cache_released_total", "what", "entries",
|
||||
c_prefix_released_.get());
|
||||
labelled("radiance:prefix_cache_released_total", "what", "snapshots",
|
||||
c_prefix_ckpt_released_.get());
|
||||
w.counter("radiance:prefix_cache_ckpt_refused_total",
|
||||
"Checkpoints not written because every snapshot slot was in use by a restore "
|
||||
"in the same step.", L, c_ckpt_refused_.get());
|
||||
|
||||
@@ -152,6 +152,7 @@ private:
|
||||
Counter c_attn_cached_, c_linear_cached_, c_checkpoints_;
|
||||
Counter c_prefix_evict_, c_prefix_ckpt_evict_;
|
||||
Counter c_prefix_expired_, c_prefix_ckpt_expired_;
|
||||
Counter c_prefix_released_, c_prefix_ckpt_released_;
|
||||
Counter c_ckpt_retired_, c_ckpt_lru_, c_ckpt_refused_;
|
||||
Counter c_cut_no_snapshot_, c_cut_window_, c_cut_adopt_, c_cut_resumed_below_, c_cut_tokens_;
|
||||
Counter c_restore_cuts_;
|
||||
|
||||
@@ -210,6 +210,12 @@ void Server::register_routes() {
|
||||
[this](const HttpRequest& q) { return handle_control_vector(q); });
|
||||
router_.post("/admin/control-vector",
|
||||
[this](const HttpRequest& q) { return handle_control_vector(q); });
|
||||
/* Forget one stored conversation: by its client label in the path (or `?label=`, for a
|
||||
* label the path cannot carry), or by engine id with `?id=`. */
|
||||
router_.add ("DELETE", "/sessions/:label",
|
||||
[this](const HttpRequest& q) { return handle_session_release(q); });
|
||||
router_.add ("DELETE", "/sessions",
|
||||
[this](const HttpRequest& q) { return handle_session_release(q); });
|
||||
}
|
||||
|
||||
/* Workers beyond the admission ceiling. A generation holds its connection's worker for its whole
|
||||
|
||||
@@ -329,6 +329,7 @@ private:
|
||||
* {"enabled": bool} sets the default for requests that name no choice. Guarded by the API key
|
||||
* like every other route but the health probes and the page. */
|
||||
HttpResponse handle_control_vector(const HttpRequest& req);
|
||||
HttpResponse handle_session_release(const HttpRequest& req);
|
||||
|
||||
HttpResponse error_response(const ApiError& e, const std::string& peer,
|
||||
ApiShape shape = ApiShape::OpenAI);
|
||||
|
||||
Reference in new issue
Block a user