Merge lp:~ralph-bean/pylibravatar/tcp-dns into lp:pylibravatar

Proposed by Ralph Bean
Status: Merged
Merged at revision: 37
Proposed branch: lp:~ralph-bean/pylibravatar/tcp-dns
Merge into: lp:pylibravatar
Diff against target: 12 lines (+1/-1)
1 file modified
libravatar.py (+1/-1)
To merge this branch: bzr merge lp:~ralph-bean/pylibravatar/tcp-dns
Reviewer Review Type Date Requested Status
François Marier Approve
Review via email: mp+263157@code.launchpad.net

Commit message

Use TCP for SRV lookups

Description of the change

Use tcp for SRV lookups.

By default, the DNS module is using udp. I discovered this because it would
periodically time out on our server -- requests would sometimes take 30s that
would normally take less than 1s. I'd like to use tcp for our use case in
order to avoid timeouts. However, that alone is not reason enough to ask
everyone else to use tcp. They may want udp. It is faster, right?

While playing with this, I found that on average tcp is repeatably faster than
udp for these kinds of requests.

See tcp:

  $ time python -c """
  import DNS
  DNS.DiscoverNameServers()
  [DNS.Request(name='_avatars._tcp.ralph.id.fedoraproject.org', qtype='SRV', protocol='tcp').req() for i in range(128)]
  """
  python -c 0.10s user 0.03s system 10% cpu 1.270 total

Versus udp:

  $ time python -c """
  import DNS
  DNS.DiscoverNameServers()
  [DNS.Request(name='_avatars._tcp.ralph.id.fedoraproject.org', qtype='SRV', protocol='udp').req() for i in range(128)]
  """
  python -c 0.24s user 0.11s system 3% cpu 9.514 total

Which makes it a more suitable default for libravatar.py, no?

To post a comment you must log in.
Revision history for this message
François Marier (fmarier) wrote :

Thanks!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'libravatar.py'
--- libravatar.py 2014-09-01 23:28:18 +0000
+++ libravatar.py 2015-06-26 18:40:19 +0000
@@ -165,7 +165,7 @@
165 DNS.DiscoverNameServers()165 DNS.DiscoverNameServers()
166 try:166 try:
167 dns_request = DNS.Request(name=service_name(domain, https),167 dns_request = DNS.Request(name=service_name(domain, https),
168 qtype='SRV').req()168 qtype='SRV', protocol='tcp').req()
169 except DNS.DNSError as message:169 except DNS.DNSError as message:
170 print("DNS Error: %s" % message)170 print("DNS Error: %s" % message)
171 return None171 return None

Subscribers

People subscribed via source and target branches

to all changes: