Skip to content

Commit

Permalink
对异常响应进行指标统计,分请求过程和最终响应两种场景,排除mc,因为异常基本是请求miss或del notfound
Browse files Browse the repository at this point in the history
  • Loading branch information
hustfisher committed Oct 11, 2024
1 parent c4a1725 commit 3eb4e68
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 2 deletions.
6 changes: 6 additions & 0 deletions protocol/src/memcache/binary/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,12 @@ impl Protocol for MemcacheBinary {
None
}
}

// mc目前不需要统计error,因为mc的error基本都是get miss,del not-found这种,这种错误不需要统计
#[inline]
fn metric_err(&self) -> bool {
false
}
}
impl MemcacheBinary {
// 根据req构建response,status为mc协议status,共11种
Expand Down
4 changes: 4 additions & 0 deletions protocol/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@ pub trait Proto: Unpin + Clone + Send + Sync + 'static {
fn max_tries(&self, _req_op: Operation) -> u8 {
1_u8
}

fn metric_err(&self) -> bool {
true
}
}

pub trait RequestProcessor {
Expand Down
9 changes: 8 additions & 1 deletion stream/src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pub struct Handler<'r, Req, P, S> {
s: S,
parser: P,
rtt: Metric,
err: Metric,
host_metric: HostMetric,

num: Number,
Expand Down Expand Up @@ -63,12 +64,14 @@ where
data.enable();
let name = path.clone();
let rtt = path.rtt("req");
let err = path.qps("err");
Self {
data,
pending: VecDeque::with_capacity(31),
s,
parser,
rtt,
err,
host_metric: HostMetric::from(path),
num: Number::default(),
req_buf: Vec::with_capacity(4),
Expand Down Expand Up @@ -142,8 +145,12 @@ where
}
let (req, start) = self.pending.pop_front().expect("take response");
self.num.rx();
// 统计请求耗时
// 统计请求耗时、异常响应
self.rtt += start.elapsed();
if self.parser.metric_err() && !cmd.ok() {
self.err += 1;
}

self.parser.check(&*req, &cmd);
req.on_complete(cmd);
continue;
Expand Down
8 changes: 7 additions & 1 deletion stream/src/pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,16 @@ where

let op = ctx.request().operation();
if let Some(rsp) = response {
if ctx.is_write_back() && rsp.ok() {
let rsp_ok = rsp.ok();
if ctx.is_write_back() && rsp_ok {
ctx.async_write_back(&self.parser, rsp, self.top.exp_sec(), &mut self.metrics);
self.async_pending.push_back(ctx);
}

// 不区分是否last,这样更精确的感知总的异常响应数量
if self.parser.metric_err() && !rsp_ok {
*self.metrics.err() += 1;
}
}

// 数据写完,统计耗时。当前数据只写入到buffer中,
Expand Down

0 comments on commit 3eb4e68

Please sign in to comment.