Triton Inference Server 统计扩展(Statistics Extension)协议深度解析:HTTP/REST 与 gRPC 接口全解

发布时间:2026/11/26 19:49:39

Triton Inference Server 统计扩展(Statistics Extension)协议深度解析:HTTP/REST 与 gRPC 接口全解 模型推理服务AI 应用后端【免费下载链接】serverThe Triton Inference Server provides an optimized cloud and edge inferencing solution.项目地址https://gitcode.com/gh_mirrors/server117/server点击查看免费下载Triton Inference Server 的统计扩展Statistics Extension用于报告每个模型按版本区分从服务器启动以来的累计活动统计是评估模型吞吐、时延与资源占用的事实数据来源。本文以 docs/protocol/extension_statistics.md 为骨架完整解析其 HTTP/REST 与 gRPC 两种接口的请求/响应结构、全部字段语义并结合 src/http_server.cc 与 src/grpc/grpc_server.cc 的源码实现帮助读者准确理解 inference_count、execution_count、各阶段 Duration 统计的真实含义从而正确解读与二次开发统计能力。一、什么是统计扩展Triton 的统计扩展Statistics Extension提供按模型按版本维度的累计统计这些统计聚合了自 Triton 启动以来发生在某个特定模型版本上的所有活动信息。其核心价值在于按模型/版本精确追踪每个统计对象都归属于具体的模型名称与版本便于对比同一模型不同版本之间的性能差异累计计数 累计时长统计以“count 总时长(ns)”形式呈现既可计算长期运行的平均值也可在两个采样点之间做差值得到增量平均值从服务器元数据即可发现能力由于 Triton 支持该扩展其 Server MetadataGET v2的extensions字段中会包含statistics标识客户端可以据此探测服务器是否具备统计能力。从实现层面看统计能力由编译选项TRITON_ENABLE_STATS控制。src/http_server.cc 中统计处理逻辑被#ifdef TRITON_ENABLE_STATS包裹未启用该编译选项时请求会返回“the server does not support model statistics”的不可用错误这一点在部署自编译服务器时需特别留意。二、HTTP/REST 接口2.1 端点与 URL 语义统计端点通过 HTTP GET 方法暴露URL 模板如下GET v2/models[/${MODEL_NAME}[/versions/${MODEL_VERSION}]]/statsURL 中三个段落的可选性决定了返回数据的范围URL 形式返回内容GET v2/models/stats所有模型的所有版本的统计GET v2/models/${MODEL_NAME}/stats指定模型的所有版本的统计GET v2/models/${MODEL_NAME}/versions/${MODEL_VERSION}/stats指定模型指定版本的统计这一点与源码中的路由实现一致。src/http_server.cc 首先对/v2/models/stats这一全模型路径做精确匹配并直接分发到HandleModelStats(req)随后src/http_server.cc通过正则model_regex_形如/v2/models/([^/])(?:/versions/([0-9]))?(?:/(infer|generate|generate_stream|ready|config|stats|trace/setting))?解析出模型名、版本与资源类型当kind stats时调用HandleModelStats(req, model_name, version)。实际的请求处理函数 HandleModelStats 还做了几项关键约束与校验仅接受GET方法其他方法返回405 Method Not Allowed若未启用TRITON_ENABLE_STATS返回503且错误信息为the server does not support model statistics版本字符串会先经GetModelVersionFromString解析为int64_t再调用核心 C APITRITONSERVER_ServerModelStatistics获取统计消息最后通过TRITONSERVER_MessageSerializeToJson序列化为 JSON 写入响应体。2.2 请求示例不带任何模型限定获取全部模型的统计curl -X GET http://localhost:8000/v2/models/stats仅获取某个模型如resnet50全部版本的统计curl -X GET http://localhost:8000/v2/models/resnet50/stats获取指定模型指定版本的统计curl -X GET http://localhost:8000/v2/models/resnet50/versions/1/stats2.3 成功响应$stats_model_response成功的统计请求以 HTTP 200 状态码标识响应体为$stats_model_response对象$stats_model_response { model_stats : [ $model_stat, ... ] }其中model_stats数组中的每个$model_stat对象对应一个具体模型的一个具体版本的统计信息结构如下$model_stat { name : $string, version : $string #optional, last_inference : $number, inference_count : $number, execution_count : $number, inference_stats : $inference_stats, response_stats : { $string : $response_stats, ... }, batch_stats : [ $batch_stats, ... ], memory_usage : [ $memory_usage, ...] }各字段语义如下name模型名称。version模型版本。该字段为可选项——对于不支持版本概念的服务器可以不返回。last_inference该模型最后一次收到推理请求的时间戳单位为自 epoch 以来的毫秒数。inference_count该模型累计成功的推理请求数。注意其计数口径批量请求中的每一个推理都单独计数。例如客户端发送一个 batch size 为 64 的请求inference_count增加 64如果客户端发送 64 个 batch size 为 1 的独立请求inference_count同样增加 64。该值不包含响应缓存Response Cache命中带来的推理。execution_count该模型累计成功的推理执行次数。它与inference_count的差异集中体现在动态批处理Dynamic Batching场景启用动态批处理后一次模型执行可以为多个推理请求服务。例如64 个 batch size 为 1 的请求被动态批处理器合并为一个大 batch 执行则execution_count只增加 1若未启用动态批处理64 个请求各自独立执行则execution_count增加 64。该值不包含缓存命中的执行。inference_stats模型的聚合推理统计例如inference_stats.success表示该模型成功的推理请求数量与累计时长。response_stats模型的聚合响应统计面向解耦/流式模型。例如{ key : { response_stats : success } }表示该模型在key处成功响应的聚合统计其中key用于标识模型在一次请求中产生的不同响应。对于一个产生三条响应的模型key 依次可为0、1、2。batch_stats每种被实际执行过的 batch size 的聚合统计用于揭示不同 batch size 带来的执行差异例如更大的 batch 通常计算耗时更长。memory_usage模型加载期间检测到的内存占用可用于估算模型卸载后释放的内存。注意该估算由性能剖析工具与框架自身的内存模型推断而来官方建议先做实验以理解哪些场景下报告的内存数值是可靠的。作为起点ONNX Runtime 后端与 TensorRT 后端的模型 GPU 内存占用通常是对齐的。2.4$inference_stats推理阶段耗时分解$inference_stats { success : $duration_stat, fail : $duration_stat, queue : $duration_stat, compute_input : $duration_stat, compute_infer : $duration_stat, compute_output : $duration_stat, cache_hit: $duration_stat, cache_miss: $duration_stat }字段含义success所有成功推理请求的计数与累计时长。包含缓存命中。fail所有失败推理请求的计数与累计时长。queue推理请求在调度队列或其他队列中等待的计数与累计时长。包含缓存命中。compute_input按模型框架/后端要求准备输入张量数据的计数与累计时长例如应包括将输入张量数据拷贝到 GPU 的时间。不包含缓存命中。compute_infer执行模型的计数与累计时长。不包含缓存命中。compute_output提取模型框架/后端产生的输出张量数据的计数与累计时长例如应包括将输出张量数据从 GPU 拷贝出来的时间。不包含缓存命中。cache_hit响应缓存命中的次数以及在命中时查找并提取缓存中输出张量数据的累计时长例如应包括将输出张量数据从响应缓存拷贝到响应对象的时间。命中时 Triton 无需再访问模型/后端获取输出数据因此compute_input、compute_infer、compute_output不更新。cache_miss响应缓存未命中的次数以及在未命中时查找并写入输出张量数据的累计时长例如应包括将输出张量数据从响应对象拷贝到响应缓存的时间。2.5$response_stats按响应索引的统计$response_stats { compute_infer : $duration_stat, compute_output : $duration_stat, success : $duration_stat, fail : $duration_stat, empty_response : $duration_stat, cancel : $duration_stat }字段含义compute_infer计算一个响应的计数与累计时长。compute_output提取已计算响应的输出张量的计数与累计时长。success成功推理的计数与累计时长时长为 infer 时长与 output 时长之和。fail失败推理的计数与累计时长时长为 infer 时长与 output 时长之和。empty_response空/无响应推理的计数与累计时长时长为 infer 时长。cancel推理被取消的计数与累计时长时长用于清理被取消推理请求所持有的资源。2.6$batch_stats按 batch size 的统计$batch_stats { batch_size : $number, compute_input : $duration_stat, compute_infer : $duration_stat, compute_output : $duration_stat }字段含义batch_size批次的大小。count该 batch size 在模型上被执行过的次数一次模型执行服务整个请求批次启用动态批处理时一次执行可以服务多个请求。compute_input以该 batch size 准备输入张量数据的计数与累计时长例如包括拷贝输入到 GPU 的时间。compute_infer以该 batch size 执行模型的计数与累计时长。compute_output以该 batch size 提取输出张量数据的计数与累计时长例如包括从 GPU 拷贝输出的时间。2.7$duration_stat累计时长统计基元$duration_stat是上述所有时长统计的基础对象报告一个计数与一个总时长$duration_stat { count : $number, ns : $number }字段含义count该统计被收集的次数。ns该统计的总时长单位为纳秒。由于同时提供计数与总时长该格式支持在两个采样点之间做差分从而计算任意时间窗口内的增量平均值incremental average而不是只能得到运行以来的长期平均。2.8$memory_usage内存占用统计$memory_usage { type : $string, id : $number, byte_size : $number }字段含义type内存类型取值可为CPU、CPU_PINNED、GPU。id内存所属设备的 id通常与type一起用于标识承载该内存的设备。byte_size内存的字节大小。2.9 失败响应$repository_statistics_error_response统计请求失败时以 HTTP 错误状态码标识典型为 400响应体必须为$repository_statistics_error_response对象$repository_statistics_error_response { error: $string }其中error为描述错误的可读消息。三、gRPC 接口统计扩展在 gRPC 侧对应GRPCInferenceService服务中的ModelStatisticsRPCservice GRPCInferenceService { … // Get the cumulative statistics for a model and version. rpc ModelStatistics(ModelStatisticsRequest) returns (ModelStatisticsResponse) {} }该 RPC 的注册与执行在 src/grpc/grpc_server.cc 中实现RegisterModelStatistics()通过service_-RequestModelStatistics注册异步请求处理实际执行时调用核心 C APITRITONSERVER_ServerModelStatistics填充响应。错误通过请求返回的google.rpc.Status指示OK表示成功其他状态码表示失败。请求与响应消息定义如下message ModelStatisticsRequest { // The name of the model. If not given returns statistics for all // models. string name 1; // The version of the model. If not given returns statistics for // all model versions. string version 2; } message ModelStatisticsResponse { // Statistics for each requested model. repeated ModelStatistics model_stats 1; }与 HTTP 接口类似name与version均为可选不填name返回全部模型统计不填version返回指定模型的全部版本统计。核心统计消息ModelStatistics完整定义如下字段编号与 HTTP JSON 字段一一对应// Statistic recording a cumulative duration metric. message StatisticDuration { // Cumulative number of times this metric occurred. uint64 count 1; // Total collected duration of this metric in nanoseconds. uint64 ns 2; } // Statistics for a specific model and version. message ModelStatistics { // The name of the model. string name 1; // The version of the model. string version 2; // The timestamp of the last inference request made for this model, // as milliseconds since the epoch. uint64 last_inference 3; // The cumulative count of successful inference requests made for this // model. Each inference in a batched request is counted as an // individual inference. uint64 inference_count 4; // The cumulative count of the number of successful inference executions // performed for the model. uint64 execution_count 5; // The aggregate statistics for the model. InferStatistics inference_stats 6; // The aggregate statistics for each different batch size that is // executed in the model. repeated InferBatchStatistics batch_stats 7; // The memory usage detected during model loading. repeated MemoryUsage memory_usage 8; // The key and value pairs for all decoupled responses statistics. The key is // a string identifying a set of response statistics aggregated together (i.e. // index of the response sent). The value is the aggregated response // statistics. mapstring, InferResponseStatistics response_stats 9; } // Inference statistics. message InferStatistics { // Cumulative count and duration for successful inference request. // Includes cache hits. StatisticDuration success 1; // Cumulative count and duration for failed inference request. StatisticDuration fail 2; // The count and cumulative duration that inference requests wait in // scheduling or other queues. Includes cache hits. StatisticDuration queue 3; // The count and cumulative duration to prepare input tensor data as // required by the model framework / backend. Does not account for // requests that were a cache hit. StatisticDuration compute_input 4; // The count and cumulative duration to execute the model. // Does not account for requests that were a cache hit. StatisticDuration compute_infer 5; // The count and cumulative duration to extract output tensor data // produced by the model framework / backend. Does not account for // requests that were a cache hit. StatisticDuration compute_output 6; // The count of response cache hits and cumulative duration to lookup // and extract output tensor data from the Response Cache on a cache hit. StatisticDuration cache_hit 7; // The count of response cache misses and cumulative duration to lookup // and insert output tensor data from the computed response to the cache. StatisticDuration cache_miss 8; } // Statistics per decoupled response. message InferResponseStatistics { // The count and cumulative duration to compute a response. StatisticDuration compute_infer 1; // The count and cumulative duration to extract the output tensors of a // response. StatisticDuration compute_output 2; // The count and cumulative duration for successful responses. StatisticDuration success 3; // The count and cumulative duration for failed responses. StatisticDuration fail 4; // The count and cumulative duration for empty responses. StatisticDuration empty_response 5; } // Inference batch statistics. message InferBatchStatistics { // The size of the batch. uint64 batch_size 1; // The count and cumulative duration to prepare input tensor data as // required by the model framework / backend with the given batch size. StatisticDuration compute_input 2; // The count and cumulative duration to execute the model with the given // batch size. StatisticDuration compute_infer 3; // The count and cumulative duration to extract output tensor data // produced by the model framework / backend with the given batch size. StatisticDuration compute_output 4; } // Memory usage. message MemoryUsage { // The type of memory, the value can be CPU, CPU_PINNED, GPU. string type 1; // The id of the memory, typically used with type to identify // a device that hosts the memory. int64_t id 2; // The byte size of the memory. uint64_t byte_size 3; }四、实战用 Python 客户端获取统计Triton 官方 Python 客户端库tritonclient.http与tritonclient.grpc均封装了统计接口示例用法如下。HTTP 客户端import tritonclient.http as httpclient client httpclient.InferenceServerClient(urllocalhost:8000) # 获取全部模型的统计 all_stats client.get_model_statistics() # 获取指定模型全部版本的统计 model_stats client.get_model_statistics(model_nameresnet50) # 获取指定模型指定版本的统计 ver_stats client.get_model_statistics( model_nameresnet50, model_version1 )gRPC 客户端import tritonclient.grpc as grpcclient client grpcclient.InferenceServerClient(urllocalhost:8001) # 不指定模型名时返回所有模型的统计 all_stats client.get_model_statistics() # 指定模型名与版本 stats client.get_model_statistics( model_nameresnet50, model_version1 )返回的统计对象可直接访问各字段例如stats.model_stats[0].inference_count、stats.model_stats[0].execution_count以及inference_stats下各阶段success、queue、compute_input、compute_infer、compute_output、cache_hit、cache_miss的count与ns字段。五、源码实现佐证与使用建议5.1 请求处理链路统计请求在服务端的完整链路可归纳为HTTPHTTPAPIServer::Handlesrc/http_server.cc根据 URL 分发到HandleModelStatssrc/http_server.cc→TRITONSERVER_ServerModelStatistics→ JSON 序列化返回gRPCCommonHandler::RegisterModelStatisticssrc/grpc/grpc_server.cc注册异步 RPC → 执行回调调用TRITONSERVER_ServerModelStatistics填充ModelStatisticsResponse。两条路径最终都汇入统一的 C APITRITONSERVER_ServerModelStatistics保证 HTTP 与 gRPC 返回的统计口径完全一致。5.2 编译开关与能力探测统计功能受TRITON_ENABLE_STATS编译选项控制。启用后服务器在GET v2返回的 Server Metadata 的extensions字段中会包含statistics客户端应优先通过该字段探测能力再决定是否调用统计接口未启用时 HTTP 请求会返回不可用错误gRPC 请求则通过google.rpc.Status的非 OK 状态码体现。5.3 解读统计时的三个要点区分inference_count与execution_count前者按“推理请求数”计数批量中的每个样本单独计数后者按“模型执行次数”计数。二者之比可以反映动态批处理的聚合效果——当动态批处理将大量请求合并执行时execution_count会显著小于inference_count。关注queue与compute_*的差异queue反映调度等待compute_input/compute_infer/compute_output反映后端实际计算通过差分可定位瓶颈在排队阶段还是计算阶段。缓存命中需单独核算success、queue包含缓存命中而compute_input、compute_infer、compute_output不包含启用响应缓存后应结合cache_hit/cache_miss的 count 与 ns 评估缓存收益。六、关联文档与进一步阅读协议原文docs/protocol/extension_statistics.mdHTTP 实现src/http_server.ccgRPC 实现src/grpc/grpc_server.cc统计相关测试qa/L0_response_statistics/response_statistics_test.py协议索引docs/protocol/README.md指标与监控指南docs/user_guide/metrics.md统计扩展提供的是服务器内置的按模型/版本的累计数据适合作为性能基线评估与容量规划的原始数据来源若需要更高频率、更细粒度的在线监控可结合 Triton 的 Metrics 体系Prometheus 格式指标使用两者互为补充。赞分享模型推理服务AI 应用后端【免费下载链接】serverThe Triton Inference Server provides an optimized cloud and edge inferencing solution.项目地址https://gitcode.com/gh_mirrors/server117/server点击查看免费下载相关推荐Triton Inference Server 的 KServe 协议扩展全景从 HTTP/REST 到 gRPC 的 11 个扩展机制详解Triton Inference Server 的 KServe 协议扩展全景从 HTTP/REST 到 gRPC 的 11 个扩展机制详解 导读 Trito模型推理服务AI 应用后端awesome-free-saas原型工具清单Proto、墨刀、Mockplus等5款免费原型工具awesome free saas原型工具清单Proto、墨刀、Mockplus等5款免费原型工具 awesome free saas https://lin文档知识库如何实现Triton Inference Server多端口健康检查HTTP与GRPC独立监控指南如何实现Triton Inference Server多端口健康检查HTTP与GRPC独立监控指南 Triton Inference Server是一款功能强模型推理服务AI 应用后端创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考
延伸阅读

更多相关文章

2026/11/26 15:41:52

C# OnnxRuntime部署DAMO-YOLO人头检测实战指南

简介:本资源是一套面向C#开发者与计算机视觉初学者的DAMO-YOLO人头检测实战部署方案,聚焦安防、人群密度分析等实际场景,解决传统YOLO模型在C#环境难以直接调用的工程落地难题。压缩包共500个文件,含111个运行依赖DLL、4个ONNX模型…

2026/11/26 17:14:31

用户画像从0到1:标签体系、完整流程与避坑指南

只说“用户画像”四个字,很多人会马上接一句“我知道,就是给用户打标签”。真到了要落地的时候,标签怎么打、数据从哪来、画完怎么用、团队怎么达成共识,每一步都可能卡住。我这些年做过十几套用户画像项目,从刚开始只…

2026/11/23 10:53:39

微阵列芯片服务器实战:从生物芯片类型到数据分析流程

见过太多实验室的微阵列数据管理方式:扫描仪吐出一批CEL文件,大家用U盘各自拷一份,谁用到谁拿自己电脑跑。样本量少的时候还凑合,等积累到一两百张芯片,问题就全冒出来了——文件散落得到处都是,有人重复做…

2026/11/26 19:49:21

考电工证口诀怎么背 内部消息告诉你怎么转证不踩坑

考电工证口诀怎么背 内部消息告诉你怎么转证不踩坑 之前考的证在外省能不能转过来?这几乎是所有在外地打工、想回老家发展或者打算换个城市工作的电工从业者最头疼的问题。其实, 内部消息…

2026/11/26 19:49:21

电工证用英语怎么说?真实经历告诉你怎么复审延期

电工证用英语怎么说?真实经历告诉你怎么复审延期 证书过期了不知道怎么复审延期,这事儿我见过太多人踩坑了。去年我表弟在濮阳刚毕业,电工证到期没及时处理,结果面试时被企业直接刷掉,理由就是“证书过期不能上岗”。这不是个例,而是很多人的真实经历。…

2026/11/26 19:49:21

单县哪里有考电工证的,上岗必备怎么选靠谱机构

单县哪里有考电工证的,上岗必备怎么选靠谱机构 不知道去哪报名怕被中介坑,你不是一个人。单县本地想考电工证的小伙伴,往往因为信息不对称,被各种打着“包过”“速拿证”旗号的中介忽悠,不仅多花冤枉钱,还可能拿到假证,影响职业生涯。尤其是像你这样的…

2026/11/26 19:49:21

低压电工证包怎么考?官方回应来了,找工作的你别再等了

低压电工证包怎么考?官方回应来了,找工作的你别再等了 你是不是也正愁找不到工作?电工证不齐全,连面试机会都没得谈。特别是低压电工证包,不仅关系到能不能上岗,更是影响工资待遇的关键。最近不少河南的求职者都反馈, 官方回应…

2026/11/26 19:44:20

常州安监局电工证补贴怎么申请?官方报名入口全攻略来了

常州安监局电工证补贴怎么申请?官方报名入口全攻略来了 怕考不过白交培训费?很多在常州准备考电工证的兄弟都担心这个问题,尤其是补贴政策一出,大家都想抓住机会,但又怕流程复杂、门槛高、甚至考不过白忙一场。别急,这篇文章从报名、考试、补贴申请到证…

2026/11/26 0:35:07

高压电工证还能年审吗良心建议来了,学历不高也能考!

高压电工证还能年审吗良心建议来了,学历不高也能考! 你是不是也担心,自己学历不高,根本报不上高压电工证?其实不然,现在政策已经非常明确, 高压电工证还能年审 ,而且只要符合条件, 学历不是门槛 , 良心建议…

2026/11/25 23:12:31

吴江的电工证免费培训怎么报名?官方报名入口全解析

吴江的电工证免费培训怎么报名?官方报名入口全解析 你急需特种作业证才能上岗找工作,但不知道从哪里下手?别急,现在就给你讲明白【吴江的电工证免费培训】到底怎么操作,以及怎么通过 官方报名入口…

2026/11/25 17:29:07

电工证复审肃州区的真实经历:别被中介坑了,自己搞定更靠谱

电工证复审肃州区的真实经历:别被中介坑了,自己搞定更靠谱 不知道去哪报名怕被中介坑?这几乎是每个需要办理或复审电工证的人的真实经历。尤其在肃州区,信息不透明、流程复杂、中介收费高又不靠谱,让很多电工从业者感到头疼。作为一个在应急管理和特种作…

2026/11/26 0:00:23

电工证跨省能复审吗报名入口与办理流程

电工证跨省能复审吗报名入口与办理流程 学历不高怕报不上名?别担心,电工证跨省能复审吗,其实很多人都在问,尤其是在郑州做公路工程的兄弟,经常跑项目,证件管理是个大问题。你是不是也遇到过这样的情况:在老家考的电工证,到外地打工时发现不能复审,甚…

2026/11/26 0:00:23

重庆大学怎么考电工证?怕考不过白交培训费?先看含金量再说

重庆大学怎么考电工证?怕考不过白交培训费?先看含金量再说 怕考不过白交培训费?别急,先搞清楚【重庆大学怎么考电工证】的全过程,以及电工证到底有没有含金量。很多人以为电工证只是个“纸片”,但真正进入工地、工厂、电力行业,没有这个证连门都进不去…

2026/11/26 0:00:23

电工证可以异地复试吗保姆级教程:别被中介坑了

电工证可以异地复试吗保姆级教程:别被中介坑了 你是不是也这样,手里拿着电工证,但不知道去哪里复试?担心被中介坑钱,又怕流程复杂,不知道从哪开始?今天这篇 保姆级教程 就来帮你搞定 电工证可以异地复试吗…

2026/11/25 10:58:53

面向复杂光照与角度的宠物面部识别鲁棒性增强策略

在智慧养宠时代,基于视觉的宠物身份识别技术正逐步从实验室走向家庭应用。然而,与配合度高的人类不同,宠物是典型的“非合作生物识别对象”——它们不会主动配合摄像头调整姿态,更无法控制光照环境。实际应用中,我们常…

2026/11/26 17:29:14

SSM电子书店源码全解析:结构、原理、部署与排错实战

/* MD / 富文本中的 .toc(含博客园搬家等嵌套结构);.toc-box 在侧栏,不受影响 */#content_views .toc,/* 编辑器常在目录前后插入空 p(:empty 仍占 20px),一并去掉避免顶空隙 */#content_views.markdown_views > p:empty:has(+ .toc),#content_views.markdown_views …

还想了解更多?直接咨询顾问

免费诊断 + 免费方案 + 透明报价。

全国咨询热线400-8866-253
免费获取方案
☎咨询二维码 ☎ ↑