LinkedIn’s Shravya Garlapati has shared a number of tips for improving performance on their mobile site while using Node.js.
LinkedIn is working with a standard HTML5 mobile site as well as apps for iOS and Android. Previously, LinkedIn has talked about its continuous integration testing for mobile, now they’re sharing some of what they’ve learned.
The Obvious and Not so Much
A couple of the tips are fairly obvious. For example, make sure that you use gzip to compress requests and responses. Don’t use Node.js for static content like stylesheets or images. LinkedIn recommends and uses Nginx for its mobile site.
Another tip that (one hopes) is obvious? “Keep your code small and light.”
But LinkedIn also has a few insights that might not be obvious. For example, Garlapati recommends turning off Node.js socket pooling. “The Node.js http client automatically uses socket pooling: by default, this limits you to 5 sockets per host. While the socket reuse may keep resource growth under control, it will be a serious bottleneck if you need to handle many concurrent requests that all need data from the same host.”
Garlapati also recommends using binary modules with Node.js, and standard V8 JavaScript rather than client-side libraries. “Client-side libraries usually have a lot of inefficient code to overcome browser differences,” says Garlapati. “On the other hand, in Node.js, you know exactly what JavaScript functions are available: the V8 JavaScript engine that powers Node.js implements ECMAScript as specified in ECMA-262, 5th edition. By directly using the standard V8 functions instead of client libraries, you may see significant performance gains.”
Any Node.js tips or tricks that LinkedIn has missed?