A Speedy Web

May 28, 2014

At Scribe Inc., we are constantly working to better the experience of our clients. Because our internal staff and (Well-Formed Document Workflow) WFDW clients both rely heavily on our web applications, we strive to improve the effectiveness of these services. Since the release of our newest platform, we've migrated from Apache to Nginx.

Nginx

Scribe's transition to Nginx allows for a significant increase in web server performance while consuming less memory and process overhead than Apache. We've also found the configuration of Nginx both powerful and understandable.

During this migration, our new web applications were deployed in an SSL-only environment to protect our client's data. But like any complicated web application, the many individual HTTP connections required for a single page were beginning to result in a performance penalty.

Recently, I received a call from our president, David Alan Rech, asking about possible performance difficulties. While the problem was ultimately a local internet issue on his end, the notion of improving our performance, given the requirements of our web applications, resulted in some additional research on my part.

SPDY

SPDY (pronounced speedy) is a network protocol developed primarily by Google. Its intention is to improve load latency and security. For Scribe's needs, the most important aspects of this protocol are compression, multiplexing, and prioritization.

In a regular HTTP request, when a user client (such as Firefox or Chrome) requests a web page (such as scribenet.com), an HTTP request is initiated with the server. As the user client reads the page HTML, it creates new HTTP requests for each resource on the page—every image, style sheet, and JavaScript resource. This leads to upward of ten to fifteen HTTP requests for each individual page.

It is important to realize that each additional HTTP request increases the overhead of a page load. The more assets a page has, the higher the perceived latency.

SPDY works to mitigate these costs by effectively acting as a tunnel for HTTP traffic and modifying the way HTTP requests and responses are sent. This includes prioritizing and multiplexing the transfer of resources so only one connection per client is required. It also compresses HTTP headers using gzip or DEFLATE compression.

SPDY does not operate over unencrypted HTTP requests, requiring a server that responds to HTTPS requests and supports TLS with the NPN extension. This is done by design for security and to mitigate any problems when communicating across a proxy.

Setup

To enable SPDY within Nginx, you will need to have a version of Nginx greater than 1.5.1 with the spdy module enabled. On Ubuntu, I highly recommend using the official Nginx Launchpad PPA. At this time, the stable channel offers version 1.6 of Nginx on Ubuntu 12.04.1 LTS.

To add the PPA and install version 1.6.x of Nginx on your Ubuntu server, issue the following commands:

sudo add-apt-repository ppa:nginx/stable
sudo apt-get update
sudo apt-get install nginx

Once you have configured Nginx for your particular setup (which is beyond the scope of this article), enabling SPDY support is easy. Within the server block of your site configuration file, change the line

listen 443 ssl;

to

listen 443 ssl spdy;

Once you have completed this, you must reload your Nginx configuration. This can be accomplished using the following command:

sudo service nginx reload

Testing

Please note: This testing procedure relies on using Chrome/Chromium. While Firefox and Opera likely offer a similar interface, this article will focus on using Chrome/Chromium.

First, open a new tab in Chrome and enter the following URL

chrome://net-internals/#spdy

Then navigate to your website (if you haven't setup Nginx yet, for the purpose of this tutorial, you may use scribenet.com). Once you have loaded your website, navigate back to the tab you previously opened and you will see your domain within the list of SPDY sessions.

Conclusion

In our internal testing, page load improved upward of 25 percent—a substantial percentage! We estimate the perceived latency decrease will be even greater.

SPDY is currently enabled on the majority of Google web servers and a percentage of Twitter and Facebook servers. It is also being used by the Internet Engineering Task Force as the baseline for the working draft of HTTP 2.0. As such, its usage will likely continue to increase as it becomes a standardized protocol.

Rob Frawley 2nd Gravatar Profile Picture

Rob Frawley 2nd
Systems Architect, Scribe Inc.
rmf@scribe.tools

Blog Archive