next.js icon indicating copy to clipboard operation
next.js copied to clipboard

v12.2 Major performance decrease in server response time

Open willemliufdmg opened this issue 2 years ago • 9 comments

Verify canary release

  • [X] I verified that the issue exists in the latest Next.js canary release

Provide environment information

Operating System:
  Platform: win32
  Arch: x64
  Version: Windows 10 Pro   
Binaries:
  Node: 16.13.1
  npm: N/A
  Yarn: N/A
  pnpm: N/A
Relevant packages:
  next: 12.2.1-canary.1     
  eslint-config-next: 12.2.0
  react: 18.2.0
  react-dom: 18.2.0

What browser are you using? (if relevant)

Not relevant

How are you deploying your application? (if relevant)

Vercel

Describe the Bug

When navigating to the same route in Next.js v12.2 the server requires a lot more time to respond as compared to v12.1. The screenshots below show the most optimal timings. Sometimes there are spikes of over 1 second:

v12.2: image

v12.1 image

Expected Behavior

Performance should be similar and not more than twice as slow with occasional spikes of over 10x as slow.

Link to reproduction

private repo

To Reproduce

Deploy Next.js v12.2 app to Vercel.

willemliufdmg avatar Jul 01 '22 14:07 willemliufdmg

Could be related to:

  • #38267
  • #38273

willemliufdmg avatar Jul 04 '22 09:07 willemliufdmg

@willemliufdmg Not sure if it could be relevant or not, but if you are using middleware, could you please remove or rename middleware.[js/ts] from the root of your project and see whether it's affecting the performance or not?

imangm avatar Jul 04 '22 09:07 imangm

@willemliufdmg Not sure if it could be relevant or not, but if you are using middleware, could you please remove or rename middleware.[js/ts] from the root of your project and see whether it's affecting the performance or not?

Next.js v12.2 with middleware and deployed on Vercel. image

Next.js v12.2 without middleware and deployed on Vercel. image

Ran multiple times and the results are consistent with +20/-20ms deviation.

willemliufdmg avatar Jul 04 '22 10:07 willemliufdmg

Screenshot_20220707_131513_com.microsoft.emmx_edit_831992177475124.jpg This graph on Vercel itself also shows that the middleware for the demo app with the router bug is a lot slower than the blue one. I would expect the opposite as the blue one is from a production website with a much larger middleware implementation with more rules and logic.

willemliufdmg avatar Jul 07 '22 11:07 willemliufdmg

We have the same problem...! We reverted and put Next.js 10 again... 😩

image

Please Next.js team, prioritize this issue!

aralroca avatar Jul 12 '22 10:07 aralroca

I have the hypothesis that also affects another thing to the performance, is the expermiental.optimizeCSS with a CDN in assetPrefix. It's doing an extra request to have CSS from the CDN (when it already has the file from /_next).

I reported here: https://github.com/vercel/next.js/issues/38561

aralroca avatar Jul 12 '22 15:07 aralroca

I have run a benchmark on my project https://github.com/sukkaw/vercel-dns-console:

# In one terminal session
# Start the Next.js server, also perform a profiling
$ npx 0x -- node ./node_modules/.bin/next start

# In another terminal session
# Run a benchmark
$ npx autocannon localhost:3000 -c 50 -d 60s

And here is my result:

Running 60s test @ http://localhost:3000
50 connections


┌─────────┬───────┬───────┬───────┬───────┬──────────┬─────────┬───────┐
│ Stat    │ 2.5%  │ 50%   │ 97.5% │ 99%   │ Avg      │ Stdev   │ Max   │
├─────────┼───────┼───────┼───────┼───────┼──────────┼─────────┼───────┤
│ Latency │ 15 ms │ 17 ms │ 25 ms │ 31 ms │ 17.31 ms │ 3.32 ms │ 92 ms │
└─────────┴───────┴───────┴───────┴───────┴──────────┴─────────┴───────┘
┌───────────┬─────────┬─────────┬─────────┬─────────┬─────────┬─────────┬─────────┐
│ Stat      │ 1%      │ 2.5%    │ 50%     │ 97.5%   │ Avg     │ Stdev   │ Min     │
├───────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┤
│ Req/Sec   │ 1378    │ 1833    │ 2885    │ 3023    │ 2809.09 │ 264.27  │ 1378    │
├───────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┤
│ Bytes/Sec │ 36.7 MB │ 48.8 MB │ 76.7 MB │ 80.5 MB │ 74.7 MB │ 7.03 MB │ 36.7 MB │
└───────────┴─────────┴─────────┴─────────┴─────────┴─────────┴─────────┴─────────┘

Req/Bytes counts sampled once per second.
# of samples: 60

169k requests in 60.03s, 4.48 GB read

As you can see, the P50 TTFB of my project is at 17ms, and the P99 is at 31ms.

And I also take a look at the generated flamegraph, it seems that the hottest path is etag:

image

SukkaW avatar Jul 12 '22 19:07 SukkaW

Confirm. With next middleware app ~2.5x slower. If middleware matcher ignore all requests excepts pages app ~1.8x slower

oleggrishechkin avatar Aug 24 '22 09:08 oleggrishechkin

I think it might be related to https://github.com/vercel/next.js/issues/42349

michalwarda avatar Nov 02 '22 15:11 michalwarda

The above patch is now available in v13.0.3-canary.1 of Next.js, please update and give it a try!

ijjk avatar Nov 08 '22 05:11 ijjk

Does this also solve https://github.com/vercel/next.js/issues/38273?

mgreenw avatar Nov 10 '22 13:11 mgreenw

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

github-actions[bot] avatar Dec 11 '22 00:12 github-actions[bot]