基本策略
Socket Pool –Generic Pool
var poolModule = require('generic-pool');
var pool = poolModule.Pool({
name : 'mysql',
create : function(callback){
var Client = require('mysql').Client;
var c = new Client();
…
},
destroy : function(client){
client.end();
},
max : Cfg.maxSockets,
idleTimeoutMillis : Cfg.timeout
});
8.
基本策略
Cluster
Multi-Worker-Listen
Master.send(listenfd)
Worker.listen(…)
Master.close(listenfd);
Master-Listen (we use this for fully control)
Master.listen()
Master.send(sockfd)
Worker.receive(sockfd)
CreateReqRes(sockfd)
Stardard
JS has many pitfalls
Async mode is tricky
For fluent team cooperation
We are designing a server on our own
The server is a long-time running programe
We need helps from community
…
Stardard is a MUST !!!
21.
Stardard
We need YOUR contribution!
减少外部依赖,谨慎选择开源模块
面向接口编程,不管内部实现如何,接口定义要简洁、清晰、固定
对于复杂的逻辑运算,不仅要有Unit Test,还要有相应的Benchmark Test
对于外部的网络请求,一定也要有相应的benchmark test,摸清其 qps,
response time, CPU 耗费
对于异步回调函数,一定要检查其是否错误,即第一个回调参数,并做相应处理
谨慎使用 fs 同步操作函数组---除非你清楚知道其不会造成严重后果
…
https://github.com/windyrobin/iFrame/blob/master/style.md
https://github.com/windyrobin/iFrame/blob/master/pp.md
https://github.com/windyrobin/iFrame/blob/master/mng.md