Sunday, April 22, 2012

Getting Started with SPDY v3

‹prev | My Chain | next›

Up tonight, I would like to experiment a bit with SPDY version 3. Much of the research that went into SPDY Book was based on the draft for version 3, but all of the code was written for version 2.

I seem to recall hearing mention that someone had started work on version 3 support in node-spdy, but I see nothing in the fork graph in GitHub. So I start on my own. First up, I link my locally cloned node-spdy so that npm will use it rather than trying to download it from the network:
➜  express-spdy-test  cd ~/repos/node-spdy
➜  node-spdy git:(master) npm link
mocha@0.10.2 ./node_modules/mocha
├── growl@1.4.1
├── debug@0.6.0
└── commander@0.5.2
../../local/node-v0.7.7/lib/node_modules/spdy -> /home/chris/repos/node-spdy
Then, in my simple express.js + SPDY site from the other night, I complete the link:
➜  node-spdy git:(master) cd ~/tmp/express-spdy-test
➜  express-spdy-test  npm link spdy
./node_modules/spdy -> /home/chris/local/node-v0.7.7/lib/node_modules/spdy -> /home/chris/repos/node-spdy
➜  express-spdy-test  npm ls
application-name@0.0.1 /home/chris/tmp/express-spdy-test
├─┬ connect@2.1.2 
│ └── ....
├─┬ express@2.5.9
│ └── ...
├─┬ jade@0.24.0
│ ├── ...
└─┬ spdy@1.2.0 -> /home/chris/repos/node-spdy
I really love that npm makes it easy to use packages as I develop like that.

It seems that Fedor Indutny has anticipated the next version of SPDY in that the current node-spdy has a v2 directory:
➜  node-spdy git:(master) ✗ ls -1 lib/spdy/protocol
And the code itself also looks to anticipate newer versions:
// lib/spdy.js
// Only SPDY v2 is supported now
spdy.protocol[2] = require('./spdy/protocol/v2');
The first thing to do is copy v2 to v3 in the file system and to add version 3 to lib/spdy.js:
// Supported SPDY versions
spdy.protocol[2] = require('./spdy/protocol/v2');
spdy.protocol[3] = require('./spdy/protocol/v3');
After verifying that this still works, I am ready to try out SPDY v3. I would tend to doubt that it would work without changes, but I need to start somewhere. In chrome://flags/, I enable SPDY v3:

I also need to relaunch:

I then reload the page to see... that I am still talking spdy/2 according to the SPDY tab in chrome://net-internals.

The good news is that Chrome does seem to be SPDY v3 ready. The bad news should be fixed by one more tweak to node-spdy—adding spdy/3 to the list of advertised protocols:
function Server(options, requestListener) {
    if (!options) options = {};
    if (!options.maxStreams) options.maxStreams = 100;
    options.NPNProtocols = ['spdy/3', 'spdy/2', 'http/1.1', 'http/1.0'];
Unfortunately, after restarting the server, I get variations of server unavailable or empty response:

Ah well. It was a bit much to expect this to work immediately. I call it a night here and will pick back up tomorrow inspecting packets in Wireshark.

Day #364

No comments:

Post a Comment