First, thanks for all your projects around docker - they are great help.
One issue that I've been noticing is that when I have more than one container of the same service, the haproxy config would start reloading every 10-15 seconds even tho there were no change.
The issue is that etcd doesn't send back the nodes in the same order every time, and docker-discover would detect a change even tho it was just the same nodes, not in the same order.
A way to avoid this would be to have get_services() sort its results so that no change would be detected when nodes are swapped in the etcd response
I wrote a workaround, but I'm no python expert and it's too dirty to put in a pull request, but here it is anyway:
if name == "main":
current_services = {}
while True:
changed = False
try:
services = get_services()
if not services or services == current_services:
time.sleep(POLL_TIMEOUT)
continue
else:
numberServices = len(services.items())
current_numberServices = len(current_services.items())
# print "numberServices = " + str(numberServices)
# print "current_numberServices = " + str(current_numberServices)
if numberServices == current_numberServices:
# "No new services... lets check them"
for i in range(numberServices):
if services.items()[i][0] == current_services.items()[i][0]:
# "Same services... Same values?"
regex = re.compile('[0-9]+.[0-9]+.[0-9]+.[0-9]+\:[0-9]+')
ipServices = sorted(re.findall(regex, str(services.items()[i])))
current_ipServices = sorted(re.findall(regex, str(current_services.items()[i])))
if ipServices == current_ipServices:
else:
changed = True
break;
else:
changed = True
break;
if changed == True:
print "config changed. reload haproxy"
generate_config(services)
ret = call(["./reload-haproxy.sh"])
if ret != 0:
print "reloading haproxy returned: ", ret
time.sleep(POLL_TIMEOUT)
continue
current_services = services
except Exception, e:
print "Error:", e
time.sleep(POLL_TIMEOUT)
I'm sure all of this could be done with a one liner sorting in get_services tho
Hello,
First, thanks for all your projects around docker - they are great help. One issue that I've been noticing is that when I have more than one container of the same service, the haproxy config would start reloading every 10-15 seconds even tho there were no change.
The issue is that etcd doesn't send back the nodes in the same order every time, and docker-discover would detect a change even tho it was just the same nodes, not in the same order.
A way to avoid this would be to have get_services() sort its results so that no change would be detected when nodes are swapped in the etcd response
I wrote a workaround, but I'm no python expert and it's too dirty to put in a pull request, but here it is anyway:
if name == "main": current_services = {} while True: changed = False try: services = get_services()
I'm sure all of this could be done with a one liner sorting in get_services tho
Regards,