Fix collector single worker to handle UDP package with many worker config
When enable ceilometer-collector with many worker,only one subprocess process UDP package , the others doesn't work. the parameter SO_REUSEPORT will allow process listen same socket and improve effectively work. Change-Id: I7f0d87bf6a3635a648b11419ae088c748f51e377 Closes-bug: 1632576
This commit is contained in:
parent
7a7866c58f
commit
2a6b325f4d
@ -108,8 +108,15 @@ class CollectorService(cotyledon.Service):
|
||||
address_family = socket.AF_INET6
|
||||
udp = socket.socket(address_family, socket.SOCK_DGRAM)
|
||||
udp.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
||||
udp.bind((self.conf.collector.udp_address,
|
||||
self.conf.collector.udp_port))
|
||||
try:
|
||||
# NOTE(zhengwei): linux kernel >= 3.9
|
||||
udp.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1)
|
||||
except Exception:
|
||||
LOG.warning(_LW("System does not support socket.SO_REUSEPORT "
|
||||
"option. Only one worker will be able to process "
|
||||
"incoming data."))
|
||||
udp.bind((cfg.CONF.collector.udp_address,
|
||||
cfg.CONF.collector.udp_port))
|
||||
|
||||
self.udp_run = True
|
||||
while self.udp_run:
|
||||
|
@ -109,8 +109,11 @@ class TestCollector(tests_base.BaseTestCase):
|
||||
|
||||
def _verify_udp_socket(self, udp_socket):
|
||||
conf = self.CONF.collector
|
||||
udp_socket.setsockopt.assert_called_once_with(socket.SOL_SOCKET,
|
||||
socket.SO_REUSEADDR, 1)
|
||||
setsocketopt_calls = [mock.call.setsockopt(socket.SOL_SOCKET,
|
||||
socket.SO_REUSEADDR, 1),
|
||||
mock.call.setsockopt(socket.SOL_SOCKET,
|
||||
socket.SO_REUSEPORT, 1)]
|
||||
udp_socket.setsockopt.assert_has_calls(setsocketopt_calls)
|
||||
udp_socket.bind.assert_called_once_with((conf.udp_address,
|
||||
conf.udp_port))
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user