Apache/Server X forwarding to node.js performance
I am starting to work with node.js to build a light-weight, high-demand REST platform to build some in-house apps off of. One issue relates to my development environment and having Apache and node.js co-exist. No issue in having them co-exist, as there are lots of posts on how to 'share' port 80 via having Apache redirect requests to node:
And node proxying to Apache:
One question that seems to go wanting however relates to the performance 'hit' when proxying, specifically when using Apache to proxy node. While my production environment will be a pure node.js solution listening on port 80, in theory wouldn't having Apache step in and handle the initial I/O pretty much defeat most of the performance benefits of using node.js, from the I/O perspective? If this box is getting thousands of requests, long-polling, etc would the Apache redirects not be spawning many many threads, that then pass off to the single-threaded node.js?
As I said, new to node, so just trying to get my head around this issue moving forward.
You got the basic idea right.
Having Apache handling the requests first make it part of the chain and if it is the weakest link in the chain it could slow down you application.
In standard configuration Apache is not slow if the number of concurrent requests is low, but the more request are handled the more RAM is used by the Apache. If you are using some persistent connections you could easily hit some limits there.
Apache has different MPM (Multi-processing modules). By default it uses mpm_prefork which is known to be memory hungry (one thread per connection). You could switch to mpm_worker which uses a similar model as node.js to handle connections is is more suitable for the kind of task you try to archive. (evented connection handling, but it has some quirks with other modules [like mod_php] to not be thread-safe anymore.)
As always the best solution would be: Try different things, make some benchmarks and take what works best for you.