Friday 11:30 a.m.–noon
Kneel And Disconnect: Getting The Fastest Connection Out Of A Hostname
Ashwini Oruganti
- Audience level:
- Intermediate
- Category:
- Python Libraries
Description
Abstract
Meet HostnameEndpoint
- it takes a hostname, does a getaddrinfo
lookup on it, picks the first IPv4 and IPv6 address out of the returned list, and then using a time-involving algorithm, tries connecting to both of them. It then gives you the connection that is established first, discarding the other one. All this sounds like it would take a lot of time, but here’s the interesting part: it does not.
In this talk, I aim to walk you through the development of HostnameEndpoint
, right from the beginning till its successful merge to the Twisted codebase.
I’ll begin by talking about the use of time-related functions in Twisted, and how one can write fast and predictable tests for them. I’ll also tell you how Twisted performs multiple network operations “in parallel” (no, not threads), and how that’s what the reactor’s job is, essentially.
As we progress, I’ll discuss the design decisions involved in the development of this endpoint and the important lessons on unit testing and test-driven development I learnt. I’ll then take you through the exciting journey of writing Twisted code, illustrate how the frightening Deferreds can be tamed to do your bidding, the ample number of times I found roadblocks and how I pushed them all away to put everything together and make it work.
Finally, I'll show you how it’s still not perfect and could be improved further – largely by starting over with some parts of the code.