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

misc: add minimal server bench setup #41328

Merged
merged 4 commits into from Oct 11, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions bench/minimal-server/benchmark-app/app/layout.js
@@ -0,0 +1,10 @@
import * as React from 'react'

export default function Root({ children }) {
return (
<html>
<head></head>
<body>{children}</body>
</html>
)
}
5 changes: 5 additions & 0 deletions bench/minimal-server/benchmark-app/app/rsc/page.js
@@ -0,0 +1,5 @@
import * as React from 'react'

export default function page() {
return <div>hello</div>
}
5 changes: 5 additions & 0 deletions bench/minimal-server/benchmark-app/next.config.js
@@ -0,0 +1,5 @@
module.exports = {
experimental: {
appDir: true,
},
}
14 changes: 14 additions & 0 deletions bench/minimal-server/benchmark-app/package.json
@@ -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"
}
}
9 changes: 9 additions & 0 deletions bench/minimal-server/benchmark-app/pages/index.js
@@ -0,0 +1,9 @@
import * as React from 'react'

export default function page() {
return <div> hello world </div>
}

export async function getServerSideProps() {
return {}
}
7 changes: 7 additions & 0 deletions bench/minimal-server/package.json
@@ -0,0 +1,7 @@
{
"name": "next-minimal-server",
"description": "Minimal server for Next.js for benchmarking/perf analysis purposes.",
"scripts": {
"start": "node start.js"
}
}
40 changes: 40 additions & 0 deletions bench/minimal-server/start.js
@@ -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')
})