我在GKE上申请了。我有一个关于pods之间的连接的问题。所构建的应用程序是在集群上使用service_type LoadBalancer实现的,它利用internet进行连接。
此时,我决定使用service_type clusterIP来包含一个不应该暴露在互联网上的pod。在一次测试中,连接到此pod大约需要5.4毫秒,但将此pod暴露到Internet时,这一时间约为4.3毫秒。
也就是说,当使用LoadBalancer类型时比使用ClusterIP类型要好。
在我看来,这些结果是相反的。我认为ClusterIP服务只使用内部网络,而LoadBalancer服务通过互联网。
这个结果是真的吗?或者在测试的方式上有任何错误?
如果这是真的,为什么会发生这种情况?
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
发布于 2019-08-13 06:25:04
可能有以下几种情况:
从一个容器到另一个pod容器的ICMP测试得到多少个"ms“?
你有没有试过使用内部负载均衡器来看看它是如何进行的?
https://stackoverflow.com/questions/57424416
复制相似问题