Skip to content

Instantly share code, notes, and snippets.

@brikis98
Created December 1, 2011 00:45
Show Gist options
  • Save brikis98/1412326 to your computer and use it in GitHub Desktop.
Save brikis98/1412326 to your computer and use it in GitHub Desktop.
Node.js performance tips
// Use built in or binary modules
var crypto = require('crypto');
var hash = crypto.createHmac("sha1",key).update(signatureBase).digest("base64");
// Disable socket pooling
var http = require('http');
var options = {.....};
options.agent = false;
var req = http.request(options)
app.use(express.session({ secret: "keyboard cat" }));
<!-- An example of a JavaScript template that can be rendered client side -->
<!DOCTYPE html>
<html>
<head>
<title>LinkedIn Mobile</title>
</head>
<body>
<div class="header">
<img src="http://mobile-cdn.linkedin.com/images/linkedin.png" alt="LinkedIn"/>
</div>
<div class="body">
Hello <%= name %>!
</div>
</body>
</html>
{"name": "John"}
<!-- An example of a simple webpage rendered entirely server side -->
<!DOCTYPE html>
<html>
<head>
<title>LinkedIn Mobile</title>
</head>
<body>
<div class="header">
<img src="http://mobile-cdn.linkedin.com/images/linkedin.png" alt="LinkedIn"/>
</div>
<div class="body">
Hello John!
</div>
</body>
</html>
// Good: write files asynchronously
fs.writeFile('message.txt', 'Hello Node', function (err) {
console.log("It's saved and the server remains responsive!");
});
// BAD: write files synchronously
fs.writeFileSync('message.txt', 'Hello Node');
console.log("It's saved, but you just blocked ALL requests!");
@tj
Copy link

tj commented Dec 5, 2011

well that depends how you cache, they wont always issue conditional gets. just seems a little weird to me I guess but thanks! was curious

@talentedmrjones
Copy link

For DisableSocketPooling, does that affect http.createServer() or in the case of express, app.listen()? I tried adding that to an express app and got:
Error: connect ECONNREFUSED
Any ideas?

@tj
Copy link

tj commented Dec 6, 2011

that's for the http client

@kevbook
Copy link

kevbook commented Feb 15, 2012

How to render HTML on client side and serve it with cdn?

@phegaro
Copy link

phegaro commented Feb 17, 2012

@talentedmrjones: This is on the httpclient not on the server. This allows you to talk to the same host without using pooling
@kevbook: You can use underscore or dust or any js templating system to render on client and have the templates sitting in CDN

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment