0

我在 GKE 上申请了。我对 pod 之间的连接有疑问。构建的应用程序是在集群上使用 service_type LoadBalancer 构建的,它利用 Internet 进行连接。

这时候,我决定使用一个 service_type clusterIP 来包含一个不应该暴露在互联网上的 pod。在测试中,连接到这个 pod 大约需要 5.4 毫秒,但是当把这个 pod 暴露在互联网上时,这个时间大约是 4.3 毫秒。

即,当使用 LoadBalancer 类型时优于 ClusterIP 类型。

在我看来,这些结果是相反的。我认为 ClusterIP 服务只使用内部网络,而 LoadBalancer 则通过 Internet。

这个结果是真的吗?或者在测试的方式上有什么错误吗?

如果这是真的,为什么会发生这种情况?

import logging, requests
import statistics
import time
from flask import Flask, jsonify

app = Flask(__name__)


#clusterIPを指定した応答時間の測定
@app.route('/req_cluster')
def req_cluster():
    try:
        #応答時間を測定(100リクエスト分)
        response_time_list = []
        for i in range(100):
            start = time.time()
            res = requests.get("http://10.0.7.70:8080/prease_get")
            end = time.time()
            print(start - end)
            response_time_list.append(float(start - end))

        #合計値を格納
        execution_hours_sum = sum(response_time_list)
        #中央値を格納
        median = statistics.median(response_time_list)
        #平均値を格納
        mean = statistics.mean(response_time_list)

        #出力フォーマットの指定
        print("clusterIPを指定した応答時間の測定\n\n最終(100回目)のステータスコード:{}\n応答時間の合計値:{}\n応答時間の中央値:{}\n応答時間の平均値:{}".format(jsonify(res.status_code), execution_hours_sum, median, mean))
        result = "clusterIPを指定した応答時間の測定\n\n最終(100回目)のステータスコード:{}\n応答時間の合計値:{}\n応答時間の中央値:{}\n応答時間の平均値:{}".format(jsonify(res.status_code), execution_hours_sum, median, mean)

    except Exception as err:
        logging.error(err.args) 

    return result

#LoadBalancerを指定した応答時間の測定
@app.route('/req_loadbalancer')
def req_loadbalancer():
    try:
        #応答時間を測定(100リクエスト分)
        response_time_list = []
        for i in range(100):
            start = time.time()
            res =  requests.get("http://34.85.40.229:8080/prease_get") 
            end = time.time()
            print(start - end)
            response_time_list.append(float(start - end))

        #合計値を格納
        execution_hours_sum = sum(response_time_list)
        #中央値を格納
        median = statistics.median(response_time_list)
        #平均値を格納
        mean = statistics.mean(response_time_list)

        #出力フォーマットの指定
        print("LoadBalancerを指定した応答時間の測定\n\n最終(100回目)のステータスコード:{}\n応答時間の合計値:{}\n応答時間の中央値:{}\n応答時間の平均値:{}".format(jsonify(res.status_code), execution_hours_sum, median, mean))
        result = "LoadBalancerを指定した応答時間の測定\n\n最終(100回目)のステータスコード:{}\n応答時間の合計値:{}\n応答時間の中央値:{}\n応答時間の平均値:{}".format(jsonify(res.status_code), execution_hours_sum, median, mean)

    except Exception as err:
        logging.error(err.args) 

    return result

if __name__ == '__main__':
   app.run()
   logging.info('fugafuga')
   logging.warning('hogehoge')

当访问 100 次时,集群 IP' 期望比负载均衡器更快的结果。

在此处输入图像描述

参考图片如下。service_type: ClusterIP == PodB service_type: LoadBalancer == PodC

4

1 回答 1

0

可能是几件事:

  • 您的 pod 是否具有相同的资源
  • 配置错误的负载均衡器
  • 您的内容可能会缓存在Google Cloud CDN上
  • 您的测试可能已经使您的 pod 资源不堪重负,负载均衡器可能已经“平衡”了您的测试

从一个容器到另一个 pod 容器的 ICMP 测试有多少“毫秒”?

您是否尝试过使用内部负载均衡器来查看效果如何?

于 2019-08-12T22:25:03.677 回答