2
0
mirror of https://github.com/xcat2/confluent.git synced 2026-07-27 08:17:30 +00:00

Cache manager name

Since the get_myname() may be called much much more
frequently now that it is in the deployment flow,
have it cache results to save a lot of disk I/O
This commit is contained in:
Jarrod Johnson
2021-01-08 16:30:51 -05:00
parent 5812a0eef6
commit 25c3f40559
@@ -28,6 +28,7 @@ import eventlet.green.ssl as ssl
import eventlet.green.threading as threading
import greenlet
import random
import time
import sys
try:
import OpenSSL.crypto as crypto
@@ -195,15 +196,21 @@ def connect_to_collective(cert, member):
raise Exception("Certificate mismatch in the collective")
return remote
mycachedname = [None, 0]
def get_myname():
if mycachedname[1] > time.time() - 15:
return mycachedname[0]
try:
with open('/etc/confluent/cfg/myname', 'r') as f:
return f.read().strip()
mycachedname[0] = f.read().strip()
mycachedname[1] = time.time()
return
except IOError:
myname = socket.gethostname()
with open('/etc/confluent/cfg/myname', 'w') as f:
f.write(myname)
mycachedname[0] = myname
mycachedname[1] = time.time()
return myname
def handle_connection(connection, cert, request, local=False):