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

Spawning process for every parallel request results in high CPU usage #1202

Closed
richardscarrott opened this issue Jul 27, 2021 · 2 comments · Fixed by #1205
Closed

Spawning process for every parallel request results in high CPU usage #1202

richardscarrott opened this issue Jul 27, 2021 · 2 comments · Fixed by #1205

Comments

@richardscarrott
Copy link

richardscarrott commented Jul 27, 2021

So this issue was raised a while back but there wasn't any reproduction steps which I guess is why it was closed.

I was profiling our node server and noticed from cold one of our APIs was spending a lot of time in the stripe SDK.

Here's a contrived way to reproduce the issue:

const paymentIntentIds = new Array(50).fill('pi_123');
await Promise.all(paymentIntentIds.map(id => stripe.paymentIntents.retrieve(id));

If run from cold (i.e. without having made a prior call to the SDK), it will spawn a new process for all 50 of the above requests because the getClientUserAgent caching is a little naive.

You can see the difference between a cold call:
Screenshot 2021-07-27 at 18 11 51

And a 2nd warm call:
Screenshot 2021-07-27 at 18 12 57

If you're wondering why one might be making so many parallel requests at once, our use case is fetching a page of orders in our DB which all have a FK reference to a payment intent in stripe (we don't currently replicate the payment intents in our DB) and unlike older stripe resources, there's no batch endpoint for payment intents AFAIK.

I discovered the issue in 7.5.3 but can also reproduce in v8.165.0.

@richardscarrott
Copy link
Author

richardscarrott commented Jul 28, 2021

In the meantime, I've patched our stripe client with:

Stripe.prototype.getClientUserAgent = cb =>
  cb('HACK: https://github.com/stripe/stripe-node/issues/1202');

Hopefully won't cause any problems with the telemetry on your end?

@richardm-stripe
Copy link
Contributor

Hello @richardscarrott, thank you for the report and the great detective work. A fix for this in #1205 has been merged and will be released soon.

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

Successfully merging a pull request may close this issue.

2 participants