-
Notifications
You must be signed in to change notification settings - Fork 26.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
misc: add minimal server bench setup (#41328)
This PR adds a script to run a minimal Next server in order to reproduce more easily the cold boot conditions in production. You can use it by using `pnpm start` after having built your app with `pnpm next-react-exp build bench/minimal-server/benchmar-app` from the root of this repo. <img width="338" alt="image" src="https://user-images.githubusercontent.com/11064311/195102966-6997b957-1e6b-433f-b611-e0eaec9462fa.png"> ## Bug - [ ] Related issues linked using `fixes #number` - [ ] Integration tests added - [ ] Errors have a helpful link attached, see `contributing.md` ## Feature - [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR. - [ ] Related issues linked using `fixes #number` - [ ] Integration tests added - [ ] Documentation added - [ ] Telemetry added. In case of a feature if it's used or not. - [ ] Errors have a helpful link attached, see `contributing.md` ## Documentation / Examples - [ ] Make sure the linting passes by running `pnpm lint` - [ ] The "examples guidelines" are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md)
- Loading branch information
1 parent
ba08576
commit c6a8675
Showing
7 changed files
with
90 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import * as React from 'react' | ||
|
||
export default function Root({ children }) { | ||
return ( | ||
<html> | ||
<head></head> | ||
<body>{children}</body> | ||
</html> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import * as React from 'react' | ||
|
||
export default function page() { | ||
return <div>hello</div> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module.exports = { | ||
experimental: { | ||
appDir: true, | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"name": "stats-app", | ||
"private": true, | ||
"license": "MIT", | ||
"dependencies": { | ||
"webpack-bundle-analyzer": "^4.6.1", | ||
"webpack-stats-plugin": "^1.1.0" | ||
}, | ||
"scripts": { | ||
"dev": "next dev", | ||
"build": "next build", | ||
"start": "next start" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import * as React from 'react' | ||
|
||
export default function page() { | ||
return <div> hello world </div> | ||
} | ||
|
||
export async function getServerSideProps() { | ||
return {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"name": "next-minimal-server", | ||
"description": "Minimal server for Next.js for benchmarking/perf analysis purposes.", | ||
"scripts": { | ||
"start": "node start.js" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
process.env.__NEXT_REACT_CHANNEL = 'exp' | ||
process.env.NODE_ENV = 'production' | ||
|
||
require('../../test/lib/react-channel-require-hook') | ||
|
||
console.time('next-cold-start') | ||
const NextServer = require('next/dist/server/next-server').default | ||
const path = require('path') | ||
|
||
const appDir = path.join(__dirname, 'benchmark-app') | ||
const distDir = '.next' | ||
|
||
const compiledConfig = require(path.join( | ||
appDir, | ||
distDir, | ||
'required-server-files.json' | ||
)).config | ||
|
||
process.chdir(appDir) | ||
|
||
const nextServer = new NextServer({ | ||
conf: compiledConfig, | ||
dir: appDir, | ||
distDir, | ||
minimalMode: true, | ||
customServer: false, | ||
}) | ||
|
||
const requestHandler = nextServer.getRequestHandler() | ||
|
||
require('http') | ||
.createServer((req, res) => { | ||
console.time('next-request') | ||
return requestHandler(req, res).finally(() => { | ||
console.timeEnd('next-request') | ||
}) | ||
}) | ||
.listen(3000, () => { | ||
console.timeEnd('next-cold-start') | ||
}) |