-2

I'm a web apps developer, I use for most apps PHP/MySQL with APC enabled, caching technologies: Memcached is my favorite one. Sometimes I use Percona MySQL version.

I'm new to NodeJS and I want to build my own web app using it. It's a SaaS working with Facebook, Twitter and Instagram APIs. I read a lot of good things about it.

What I need to know about Asynchronous JS Programming before starting the app?

Is there any performance advantages for Asynchronous Programming?

Is there any live examples, graphs with the difference between Async/Sync?

4

1 回答 1

2

它不会阻塞。

让我们比较一下PHP

<?
    readfile('some/large/file.bin');
?>

这可能需要一段时间。并且在PHP读取文件时,它不能做其他事情(比如回答其他请求)。

同样的事情异步(使用node.js):

fs.readFile('/some/large/file.bin', function callback);

Node 在没有blocking当前进程的情况下进行读取。

总而言之:虽然synchronous方法会阻塞过程直到结果可用,但asynchronous方法具有做其他事情的优势,甚至在readFile callback被解雇之前。

于 2013-06-08T23:26:48.360 回答