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

excessive CPU usage warning from Vercel for middleware #45

Closed
nibtime opened this issue Jul 12, 2022 · 1 comment · Fixed by #51
Closed

excessive CPU usage warning from Vercel for middleware #45

nibtime opened this issue Jul 12, 2022 · 1 comment · Fixed by #51

Comments

@nibtime
Copy link
Owner

nibtime commented Jul 12, 2022

Just checked my emails and received a warning from Vercel about excessive CPU usage of middleware, both on my hobby account and a Pro Team account. For middleware, there is a limit of 50ms CPU execution time per request, on average

I merged the release commit for 0.8.0 on Jul 7, 2022 at 6:13PM (UTC), with also redeployed the e2e app with the new version.

Strange though is, that the avg. CPU time per request doesn't execeed 50ms on any day + a project on the Pro account that uses middleware doesn't use the new release and still runs on 0.6.0 with Beta middleware. Also both alert arrived around the same time, (Fr. 8 Juli, 3:08PM and 3:10PM (UTC).

Hobby CPU utilization

2022-07-12 02_47_12

Pro Team CPU utilization

2022-07-12 02_47_58

I got in touch with Vercel support and asked what I should do. I'll update this issue once I get a reply

@nibtime nibtime changed the title excessive CPU usage warning from Vercel excessive CPU usage warning from Vercel for middleware Jul 12, 2022
@nibtime
Copy link
Owner Author

nibtime commented Jul 23, 2022

The reply from @vercel was

Thank you for proactively looking at this! In your troubleshooting efforts, the function logs ... for the current production deployment may shed some light on what requests are resulting in high usage times.

However, function logs don't give insight into CPU utilization (there seems no good telemetry story for middleware yet, see vercel/next.js#34420).

I did some improvements to decrease CPU utilization in #47, somewhat into the blue, and by educated guessing. I also provided a telemetry wrapper middleware to measure execution time by logging to the console

I just hammered a new deployment with autocannon to observe effects on average CPU utilization in Vercel Dashboard. The changes to seem to have a significant effect:

CPU utilization (5,85ms avg)

2022-07-23 12_12_40

Invocations (4060)

2022-07-23 12_12_57

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant