翻译--Blazing fast node.js: 10 performance tips from LinkedIn Mobile
来源:互联网 发布:2003网络歌手名单大全 编辑:程序博客网 时间:2024/06/05 09:03
1.避免使用同步代码:
// Good: write files asynchronouslyfs.writeFile('message.txt', 'Hello Node', function (err) { console.log("It's saved and the server remains responsive!");}); // BAD: write files synchronouslyfs.writeFileSync('message.txt', 'Hello Node');console.log("It's saved, but you just blocked ALL requests!");
code 的github地址
2.关闭sockect池:
nodejs的http客户端会自动的使用sockect池,默认情况下,每一台主机限制你最多使用5个sockect连接,sockect重用能保持很多的资源能够在一定范围内重用,如果你想控制从相同主机取数据的大量请求,这会有很多的瓶颈。在这种情况下,一个很好的办法是提高maxSockets 的值或者是彻底的关闭sockect池
var http = require('http');var options = {.....};options.agent = false;var req = http.request(options)
code的github 地址
3.不要使用nodejs 做静态资源存储
4.在客户端渲染页面
5.使用gzip压缩
6.并行
试着去处理你的所有阻碍操作,也就是说,并行请求你的远程服务,数据库调用,文件访问,这个将会减少潜在的最慢的请求,而不是所有的在一个队列中的总和时间,为了保持比较好的控制回调和错误信息,我建议step 框架去做工作流控制
7.session 空闲
LinkedIn mobile 使用express 框架控制请求和响应,很多的express 例子中都包含了如下的配置
app.use(express.session({ secret: "keyboard cat" }));
一般地,session 数据是存储在内存中,这个将会导致系统开销,特别是有很多的用户组,当然你也可以使用外部的session 存储,比如说MongoDB or Redis,但是这样做的话,就会导致远程请求session 数据的系统开销。当然,如果可能,最好的选项是不在服务端存储session数据。在express 框架中不要包含上述配置你将得到更好的性能。
8.使用二进制模块
如果可能的话,尽量使用二进制模块,而不使用javascript 库,例如:当我们使用SHA模块转换的话,我们将看到有更好的性能。
// Use built in or binary modulesvar crypto = require('crypto');var hash = crypto.createHmac("sha1",key).update(signatureBase).digest("base64");
9.使用标准的V8而不是使用客户端的库
10.保持你的代码小而简洁
时不时的问问自己这几个问题:
1.我真的需要这个模块吗?
2.我为什么要使用这个框架?
3.这个系统开销值得吗?
4.我是否可以用一个更简单的方式去实现这个?
- Blazing fast node.js: 10 performance tips from LinkedIn Mobile
- 翻译--Blazing fast node.js: 10 performance tips from LinkedIn Mobile
- 高性能Node.js:来自LinkedIn Mobile的10条优化建议
- Tips for optimizing mobile graphic performance
- From LinkedIn
- 46 Tips & Tricks for 2D mobile Performance in Unity
- Top 10 WPF Performance Tips
- 极速Node.js:来自LinkedIn的10个性能提升秘籍
- 极速Node.js:来自LinkedIn的10个性能提升秘籍
- 10个最佳Node.js企业应用案例:从Uber到LinkedIn
- Unity3D翻译——Performance Tips when Writing Shaders
- Performance Tips —— Android 官方文档翻译<二>
- Performance tips
- 10 Tips for Flex Application Performance
- C++ Performance Tips
- ASP.NET Performance Tips
- Documentum Performance Tips
- Python Performance Tips
- Java内存溢出的详细解决方案
- php笔记(5) 数组GET
- 工欲善其事必先利其器之Chrome浏览器的快捷键
- STL,ATL,WTL之间的联系和区别
- centos 6.4 系统CPU,内存,负载,IO监控脚本
- 翻译--Blazing fast node.js: 10 performance tips from LinkedIn Mobile
- android简单的进程间通信
- 针对UI给出的背景颜色和透明度#ba9163 35%透明度该如何设置
- Java Heap sapce 与 Java PermGen space
- Element type "action" must be followed by either attribute specifications, ">" or "/>".
- GOODSTUDY
- hadoop介绍以及高人指点的学习方法
- Oracle10gRAC(102040)打PSU 102044
- Andorid API TestDemo 解析