Hello, when I run getSignedUrl inside a cloud function it takes about 1 second, compared to 6ms on my local machine. I tried to set the memory to 2GB, but it still takes the same amount of time. Does anyone maybe have some other tweaks I could implement? Since I want to sign multiple download urls at once, it has a big impact on the overall processing. I managed to lower the response time a little bit by signing in parallel by using Promise.all, but sill takes too long.
Thank you
I think there is a small performance penalty for GCF at the initialization stage of our module. That is primarily due to the authentication step, where some time is spent determining how to get the credentials to authorize the request. Are you using the automatic authentication that happens in GCF or are you providing credentials manually?
Another thing to look at is where the require and instantiation of the client is. I believe the require should happen outside of the function and the instantiation inside.
@JustinBeckwith @bcoe does this sound right?
Thank you for your answer! I am using in production an auto assigned service account, instead of passing a keyFile. So maybe I could try to change this. And regarding the instantiation: I do require and am instatiating the storage outside a function, but in a different file.
@stephenplusplus I passed a keyFile also on production and the duration of signing the urls inside a cloud function went down to 120ms! Thank you for the hint. Now I just need to figure out how to distribute the key file securly to the cloud functions. Can I use some kind of keystore service maybe?
@stephenplusplus there's another potential speed up in this case.
The auth library is using an older version of SignBlob and should be using the newer version of SignBlob. A similar issue was hit in Java. In the case that the credentials file isn't passed along with the GCF it could instead use IAM SignBlob to sign the URL.
HTH
@mklan we've been working on some improvements to environment detection (as of yesterday we're caching credentials on their first request, which might improve lookup time). Want to try without the service account file, and see what your bootstrap time is looking like now?
@bcoe cool, I will try it when I will be deploying the next version and report back. thank you
@mklan Hi, we haven't heard back from you, so I went ahead and closed this issue for now. Feel free to reopen if @bcoe's solution didn't work out for you. Thank you!
Most helpful comment
@stephenplusplus there's another potential speed up in this case.
The auth library is using an older version of SignBlob and should be using the newer version of SignBlob. A similar issue was hit in Java. In the case that the credentials file isn't passed along with the GCF it could instead use IAM SignBlob to sign the URL.
HTH