Increase throughput of a node.js application with IIS output caching

Hero Image

One of the benefits of hosting node.js applications in IIS on Windows using iisnode is that you can use the functionality of the many IIS modules for greater utility and improved performance. I have already talked about using the URL rewrite module to improve the performance of node.js applications that serve some static content. In this post I will show how IIS output caching can dramatically improve the throughput of your node.js application without any changes in the application itself.

What is IIS output caching

IIS output caching provides a mechanism to capture the HTTP response generated by the web application (a node.js application in this case) and very efficiently serve it for subsequent HTTP requests that match it. The response is cached for a specified duration after which the cache will be cleared, and the subsequent request will cause the node.js application to generate a fresh request.

You can benefit from IIS output caching if the content served by your node.js application does not require immediate, request by request updates. Even if you can cache the response for just 1 second, IIS output caching can provide dramatic improvements in throughput.

Show me the numbers

For the simple, unscientific benchmark, I will use a “hello world” application in node.js:

   require('http').createServer(function (req, res) {  
    res.writeHead(200, { 'Content-Type': 'text/plain' });  
    res.end('Hello, world!');  

I will then host the application in IIS using iisnode, and measure its throughput using the WCAT stress testing tool. The WCAT test configuration specifies that we will be repeatedly calling the the node.js application above with Connection: keep-alive for consecutive 30 seconds:

    name    = "default";  
    warmup      = 5;  
    duration    = 30;  
    cooldown    = 5;  
            name    = "Connection";  
            value   = "keep-alive";  
        close       = ka;  
        id = "hello";  
        weight = 1000;  
            url = "/node/helloworld/hello.js";  

Note that I am running both client and server on the same machine so the results are highly unscientific. However, we are only going to use them for relative comparison between lack of caching and presence of caching to get a high level idea of the benefits.

Running the WCAT configuration above with 100 virtual clients for 30 seconds results in a throughput of about 4000 requests/second.


Now let’s add IIS output caching. Using IIS Management Console, we will configure IIS output caching for the node.js application such that responses are cached for 1 second:


And then re-run the WCAT test with the same configuration. This time we see the throughput has increased to 35500 requests/second, a 875% improvement over the non-cached configuration!


The conclusion

If your node.js application hosted in iisnode serves content which can be cached for even short periods (e.g. 1 second), you can realize very substantial throughput improvement by using IIS output caching.


Related Content

2 February 2022
fetch() In Node.js Core: Why You Should Care

Node 17.5 introduces support for the fetch() HTTP client, a new way to send requests to HTTP APIs.

23 February 2022
Node.js Adds Support for Direct Registry-less HTTPS Imports

Node is planning to introduce support for HTTPS imports in Node 18 - a feature that enables you to use urls to directly import modules over HTTPS into your project.

15 February 2022
Run Every Node.js Version in AWS Lambda

Run any version of Node.js in AWS Lambda within hours after release using custom AWS Lambda runtimes from Fusebit