Blazing fast node.js: 10 performance tips from LinkedIn Mobile

Shravya Garlapati
6 min readintermediate
--
View Original

Overview

The article provides ten performance optimization tips for Node.js applications, specifically derived from LinkedIn's mobile server experience. It emphasizes the importance of asynchronous programming, efficient resource management, and leveraging external tools for static content delivery.

What You'll Learn

1

How to avoid synchronous code in Node.js applications

2

Why socket pooling can be a bottleneck in high-concurrency scenarios

3

When to use a standard web server for serving static assets

4

How to implement client-side rendering for better performance

5

How to use gzip for compressing requests and responses

Key Questions Answered

How can I improve the performance of my Node.js application?
To improve Node.js performance, avoid synchronous code, turn off socket pooling, and use a standard web server for static assets. Additionally, consider client-side rendering, utilize gzip for compression, and keep your code lightweight. These strategies help manage resources effectively and enhance response times.
What are the benefits of using binary modules in Node.js?
Using binary modules instead of JavaScript modules can lead to significant performance improvements. For example, switching from a JavaScript SHA module to the compiled version provided by Node.js resulted in a notable performance boost, demonstrating the efficiency of binary over interpreted code.
Why is it recommended to render on the client-side?
Client-side rendering allows for sending only dynamic data as JSON while serving static HTML from a JavaScript template. This approach reduces server load and improves performance by minimizing the amount of data sent over the network after the initial load.
When should I turn off socket pooling in Node.js?
Socket pooling should be turned off or adjusted when handling many concurrent requests to the same host. By default, Node.js limits to 5 sockets per host, which can become a bottleneck in high-demand scenarios, necessitating a configuration change to improve throughput.

Key Statistics & Figures

Performance drop due to synchronous calls
From thousands of requests per second to just a few dozen
This drastic reduction highlights the critical impact of synchronous operations in a Node.js environment.

Technologies & Tools

Some links below are affiliate links. We may earn a commission if you make a purchase.

Key Actionable Insights

1
Avoid using synchronous code in your Node.js applications to maintain high performance.
Since Node.js operates on a single-threaded model, blocking calls can severely degrade performance. Always prefer asynchronous methods to ensure your application can handle multiple requests efficiently.
2
Utilize a standard web server like nginx for serving static assets instead of Node.js.
This offloads the work from your Node.js server, allowing it to focus on dynamic requests and improving overall application responsiveness.
3
Implement client-side rendering to reduce server load and enhance user experience.
By sending only the necessary dynamic data as JSON and caching static templates, you can significantly decrease the amount of data transferred and improve load times for users.
4
Use gzip compression for both requests and responses to optimize network performance.
Gzip is widely supported and can drastically reduce the size of data transmitted, leading to faster load times and reduced bandwidth usage.

Common Pitfalls

1
Using synchronous/blocking calls in Node.js applications can lead to severe performance issues.
This happens because Node.js is designed to be asynchronous, and blocking the event loop can prevent it from handling multiple requests, resulting in significant slowdowns.

Related Concepts

Asynchronous Programming In Node.js
Performance Optimization Techniques
Static Asset Management
Client-side Rendering Strategies