最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

AsyncHttpClient?ClientStats源碼流程解讀

 更新時(shí)間:2023年12月15日 09:46:48   作者:codecraft  
這篇文章主要為大家介紹了AsyncHttpClient?ClientStats源碼流程解讀,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪

本文主要研究一下AsyncHttpClient的ClientStats

ClientStats

org/asynchttpclient/ClientStats.java

/**
 * A record class representing the state of an (@link org.asynchttpclient.AsyncHttpClient).
 */
public class ClientStats {
  private final Map<String, HostStats> statsPerHost;
  public ClientStats(Map<String, HostStats> statsPerHost) {
    this.statsPerHost = Collections.unmodifiableMap(statsPerHost);
  }
  /**
   * @return A map from hostname to statistics on that host's connections.
   * The returned map is unmodifiable.
   */
  public Map<String, HostStats> getStatsPerHost() {
    return statsPerHost;
  }
  /**
   * @return The sum of {@link #getTotalActiveConnectionCount()} and {@link #getTotalIdleConnectionCount()},
   * a long representing the total number of connections in the connection pool.
   */
  public long getTotalConnectionCount() {
    return statsPerHost
            .values()
            .stream()
            .mapToLong(HostStats::getHostConnectionCount)
            .sum();
  }
  /**
   * @return A long representing the number of active connections in the connection pool.
   */
  public long getTotalActiveConnectionCount() {
    return statsPerHost
            .values()
            .stream()
            .mapToLong(HostStats::getHostActiveConnectionCount)
            .sum();
  }
  /**
   * @return A long representing the number of idle connections in the connection pool.
   */
  public long getTotalIdleConnectionCount() {
    return statsPerHost
            .values()
            .stream()
            .mapToLong(HostStats::getHostIdleConnectionCount)
            .sum();
  }
  @Override
  public String toString() {
    return "There are " + getTotalConnectionCount() +
            " total connections, " + getTotalActiveConnectionCount() +
            " are active and " + getTotalIdleConnectionCount() + " are idle.";
  }
  @Override
  public boolean equals(final Object o) {
    if (this == o) return true;
    if (o == null || getClass() != o.getClass()) return false;
    final ClientStats that = (ClientStats) o;
    return Objects.equals(statsPerHost, that.statsPerHost);
  }
  @Override
  public int hashCode() {
    return Objects.hashCode(statsPerHost);
  }
}
ClientStats通過Map<String, HostStats>維護(hù)了每個(gè)host對(duì)應(yīng)的統(tǒng)計(jì);它提供了getStatsPerHost、getTotalConnectionCount、getTotalActiveConnectionCount、getTotalIdleConnectionCount方法

HostStats

org/asynchttpclient/HostStats.java

/**
 * A record class representing the status of connections to some host.
 */
public class HostStats {
  private final long activeConnectionCount;
  private final long idleConnectionCount;
  public HostStats(long activeConnectionCount,
                   long idleConnectionCount) {
    this.activeConnectionCount = activeConnectionCount;
    this.idleConnectionCount = idleConnectionCount;
  }
  /**
   * @return The sum of {@link #getHostActiveConnectionCount()} and {@link #getHostIdleConnectionCount()},
   * a long representing the total number of connections to this host.
   */
  public long getHostConnectionCount() {
    return activeConnectionCount + idleConnectionCount;
  }
  /**
   * @return A long representing the number of active connections to the host.
   */
  public long getHostActiveConnectionCount() {
    return activeConnectionCount;
  }
  /**
   * @return A long representing the number of idle connections in the connection pool.
   */
  public long getHostIdleConnectionCount() {
    return idleConnectionCount;
  }
  @Override
  public String toString() {
    return "There are " + getHostConnectionCount() +
            " total connections, " + getHostActiveConnectionCount() +
            " are active and " + getHostIdleConnectionCount() + " are idle.";
  }
  @Override
  public boolean equals(final Object o) {
    if (this == o) return true;
    if (o == null || getClass() != o.getClass()) return false;
    final HostStats hostStats = (HostStats) o;
    return activeConnectionCount == hostStats.activeConnectionCount &&
            idleConnectionCount == hostStats.idleConnectionCount;
  }
  @Override
  public int hashCode() {
    return Objects.hash(activeConnectionCount, idleConnectionCount);
  }
}
HostStats定義了activeConnectionCount、idleConnectionCount屬性

getClientStats

org/asynchttpclient/netty/channel/ChannelManager.java

public ClientStats getClientStats() {
    Map<String, Long> totalConnectionsPerHost = openChannels.stream().map(Channel::remoteAddress).filter(a -> a.getClass() == InetSocketAddress.class)
            .map(a -> (InetSocketAddress) a).map(InetSocketAddress::getHostName).collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));
    Map<String, Long> idleConnectionsPerHost = channelPool.getIdleChannelCountPerHost();
    Map<String, HostStats> statsPerHost = totalConnectionsPerHost.entrySet().stream().collect(Collectors.toMap(Entry::getKey, entry -> {
      final long totalConnectionCount = entry.getValue();
      final long idleConnectionCount = idleConnectionsPerHost.getOrDefault(entry.getKey(), 0L);
      final long activeConnectionCount = totalConnectionCount - idleConnectionCount;
      return new HostStats(activeConnectionCount, idleConnectionCount);
    }));
    return new ClientStats(statsPerHost);
  }
ChannelManager提供了getClientStats方法,它從openChannels獲取totalConnectionsPerHost,從channelPool.getIdleChannelCountPerHost()獲取idleConnectionCount,然后創(chuàng)建HostStats,最后返回ClientStats

小結(jié)

AsyncHttpClient提供了ClientStats用于獲取連接的統(tǒng)計(jì)信息,可按host維度,統(tǒng)計(jì)activeConnectionCount、idleConnectionCount,也可匯總查看totalConnectionCount、totalActiveConnectionCount、totalIdleConnectionCount。它可以從ChannelManager獲取。對(duì)于使用micrometer的可以使用這個(gè)作為數(shù)據(jù)源進(jìn)行適配。

以上就是AsyncHttpClient ClientStats源碼流程解讀的詳細(xì)內(nèi)容,更多關(guān)于AsyncHttpClient ClientStats的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

最新評(píng)論

万盛区| 阳曲县| 太原市| 共和县| 永修县| 湖州市| 筠连县| 右玉县| 湖口县| 万载县| 澄迈县| 汉阴县| 南郑县| 新河县| 家居| 于都县| 封丘县| 永和县| 白山市| 萨迦县| 扶绥县| 饶河县| 报价| 雅江县| 丹东市| 凯里市| 安仁县| 行唐县| 都匀市| 疏勒县| 阳谷县| 炎陵县| 景谷| 临高县| 临漳县| 罗定市| 吴江市| 上饶县| 绥宁县| 桓仁| 湘乡市|