简体   繁体   中英

gcloud module loading is slow

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.

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 require s, 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)?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM