I made an application on GKE. I have a question about a connection between pods. The contructed application was made on the cluster, using a service_type LoadBalancer, which was utilizing internet for connection.
At this time, I decided to use a service_type clusterIP to include a pod that should not be exposed to the Internet. In a test, it took about 5.4 ms to connect to this pod, however when exposing this pod to the Internet, that one was about 4.3 ms.
Namely, when using LoadBalancer type was better than ClusterIP one.
In my opinion, those results is opposite. I think that ClusterIP service uses only internal networks, and that LoadBalancer one do thorough the Internet.
Is this result true? Or is there any mistakes on a way to test?
If this is true, why this happens?
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')
Cluster IP' expects faster results than load balancerwhen accessed 100 times.
Reference image is below. service_type: ClusterIP == PodB service_type: LoadBalancer == PodC
Could be several things:
How many "ms" an ICMP test from a container to another pod container you get?
Have you tried using an Internal Load Balancer to see how it goes?