-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into fix/vercel-request
- Loading branch information
Showing
35 changed files
with
760 additions
and
70 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,5 @@ | ||
--- | ||
'astro': patch | ||
--- | ||
|
||
Run astro sync in build mode |
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
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
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
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 |
---|---|---|
@@ -1,6 +1,7 @@ | ||
name: Examples astro check | ||
|
||
on: | ||
workflow_dispatch: | ||
push: | ||
branches: | ||
- main | ||
|
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 |
---|---|---|
@@ -1,6 +1,7 @@ | ||
name: CI | ||
|
||
on: | ||
workflow_dispatch: | ||
push: | ||
branches: | ||
- main | ||
|
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 |
---|---|---|
@@ -1,6 +1,7 @@ | ||
name: "Format Code" | ||
|
||
on: | ||
workflow_dispatch: | ||
push: | ||
branches: | ||
- main | ||
|
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 |
---|---|---|
@@ -1,6 +1,7 @@ | ||
name: Main Checks | ||
|
||
on: | ||
workflow_dispatch: | ||
push: | ||
branches: | ||
- main | ||
|
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 |
---|---|---|
@@ -1,6 +1,7 @@ | ||
name: Scripts | ||
|
||
on: | ||
workflow_dispatch: | ||
pull_request: | ||
branches: | ||
- "main" | ||
|
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 |
---|---|---|
@@ -1,6 +1,7 @@ | ||
name: Create a Snapshot Release | ||
|
||
on: | ||
workflow_dispatch: | ||
issue_comment: | ||
types: [created] | ||
|
||
|
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
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 @@ | ||
# benchmark | ||
|
||
Astro's main benchmark suite. It exposes the `astro-benchmark` CLI command. Run `astro-benchmark --help` to see all available commands! | ||
|
||
If you'd like to understand how the benchmark works, check out the other READMEs in the subfolders. |
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 @@ | ||
# bench | ||
|
||
This `bench` folder contains different benchmarking files that you can run via `astro-benchmark <bench-file-name>`, e.g. `astro-benchmark memory`. Files that start with an underscore are not benchmarking files. | ||
|
||
Benchmarking files will run against a project to measure its performance, and write the results down as JSON in the `results` folder. The `results` folder is gitignored and its result files can be safely deleted if you're not using them. | ||
|
||
You can duplicate `_template.js` to start a new benchmark test. All shared utilities are kept in `_util.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,12 @@ | ||
/** Default project to run for this benchmark if not specified */ | ||
export const defaultProject = 'project-name'; | ||
|
||
/** | ||
* Run benchmark on `projectDir` and write results to `outputFile`. | ||
* Use `console.log` to report the results too. Logs that start with 10 `=` | ||
* and end with 10 `=` will be extracted by CI to display in the PR comment. | ||
* Usually after the first 10 `=` you'll want to add a title like `#### Test`. | ||
* @param {URL} projectDir | ||
* @param {URL} outputFile | ||
*/ | ||
export async function run(projectDir, outputFile) {} |
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,3 @@ | ||
import { createRequire } from 'module'; | ||
|
||
export const astroBin = createRequire(import.meta.url).resolve('astro'); |
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,58 @@ | ||
import fs from 'fs/promises'; | ||
import { fileURLToPath } from 'url'; | ||
import { execaCommand } from 'execa'; | ||
import { markdownTable } from 'markdown-table'; | ||
import { astroBin } from './_util.js'; | ||
|
||
/** @typedef {Record<string, import('../../packages/astro/src/core/config/timer').Stat>} AstroTimerStat */ | ||
|
||
/** Default project to run for this benchmark if not specified */ | ||
export const defaultProject = 'memory-default'; | ||
|
||
/** | ||
* @param {URL} projectDir | ||
* @param {URL} outputFile | ||
*/ | ||
export async function run(projectDir, outputFile) { | ||
const root = fileURLToPath(projectDir); | ||
const outputFilePath = fileURLToPath(outputFile); | ||
|
||
console.log('Building and benchmarking...'); | ||
await execaCommand(`node --expose-gc --max_old_space_size=256 ${astroBin} build`, { | ||
cwd: root, | ||
stdio: 'inherit', | ||
env: { | ||
ASTRO_TIMER_PATH: outputFilePath, | ||
}, | ||
}); | ||
|
||
console.log('Raw results written to', outputFilePath); | ||
|
||
console.log('Result preview:'); | ||
console.log('='.repeat(10)); | ||
console.log(`#### Memory\n\n`); | ||
console.log(printResult(JSON.parse(await fs.readFile(outputFilePath, 'utf-8')))); | ||
console.log('='.repeat(10)); | ||
|
||
console.log('Done!'); | ||
} | ||
|
||
/** | ||
* @param {AstroTimerStat} output | ||
*/ | ||
function printResult(output) { | ||
return markdownTable( | ||
[ | ||
['', 'Elapsed time (s)', 'Memory used (MB)', 'Final memory (MB)'], | ||
...Object.entries(output).map(([name, stat]) => [ | ||
name, | ||
(stat.elapsedTime / 1000).toFixed(2), | ||
(stat.heapUsedChange / 1024 / 1024).toFixed(2), | ||
(stat.heapUsedTotal / 1024 / 1024).toFixed(2), | ||
]), | ||
], | ||
{ | ||
align: ['l', 'r', 'r', 'r'], | ||
} | ||
); | ||
} |
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,85 @@ | ||
import fs from 'fs/promises'; | ||
import { fileURLToPath } from 'url'; | ||
import autocannon from 'autocannon'; | ||
import { execaCommand } from 'execa'; | ||
import { waitUntilBusy } from 'port-authority'; | ||
import { astroBin } from './_util.js'; | ||
|
||
const port = 4321; | ||
|
||
export const defaultProject = 'server-stress-default'; | ||
|
||
/** | ||
* @param {URL} projectDir | ||
* @param {URL} outputFile | ||
*/ | ||
export async function run(projectDir, outputFile) { | ||
const root = fileURLToPath(projectDir); | ||
|
||
console.log('Building...'); | ||
await execaCommand(`${astroBin} build`, { | ||
cwd: root, | ||
stdio: 'inherit', | ||
}); | ||
|
||
console.log('Previewing...'); | ||
const previewProcess = execaCommand(`${astroBin} preview --port ${port}`, { | ||
cwd: root, | ||
stdio: 'inherit', | ||
}); | ||
|
||
console.log('Waiting for server ready...'); | ||
await waitUntilBusy(port, { timeout: 5000 }); | ||
|
||
console.log('Running benchmark...'); | ||
const result = await benchmarkCannon(); | ||
|
||
console.log('Killing server...'); | ||
if (!previewProcess.kill('SIGTERM')) { | ||
console.warn('Failed to kill server process id:', previewProcess.pid); | ||
} | ||
|
||
console.log('Writing results to', fileURLToPath(outputFile)); | ||
await fs.writeFile(outputFile, JSON.stringify(result, null, 2)); | ||
|
||
console.log('Result preview:'); | ||
console.log('='.repeat(10)); | ||
console.log(`#### Server stress\n\n`); | ||
let text = autocannon.printResult(result); | ||
// Truncate the logs in CI so that the generated comment from the `!bench` command | ||
// is shortened. Also we only need this information when comparing runs. | ||
// Full log example: https://github.com/mcollina/autocannon#command-line | ||
if (process.env.CI) { | ||
text = text.match(/^.*?requests in.*?read$/m)?.[0]; | ||
} | ||
console.log(text); | ||
console.log('='.repeat(10)); | ||
|
||
console.log('Done!'); | ||
} | ||
|
||
/** | ||
* @returns {Promise<import('autocannon').Result>} | ||
*/ | ||
async function benchmarkCannon() { | ||
return new Promise((resolve, reject) => { | ||
const instance = autocannon( | ||
{ | ||
url: `http://localhost:${port}`, | ||
connections: 100, | ||
duration: 30, | ||
pipelining: 10, | ||
}, | ||
(err, result) => { | ||
if (err) { | ||
reject(err); | ||
} else { | ||
// @ts-expect-error untyped but documented | ||
instance.stop(); | ||
resolve(result); | ||
} | ||
} | ||
); | ||
autocannon.track(instance, { renderResultsTable: false }); | ||
}); | ||
} |
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,13 @@ | ||
// This script helps extract the benchmark logs that are between the `==========` lines. | ||
// They are a convention defined in the `./bench/_template.js` file, which are used to log | ||
// out with the `!bench` command. See `/.github/workflows/benchmark.yml` to see how it's used. | ||
const benchLogs = process.argv[2]; | ||
const resultRegex = /==========(.*?)==========/gs; | ||
|
||
let processedLog = ''; | ||
let m; | ||
while ((m = resultRegex.exec(benchLogs))) { | ||
processedLog += m[1] + '\n'; | ||
} | ||
|
||
console.log(processedLog); |
Oops, something went wrong.