一段经典的node.js 数据库高并发实现

var proxy = new EventProxy();
var status = "ready";
var select = function(callback){
proxy.once("selected",callback);
if(status == "ready"){
status = "pending";
db.select("SQL", function(results){
proxy.emit("selected",results);
status = "ready";
});
}


网上摘的,看得懂么。短短几行代码。功效 perfect!
在一条sql执行的时间内,如果来了1000条访问请求,那么一次查询结果将返回给1000条请求,node.js 高并发可见一斑。

 

相关参考资料
http://blog.csdn.net/aoyzc/article/details/8272162
http://www.infoq.com/cn/articles/tyq-nodejs-event

posted @ 2016-07-22 08:38  yuan.net  阅读(1253)  评论(0编辑  收藏  举报