Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix auth performance degradation in >= v0.14.0 / cache Google auth client per config #674

Closed
robertdimarco opened this issue Jun 18, 2015 · 2 comments
Assignees

Comments

@robertdimarco
Copy link
Contributor

The v0.14.0 release of this module included a change in the underlying dependency used for Google authentication, from the google-service-account module to google-auth-library (see eae1b7d). During routine service benchmarking as part of our upgrade to v0.15.0, I noticed a 50% decrease in throughput for our proxy server when asked to serve 10k small files.

A super-simple example is shown below, which directly calls into utils.makeAuthorizedRequest(...). This script makes 100 requests to GCS for file metadata, serially, and exits on completion. On v0.13.2, this script successfully completes in ~20-25 seconds, while in v0.14.0 and v0.15.0 it completes in ~45-50 seconds.

var util = require('./node_modules/gcloud/lib/common/util.js')

var config = {
  keyFile: "[redacted]",
  projectId: "[redacted]",
  scopes: [ 'https://www.googleapis.com/auth/devstorage.full_control' ]
};

var reqOpts = { method: 'GET', qs: null, uri: '[redacted]', json: true };

var makeAuthorizedRequest;
if (util.makeAuthorizedRequestFactory) { // >= v0.14.0
  makeAuthorizedRequest = util.makeAuthorizedRequestFactory(config)
} else { // v0.13.2
  makeAuthorizedRequest = util.makeAuthorizedRequest(config)
}

var n = 100;
function next() {
  if (n > 0) {
    run(function() {
      setTimeout(next, 0);
    });
  } else {
    process.exit();
  }
}
function run(cb) {
  if (n > 0) {
    makeAuthorizedRequest(reqOpts, function(err, resp, req) {
      if (err) {
        console.error(err);
        process.exit(1);
      }
      cb();
    })
  }
}
next();

This difference is fully accounted for through additional time spent in util.authorizeRequest(...). On v0.13.2, the call to authorize(...) is essentially a no-op if you are using a service account credential, and network I/O is not required.

This is caused by creating a new instance of GoogleAuth in util.getAuthClient(...), effectively blowing away the cached bearer token and causing a new one to be generated for each request.

I'll follow-up with a PR addressing this issue in the next 24 hours.

@ryanseys
Copy link
Contributor

Take a look at #661. It might be what you're referring to. Let us know if/if not that's the case.

@robertdimarco
Copy link
Contributor Author

@ryanseys Ah yes, that's it! Apologies for not seeing it. I'll close this out as a dupe.

sofisl pushed a commit that referenced this issue Oct 11, 2022
🤖 I have created a release *beep* *boop*
---


## [5.0.1](googleapis/nodejs-language@v5.0.0...v5.0.1) (2022-06-30)


### Bug Fixes

* **docs:** describe fallback rest option ([#673](googleapis/nodejs-language#673)) ([6767804](googleapis/nodejs-language@6767804))

---
This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
sofisl pushed a commit that referenced this issue Oct 13, 2022
🤖 I have created a release *beep* *boop*
---


## [5.0.1](googleapis/nodejs-language@v5.0.0...v5.0.1) (2022-06-30)


### Bug Fixes

* **docs:** describe fallback rest option ([#673](googleapis/nodejs-language#673)) ([6767804](googleapis/nodejs-language@6767804))

---
This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
sofisl pushed a commit that referenced this issue Nov 17, 2022
Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants