Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
272 views
in Technique[技术] by (71.8m points)

java - How to correctly measure downstream response times in Spring Cloud Gateway?

In Spring Cloud Gateway I would like to measure, how long downstream requests exactly take in order to compare it to complete time needed (downstream service time + processing time of Spring cloud Gateway).

I implemented a GlobalFilter which does the measure right in front of NettyRoutingFilter. This however also includes part of the event loop processing (as far as I understand). At least under load the times measured here do not correlate to the response times of a known downstream service.

Basic simplified approach:

class ProxyResponseTimeFilter
  implements GlobalFilter, Ordered
{
  @Override
  public int getOrder()
  {
    // see NettyRoutingFilter
    return Ordered.LOWEST_PRECEDENCE - 1;
  }

  @Override
  public Mono<Void> filter(final ServerWebExchange exchange, final GatewayFilterChain chain)
  {
    return chain.filter(exchange).transformDeferred(request ->
    {
      final long start = System.nanoTime();
      return request.doFinally(s ->
      {
        final long duration = System.nanoTime() - start;
        System.out.println(exchange.getRequest().getPath() + " " + TimeUnit.NANOSECONDS.toMillis(duration));
      });
    });
  }
}

I'm using Spring Cloud Hoxton.SR9.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...