MetacogniTV

Thinking about thinking.

Websockets With Nginx + SSL. Also, Benchmarks

After weeks of following the nginx roadmap for news about websockets support, I was ecstatic to see the newest changeset had some simple intructions on how to implement them.

I have an example of a websocket + ssl server running right now at: https://legionofevil.org

If you want to see the code, go ahead an skip these benchmarks.

Very Coarse Benchmarks

Previously, I was using xhr-polling with socket.io and was getting latency readings of about 120ms. My friends in the US were getting a 60ms lag reading (the server is in Utah, while I’m in British Columbia).

After recompiling nginx from the trunk source, I got speedups to about 55ms, which is half of what I was getting before. My US friends also reported a latency of 35ms.

So, ya. It’s worth an upgrade if you’re working with ssl.

Instructions

The app at legionofevil is actually running mana.js, a 2d online mmorpg based on melon.js. The server is running Node.js and Socket.io. I’m also graphing latency on the top of the page.

Here’s a gist of my node server:

And the Nginx conf:

A couple of things to note here:

  • Socket.io is automaticaly sending an “Upgrade” header for websockets.
  • You don’t need to specify wss:// in your nginx configuration. As long as socket.io can upgrade to Http1.1, you should be fine.

I’ll be updating this entry with more info, but I’m sure this should get any intrepid hackers going.