1

I'm using gcloud nodejs module. Whenever I make changes, nodeJS will reload (using nodemon) and it has to load all the dependencies. Everything is fast, except when it comes to gcloud. It takes considerable amount of time (like 10-20 seconds) for loading only that module.

All I did is:

console.log('Loading gCloud Module');
var gcloud = require('gcloud');
console.log('Done.');

Why is that? I'm running NodeJs 4.1.1. gcloud - 0.21.0.

Nekresh
  • 2,948
  • 23
  • 28
viji
  • 2,706
  • 5
  • 28
  • 34

1 Answers1

0

I tried this with the following code:

> node
console.time(); require('gcloud'); console.timeEnd();

The first time I ran it, I got almost 10 seconds. Every time after, I got around 900ms-2.5s. I've tried various gcloud versions, as well as Node versions, and received minor differences.

I started digging into what specific dependency is taking the most time. I found various leads: google-auto-auth takes around 375ms. But really, it's a dependency of that; google-auth-library-nodejs that took up 370ms of the time. So I dug into that and found its dependency gtoken takes about 366ms. One of its dependencies, node-forge, takes 120ms and another one took most of the rest.

Basically, because gcloud has so many dependencies, it has to resolve many sync requires, which means walking the file system and blocking all the while. Without modularizing, for a library of its size and scope, I'm not sure what can be done that would make a huge difference to the start-up time.

Running npm dedupe might make a small difference.

If you are consistently seeing 10-20 seconds, that's interesting. Could you share more about the system the script is running on? And could you try upgrading to the latest gcloud (0.23)?

Stephen
  • 5,710
  • 1
  • 24
  • 32
  • Thanks Stephen for your answer. I'm running Ubuntu 14.04 in a VM, which is created through vagrant. My host is Windows 10. My nodejs app folder is in windows which is shared with the Ubuntu VM. I'll check out whether it takes this much time on a non-shared folder or not. – viji Oct 04 '15 at 21:24