read

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:

1
2
3
4
5
   require('http').createServer(function (req, res) {  
    res.writeHead(200, { 'Content-Type': 'text/plain' });  
    res.end('Hello, world!');  
}).listen(process.env.PORT);
  

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:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
scenario  
{  
    name    = "default";  
   
    warmup      = 5;  
    duration    = 30;  
    cooldown    = 5;  
   
    default   
    {  
        setheader  
        {  
            name    = "Connection";  
            value   = "keep-alive";  
        }  
        close       = ka;  
    }  
       
    transaction  
    {  
        id = "hello";  
        weight = 1000;  
        request  
        {  
            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.

image

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:

image

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!

image

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.

Blog Logo

Tomasz Janczuk


Published

Image

Tomek on Software

Software - shaken, not stirred

Back to Overview