mirror of
https://github.com/versia-pub/server.git
synced 2025-12-06 08:28:19 +01:00
feat: Add timeline benchmark
This commit is contained in:
parent
15ef1851fc
commit
df5e8f744b
15
README.md
15
README.md
|
|
@ -23,10 +23,25 @@ This project aims to be a fully featured social network, with a focus on privacy
|
||||||
- [x] Full regex-based filters for posts, users and media
|
- [x] Full regex-based filters for posts, users and media
|
||||||
- [x] Custom emoji support
|
- [x] Custom emoji support
|
||||||
- [x] Automatic image conversion to WebP or other formats
|
- [x] Automatic image conversion to WebP or other formats
|
||||||
|
- [x] Scripting-compatible CLI with JSON and CSV outputs
|
||||||
- [ ] Moderation tools
|
- [ ] Moderation tools
|
||||||
- [ ] Full Mastodon API support
|
- [ ] Full Mastodon API support
|
||||||
- [ ] Outbound federation
|
- [ ] Outbound federation
|
||||||
|
|
||||||
|
## Benchmarks
|
||||||
|
|
||||||
|
> **Note**: These benchmarks are not representative of real-world performance, and are only meant to be used as a rough guide.
|
||||||
|
|
||||||
|
### Timeline Benchmarks
|
||||||
|
|
||||||
|
You may run the following command to benchmark the `/api/v1/timelines/home` endpoint:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
TOKEN=token_here bun benchmark:timeline <request_count>
|
||||||
|
```
|
||||||
|
|
||||||
|
The `request_count` variable is optional and defaults to 100. `TOKEN` is your personal user token, used to login to the API.
|
||||||
|
|
||||||
## How do I run it?
|
## How do I run it?
|
||||||
|
|
||||||
### Requirements
|
### Requirements
|
||||||
|
|
|
||||||
56
benchmarks/timelines.ts
Normal file
56
benchmarks/timelines.ts
Normal file
|
|
@ -0,0 +1,56 @@
|
||||||
|
/**
|
||||||
|
* Usage: TOKEN=your_token_here bun benchmark:timeline <request_count>
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { getConfig } from "@config";
|
||||||
|
import chalk from "chalk";
|
||||||
|
|
||||||
|
const config = getConfig();
|
||||||
|
|
||||||
|
const token = process.env.TOKEN;
|
||||||
|
const requestCount = Number(process.argv[2]) || 100;
|
||||||
|
|
||||||
|
if (!token) {
|
||||||
|
console.log(
|
||||||
|
`${chalk.red(
|
||||||
|
"✗"
|
||||||
|
)} No token provided. Provide one via the TOKEN environment variable.`
|
||||||
|
);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
const fetchTimeline = () =>
|
||||||
|
fetch(`${config.http.base_url}/api/v1/timelines/home`, {
|
||||||
|
headers: {
|
||||||
|
Authorization: `Bearer ${token}`,
|
||||||
|
},
|
||||||
|
}).then(res => res.ok);
|
||||||
|
|
||||||
|
const timeNow = performance.now();
|
||||||
|
|
||||||
|
const requests = Array.from({ length: requestCount }, () => fetchTimeline());
|
||||||
|
|
||||||
|
Promise.all(requests)
|
||||||
|
.then(results => {
|
||||||
|
const timeTaken = performance.now() - timeNow;
|
||||||
|
if (results.every(t => t)) {
|
||||||
|
console.log(`${chalk.green("✓")} All requests succeeded`);
|
||||||
|
} else {
|
||||||
|
console.log(
|
||||||
|
`${chalk.red("✗")} ${
|
||||||
|
results.filter(t => !t).length
|
||||||
|
} requests failed`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
console.log(
|
||||||
|
`${chalk.green("✓")} ${
|
||||||
|
requests.length
|
||||||
|
} requests fulfilled in ${chalk.bold(
|
||||||
|
(timeTaken / 1000).toFixed(5)
|
||||||
|
)}s`
|
||||||
|
);
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
console.log(`${chalk.red("✗")} ${err}`);
|
||||||
|
process.exit(1);
|
||||||
|
});
|
||||||
3
index.ts
3
index.ts
|
|
@ -12,6 +12,7 @@ import { client } from "~database/datasource";
|
||||||
import type { PrismaClientInitializationError } from "@prisma/client/runtime/library";
|
import type { PrismaClientInitializationError } from "@prisma/client/runtime/library";
|
||||||
import { HookTypes, Server } from "~plugins/types";
|
import { HookTypes, Server } from "~plugins/types";
|
||||||
|
|
||||||
|
const timeAtStart = performance.now();
|
||||||
const server = new Server();
|
const server = new Server();
|
||||||
|
|
||||||
const router = new Bun.FileSystemRouter({
|
const router = new Bun.FileSystemRouter({
|
||||||
|
|
@ -171,7 +172,7 @@ console.log(
|
||||||
`${chalk.green(`✓`)} ${chalk.bold(
|
`${chalk.green(`✓`)} ${chalk.bold(
|
||||||
`Lysand started at ${chalk.blue(
|
`Lysand started at ${chalk.blue(
|
||||||
`${config.http.bind}:${config.http.bind_port}`
|
`${config.http.bind}:${config.http.bind_port}`
|
||||||
)}`
|
)} in ${chalk.gray((performance.now() - timeAtStart).toFixed(0))}ms`
|
||||||
)}`
|
)}`
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -39,6 +39,7 @@
|
||||||
"lint": "eslint --config .eslintrc.cjs --ext .ts .",
|
"lint": "eslint --config .eslintrc.cjs --ext .ts .",
|
||||||
"prisma": "bun run prisma.ts",
|
"prisma": "bun run prisma.ts",
|
||||||
"generate": "bun prisma generate",
|
"generate": "bun prisma generate",
|
||||||
|
"benchmark:timeline": "bun run benchmarks/timelines.ts",
|
||||||
"cli": "bun run cli.ts"
|
"cli": "bun run cli.ts"
|
||||||
},
|
},
|
||||||
"trustedDependencies": [
|
"trustedDependencies": [
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue