首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >代理统计: qtime,ctime,rtime,ttime?

代理统计: qtime,ctime,rtime,ttime?
EN

Stack Overflow用户
提问于 2018-02-12 22:41:18
回答 1查看 1.9K关注 0票数 5

在HAProxy 1.6.3-1 ubuntu0.1后面运行一个web应用程序,我将得到0,0,0,2704的haproxy stats qtime,ctime,rtime,ttime值。

来自docs (https://www.haproxy.org/download/1.6/doc/management.txt):

代码语言:javascript
复制
 58. qtime [..BS]: the average queue time in ms over the 1024 last requests
 59. ctime [..BS]: the average connect time in ms over the 1024 last requests
 60. rtime [..BS]: the average response time in ms over the 1024 last requests
     (0 for TCP)
 61. ttime [..BS]: the average total session time in ms over the 1024 last requests

我预计响应时间在0-10毫秒范围内。2704毫秒的ttime似乎不切实际地高。是否有可能单位关闭,这是2704微秒,而不是2704万秒?

第二,ttime甚至与qtime+ctime+rtime并不接近,这似乎令人怀疑。总响应时间不是队列、连接和响应时间的总和吗?其他时间是什么,包括在总数中,但不包括队列/连接/响应?为什么我的响应时间可以是<1ms,而我的总响应时间是2704 ms?

这是我完整的csv数据:

代码语言:javascript
复制
$ curl "http://localhost:9000/haproxy_stats;csv"
# pxname,svname,qcur,qmax,scur,smax,slim,stot,bin,bout,dreq,dresp,ereq,econ,eresp,wretr,wredis,status,weight,act,bck,chkfail,chkdown,lastchg,downtime,qlimit,pid,iid,sid,throttle,lbtot,tracked,type,rate,rate_lim,rate_max,check_status,check_code,check_duration,hrsp_1xx,hrsp_2xx,hrsp_3xx,hrsp_4xx,hrsp_5xx,hrsp_other,hanafail,req_rate,req_rate_max,req_tot,cli_abrt,srv_abrt,comp_in,comp_out,comp_byp,comp_rsp,lastsess,last_chk,last_agt,qtime,ctime,rtime,ttime,
http-in,FRONTEND,,,4707,18646,50000,5284057,209236612829,42137321877,0,0,997514,,,,,OPEN,,,,,,,,,1,2,0,,,,0,4,0,2068,,,,0,578425742,0,997712,22764,1858,,1561,3922,579448076,,,0,0,0,0,,,,,,,,
servers,server1,0,0,0,4337,20000,578546476,209231794363,41950395095,,0,,22861,1754,95914,0,no check,1,1,0,,,,,,1,3,1,,578450562,,2,1561,,6773,,,,0,578425742,0,198,0,0,0,,,,29,1751,,,,,0,,,0,0,0,2704,
servers,BACKEND,0,0,0,5919,5000,578450562,209231794363,41950395095,0,0,,22861,1754,95914,0,UP,1,1,0,,0,320458,0,,1,3,0,,578450562,,1,1561,,3922,,,,0,578425742,0,198,22764,1858,,,,,29,1751,0,0,0,0,0,,,0,0,0,2704,
stats,FRONTEND,,,2,5,2000,5588,639269,8045341,0,0,29,,,,,OPEN,,,,,,,,,1,4,0,,,,0,1,0,5,,,,0,5374,0,29,196,0,,1,5,5600,,,0,0,0,0,,,,,,,,
stats,BACKEND,0,0,0,1,200,196,639269,8045341,0,0,,196,0,0,0,UP,0,0,0,,0,320458,0,,1,4,0,,0,,1,0,,5,,,,0,0,0,0,196,0,,,,,0,0,0,0,0,0,0,,,0,0,0,0,
EN

回答 1

Stack Overflow用户

发布于 2021-02-04 10:02:27

在haproxy >2中,您现在得到两个值n / n,即滑动窗口中的最大值和该窗口的平均值。在所有示例窗口中,最大值将保持为最大值,直到找到更高的值为止。在1.8岁时,你只能得到平均水平。

haproxy 2 v1.8的例子。注意,这些代理的使用非常不同,负载也有很大的不同。

因此,看起来平均响应时间至少自上次重新启动以来是66m和275 at。

平均数计算如下:

代码语言:javascript
复制
data time + cumulative http connections - 1 / cumulative http connections

这可能不是一个完美的分析,所以如果有人有改进,它将是感激的。这是为了显示我是如何找到上面的答案的,这样你就可以用它来收集更多关于你询问的其他计数器的信息。这些信息大部分是从阅读stats.c中收集的。您询问的计数器是定义的这里

代码语言:javascript
复制
unsigned int q_time, c_time, d_time, t_time; /* sums of conn_time, queue_time, data_time, total_time */
unsigned int qtime_max, ctime_max, dtime_max, ttime_max; /* maximum of conn_time, queue_time, data_time, total_time observed */```

stats页值是从以下代码生成的:

代码语言:javascript
复制
if (strcmp(field_str(stats, ST_F_MODE), "http") == 0)
            chunk_appendf(out, "<tr><th>- Responses time:</th><td>%s / %s</td><td>ms</td></tr>",
                      U2H(stats[ST_F_RT_MAX].u.u32), U2H(stats[ST_F_RTIME].u.u32));
            chunk_appendf(out, "<tr><th>- Total time:</th><td>%s / %s</td><td>ms</td></tr>",
                  U2H(stats[ST_F_TT_MAX].u.u32), U2H(stats[ST_F_TTIME].u.u32));   

你问了所有的柜台,但我会集中在一个。从上面的片段中可以看到,“响应时间:”ST_F_RT_MAXST_F_RTIME是在stats页面上分别显示为n (rtime_max) / n (rtime)的值。它们的定义如下:

代码语言:javascript
复制
[ST_F_RT_MAX] = { .name = "rtime_max", .desc = "Maximum observed time spent waiting for a server response, in milliseconds (backend/server)" },
[ST_F_RTIME] = { .name = "rtime", .desc = "Time spent waiting for a server response, in milliseconds, averaged over the 1024 last requests (backend/server)" },

它们在代码中的case语句中设置了一个“度量”值(除其他外):

代码语言:javascript
复制
case ST_F_RT_MAX:
    metric = mkf_u32(FN_MAX, sv->counters.dtime_max);
    break;
case ST_F_RTIME:
    metric = mkf_u32(FN_AVG, swrate_avg(sv->counters.d_time, srv_samples_window));
    break;

这些度量值使我们很好地了解了stats页面告诉我们的内容。“响应时间: / 0”ST_F_RT_MAX中的第一个值是一些最大值等待时间。“响应时间:0/ ”ST_F_RTIME中的第二个值是每个连接的平均时间。这是一个时间窗口内的最大值和平均值,也就是不管你需要多长时间才能得到1024个连接。

例如“响应时间: 10000 / 20":

  • 在过去1024个连接中花费的最大等待时间(包括http保持活动时间在内的最大值达到10秒)
  • 过去1024个连接的平均时间为20 the

所以对于所有的意图和目的

代码语言:javascript
复制
rtime_max = dtime_max
rtime = swrate_avg(d_time, srv_samples_window)

这就引出了一个问题:dtime_maxd_timesrv_sample_window是什么?这些是数据时间窗口,我不知道这些时间值是如何设置的,但在表面上,对于最后1024个连接来说,这是“一段时间”。正如所指出的,这里保持活动的时间包含在最大值中,这就是为什么数字很高的原因。

既然我们知道ST_F_RT_MAX是一个最大值,而ST_F_RTIME是一个平均值,那么平均是什么呢?

代码语言:javascript
复制
/* compue time values for later use */
if (selected_field == NULL || *selected_field == ST_F_QTIME ||
    *selected_field == ST_F_CTIME || *selected_field == ST_F_RTIME ||
    *selected_field == ST_F_TTIME) {
    srv_samples_counter = (px->mode == PR_MODE_HTTP) ? sv->counters.p.http.cum_req : sv->counters.cum_lbconn;
    if (srv_samples_counter < TIME_STATS_SAMPLES && srv_samples_counter > 0)
        srv_samples_window = srv_samples_counter;
}

TIME_STATS_SAMPLES值定义为

代码语言:javascript
复制
#define TIME_STATS_SAMPLES 512
unsigned int srv_samples_window = TIME_STATS_SAMPLES;

在模式中,http srv_sample_countersv->counters.p.http.cum_reqhttp.cum_req被定义为ST_F_REQ_TOT

代码语言:javascript
复制
[ST_F_REQ_TOT]  = { .name = "req_tot",  .desc = "Total number of HTTP requests processed by this object since the worker process started" },

例如,如果http.cum_req的值为10,则srv_sample_counter为10。该示例似乎是对给定后端服务器的给定示例窗口的成功请求数。d_time (数据时间)被传递为“和”,并被计算为某个非负值或它被计算为一个错误。我以为我找到了如何创建d_time的代码,但我不确定,所以我没有包括它。

代码语言:javascript
复制
/* Returns the average sample value for the sum <sum> over a sliding window of
 * <n> samples. Better if <n> is a power of two. It must be the same <n> as the
 * one used above in all additions.
 */
static inline unsigned int swrate_avg(unsigned int sum, unsigned int n)
{
    return (sum + n - 1) / n;
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48756735

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档