Search code examples
node.jsexpressserver

How do Node.js modules affect server bandwidth?


I'm working on an Express.js application and I would like to use Socket.io, but I am worried about how using this module (and other Node.js modules) might impact the network traffic. The socket.io.js script that needs to be sent to the client browser is over 215 KiB. If the network can support 1 GiB/s, then even if all the network bandwidth was used just to service this one file, only around 4800 requests/second could be supported. I know the user's browser will cache this file so that it doesn't need to be resent during the user's session, and I know that Express.js encourages using the compression middleware, which can reduce file sizes. However I am wondering what other optimizations production-level systems might consider, if any. I'm sure the scripts could be pared down to just relevant functionality, but I'm not sure there would be any significant performance benefit (especially for the amount of time/effort this would probably take). I'm not worried about the bandwidth impact for the "steady-state" requests, but more for when there is a large spike in requests/second.


Solution

  • I suggest using a CDN as this will reduce the load going into your servers instead of serving public libraries on your servers as well.

    According to CDNPerf, the fastest CDNs to use (for socket.io, etc.) are:

    By using a CDN, the client will now request any public libraries you're using from them instead, thus reducing the traffic going to your servers.