Node.js slower than Apache

前端 未结 6 909
误落风尘
误落风尘 2020-12-13 10:25

I am comparing performance of Node.js (0.5.1-pre) vs Apache (2.2.17) for a very simple scenario - serving a text file.

Here\'s the code I use for node server:

<
6条回答
  •  误落风尘
    2020-12-13 10:38

    Dynamic requests

    node.js is very good at handling at lot small dynamic requests(which can be hanging/long-polling). But it is not good at handling large buffers. Ryan Dahl(Author node.js) explained this one of his presentations. I recommend you to study these slides. I also watched this online somewhere.

    Garbage Collector

    As you can see from slide(13 from 45) it is bad at big buffers.

    Slide 15 from 45:

    V8 has a generational garbage collector. Moves objects around randomly. Node can’t get a pointer to raw string data to write to socket.

    Use Buffer

    Slide 16 from 45

    Using Node’s new Buffer object, the results change.

    Still not that good as for example nginx, but a lot better. Also these slides are pretty old so probably Ryan has even improved this.

    CDN

    Still I don't think you should be using node.js to host static files. You are probably better of hosting them on a CDN which is optimized for hosting static files. Some popular CDN's(some even free for) via WIKI.

    NGinx(+Memcached)

    If you don't want to use CDN to host your static files I recommend you to use Nginx with memcached instead which is very fast.

提交回复
热议问题