Search code examples
node.jscontrollersails.jswaterline

Node module not using sufficiant CPU ressources


I have a controller that is fetching some information to a dashboard page. It's having to handle a lot of information as we're using the populate() function of waterline (we're using sails.js) which is practically calling the whole database. Apart from the fact that the module needs to be rewritten to perform better, I'm wondering why it's not using more of the available CPU and RAM to work faster. I'm monitoring CPU and RAM usage on my Cloud VPS server and It's only using less than 10% CPU and less than 50% of RAM all the time. So my question is simple: why is the controller not using more CPU even though it's taking more than 15 seconds to render?


Solution

  • Usually Node.js (or Sails.js) tries to do its best to use as much CPU and RAM as needed to perform perfectly.

    So instead of thinking about the CPU ressources, try to revise a little bit your code. Maybe you have some loops that need a lot of time to execute or you are sending a lot of data to be rendered in the views.

    Try also to not use <%- exposeLocalsToBrowser() %> if not needed. Otherwise you will find yourself sending your local variables to the client-side (user's browser) and this can take a lot of time..