【HDFS】一个RPC的生命周期,从服务端接收到响应的各个阶段的

2023-02-04  本文已影响0人  大数据Zone

注:本文参考的hadoop版本是:3.3.2

RPC生命周期

在ProcessingDetails.Timing枚举类里:

  /**
   * The different stages to track the time of.
   */
  public enum Timing {
    // reader线程把Call放入call queue的时间
    ENQUEUE,          // time for reader to insert in call queue.
    // Call在call queue里等待处理的时间
    QUEUE,            // time in the call queue.
    // handler线程的一些消耗(不在处理/响应的时间)
    HANDLER,          // handler overhead not spent in processing/response.
    // handler花在处理call上的时间:等于lock free + lock wait + lock shared + lock exclusive的时间
    PROCESSING,       // time handler spent processing the call. always equal to
                      // lock_free + lock_wait + lock_shared + lock_exclusive
    LOCKFREE,         // processing with no lock.
    LOCKWAIT,         // processing while waiting for lock.
    LOCKSHARED,       // processing with a read lock.
    LOCKEXCLUSIVE,    // processing with a write lock.
    // encode和发送相应的时间。
    RESPONSE;         // time to encode and send response.
  }

TODO:画一幅图,标注出每个阶段。

Handler的run方法内部,每次执行完一个call#run方法之后,finally块里会调用updateMetrics进行RPC相关指标的统计。

1、ENQUEUE

这个阶段是reader将请求插入到call queue里的时间。

internalQueueCall方法:

  private void internalQueueCall(Call call, boolean blocking)
      throws IOException, InterruptedException {
    try {
      // queue the call, may be blocked if blocking is true.
      if (blocking) {
        callQueue.put(call);
      } else {
        callQueue.add(call);
      }
      // 这个delta就是ENQUEUE的时间,因此我们要看call.timestampNanos是什么?
      long deltaNanos = Time.monotonicNowNanos() - call.timestampNanos;
      call.getProcessingDetails().set(Timing.ENQUEUE, deltaNanos,
          TimeUnit.NANOSECONDS);
    } catch (CallQueueOverflowException cqe) {
      // If rpc scheduler indicates back off based on performance degradation
      // such as response time or rpc queue is full, we will ask the client
      // to back off by throwing RetriableException. Whether the client will
      // honor RetriableException and retry depends the client and its policy.
      // For example, IPC clients using FailoverOnNetworkExceptionRetry handle
      // RetriableException.
      rpcMetrics.incrClientBackoff();
      // unwrap retriable exception.
      throw cqe.getCause();
    }
  }

timestampNanos是这个rpc call被接收时的时间。

全文请参考链接:
https://blog.csdn.net/yexiguafu/article/details/128850802

上一篇 下一篇

猜你喜欢

热点阅读