]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Refactor logging in loop to only log debug messages once
authorBilly Olsen <billy.olsen@canonical.com>
Fri, 23 Jan 2015 22:50:40 +0000 (15:50 -0700)
committerBilly Olsen <billy.olsen@canonical.com>
Wed, 4 Feb 2015 22:27:48 +0000 (15:27 -0700)
Logging entries in a loop to a file can be expensive for a large
number of objects (e.g. ports) in a loop. Rather than perform the
overhead of logging a debug entry for each line within the hosts
file, move the debug trace of the contents to after the loop to
bulk up the I/O operations.

Change-Id: I3ad7864eeb2f959549ed356a1e34fa18804395cc
Closes-Bug: #1414218

neutron/agent/linux/dhcp.py

index 63a61d8a7b10e894ed6c00543e250889f9440b0c..aa737604d3ad98f6e12f85c0614446ba7beba6fb 100644 (file)
@@ -491,8 +491,6 @@ class Dnsmasq(DhcpLocalProcess):
                 if getattr(port, 'extra_dhcp_opts', False):
                     buf.write('%s,%s%s\n' %
                               (port.mac_address, 'set:', port.id))
-                    LOG.debug('Adding %(mac)s : set:%(tag)s',
-                              {"mac": port.mac_address, "tag": port.id})
                 continue
 
             # don't write ip address which belongs to a dhcp disabled subnet.
@@ -510,19 +508,13 @@ class Dnsmasq(DhcpLocalProcess):
                 buf.write('%s,%s,%s,%s%s\n' %
                           (port.mac_address, name, ip_address,
                            'set:', port.id))
-                LOG.debug('Adding %(mac)s : %(name)s : %(ip)s : '
-                          'set:%(tag)s',
-                          {"mac": port.mac_address, "name": name,
-                           "ip": ip_address, "tag": port.id})
             else:
                 buf.write('%s,%s,%s\n' %
                           (port.mac_address, name, ip_address))
-                LOG.debug('Adding %(mac)s : %(name)s : %(ip)s',
-                          {"mac": port.mac_address, "name": name,
-                           "ip": ip_address})
 
         utils.replace_file(filename, buf.getvalue())
-        LOG.debug('Done building host file %s', filename)
+        LOG.debug('Done building host file %s with contents:\n%s', filename,
+                  buf.getvalue())
         return filename
 
     def _read_hosts_file_leases(self, filename):