CloudFlare Now Supports WebSockets But Not Without Challenges

WebSockets is supported by essentially all browsers (even the BlackBerry browser) and is being used more widely by developers. Its popularity is apparent in the news from CloudFlare, a CDN, which this week announced WebSockets support. According to the company, WebSockets support has been the most frequently requested feature by its customers.
CloudFlare’s Matthew Prince offers a nice explainer that provides a historical perspective on the functionality that WebSockets offers as well as an explanation of how CloudFlare managed to support it.
Hint: It wasn’t easy for CloudFlare to support WebSockets. The challenges that CloudFlare faced may help explain why it has taken and will continue to take a while for WebSockets to become more pervasive.
“The challenge was that WebSockets have a very different connection profile, and CloudFlare wasn’t originally optimized for that profile,” Prince writes. “WebSockets present new challenges because they require much longer lived connections than traditional web requests, and that required changes to our network stack.”
Prince goes into a fair amount of detail about how CloudFlare managed to accommodate WebSockets. In particular, he writes that they have set up a system that “instructs the operating system to be less conservative, and allows ports to be reused. You can do this when you set up a socket by setting the SO_REUSEADDR option.”
1 2 3 4 5 6 7 8 9 |
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) # Specify that it's ok to reuse the same port even if it's been used before s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) s.bind(("1.1.1.1", 0)) s.connect(("www.google.com", 80)) |
Given that developers want to support more types of information exchange, the use of WebSockets is likely to grow, despite the challenges. InfoWorld has a nice list of functions that WebSockets can help with—collecting more clickstream data, building high-performance games in a browser, pulling social feeds in automatically, and updating location data on the fly.
CloudFlare is rolling out WebSockets support to its enterprise customers and offering it as a beta to select business customers. Prince doesn’t specifically say whether it will become available to users of CloudFlare’s free tier, but he does say this: “Over the next few months, as we get a better sense for the demand and load this feature puts on our systems, we plan to expand support for WebSockets to more customers including those at other tiers of CloudFlare’s service.”
He also credits a CloudFlare engineer with pushing for WebSockets support. Marek Majkowsky “argued convincingly that WebSockets were part of the modern web, and it was critical that we find a way to protect and accelerate them,” Prince writes.
Feature image via Flickr Creative Commons