diff options
author | Chocobozzz <me@florianbigard.com> | 2022-03-18 14:52:53 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2022-03-18 14:52:53 +0100 |
commit | 6afc0d374cbb7c87c095eaa3235e1e83134c0337 (patch) | |
tree | e0b1b29f121daedc10b14dca29a76db639781539 /scripts/benchmark.ts | |
parent | cc92203fe5ea2a7fddbeb0020e3769b0678d40bb (diff) | |
download | PeerTube-6afc0d374cbb7c87c095eaa3235e1e83134c0337.tar.gz PeerTube-6afc0d374cbb7c87c095eaa3235e1e83134c0337.tar.zst PeerTube-6afc0d374cbb7c87c095eaa3235e1e83134c0337.zip |
Add watching and views endpoints to benchmark
Diffstat (limited to 'scripts/benchmark.ts')
-rw-r--r-- | scripts/benchmark.ts | 49 |
1 files changed, 42 insertions, 7 deletions
diff --git a/scripts/benchmark.ts b/scripts/benchmark.ts index 48e740dff..91e8b865a 100644 --- a/scripts/benchmark.ts +++ b/scripts/benchmark.ts | |||
@@ -2,8 +2,10 @@ import autocannon, { printResult } from 'autocannon' | |||
2 | import { program } from 'commander' | 2 | import { program } from 'commander' |
3 | import { writeJson } from 'fs-extra' | 3 | import { writeJson } from 'fs-extra' |
4 | import { Video, VideoPrivacy } from '@shared/models' | 4 | import { Video, VideoPrivacy } from '@shared/models' |
5 | import { createSingleServer, killallServers, PeerTubeServer, setAccessTokensToServers } from '@shared/server-commands' | 5 | import { createMultipleServers, doubleFollow, killallServers, PeerTubeServer, setAccessTokensToServers } from '@shared/server-commands' |
6 | 6 | ||
7 | let servers: PeerTubeServer[] | ||
8 | // First server | ||
7 | let server: PeerTubeServer | 9 | let server: PeerTubeServer |
8 | let video: Video | 10 | let video: Video |
9 | let threadId: number | 11 | let threadId: number |
@@ -21,7 +23,7 @@ const outfile = options.outfile | |||
21 | run() | 23 | run() |
22 | .catch(err => console.error(err)) | 24 | .catch(err => console.error(err)) |
23 | .finally(() => { | 25 | .finally(() => { |
24 | if (server) return killallServers([ server ]) | 26 | if (servers) return killallServers(servers) |
25 | }) | 27 | }) |
26 | 28 | ||
27 | function buildAuthorizationHeader () { | 29 | function buildAuthorizationHeader () { |
@@ -36,6 +38,12 @@ function buildAPHeader () { | |||
36 | } | 38 | } |
37 | } | 39 | } |
38 | 40 | ||
41 | function buildJSONHeader () { | ||
42 | return { | ||
43 | 'Content-Type': 'application/json' | ||
44 | } | ||
45 | } | ||
46 | |||
39 | async function run () { | 47 | async function run () { |
40 | console.log('Preparing server...') | 48 | console.log('Preparing server...') |
41 | 49 | ||
@@ -143,6 +151,27 @@ async function run () { | |||
143 | expecter: (body, status) => { | 151 | expecter: (body, status) => { |
144 | return status === 200 && body.startsWith('{"client":') | 152 | return status === 200 && body.startsWith('{"client":') |
145 | } | 153 | } |
154 | }, | ||
155 | { | ||
156 | title: 'API - watching', | ||
157 | method: 'PUT', | ||
158 | headers: { | ||
159 | ...buildAuthorizationHeader(), | ||
160 | ...buildJSONHeader() | ||
161 | }, | ||
162 | body: JSON.stringify({ currentTime: 2 }), | ||
163 | path: '/api/v1/videos/' + video.uuid + '/watching', | ||
164 | expecter: (body, status) => { | ||
165 | return status === 204 | ||
166 | } | ||
167 | }, | ||
168 | { | ||
169 | title: 'API - views', | ||
170 | method: 'POST', | ||
171 | path: '/api/v1/videos/' + video.uuid + '/views', | ||
172 | expecter: (body, status) => { | ||
173 | return status === 204 | ||
174 | } | ||
146 | } | 175 | } |
147 | ].filter(t => { | 176 | ].filter(t => { |
148 | if (!options.grep) return true | 177 | if (!options.grep) return true |
@@ -167,14 +196,18 @@ async function run () { | |||
167 | 196 | ||
168 | function runBenchmark (options: { | 197 | function runBenchmark (options: { |
169 | path: string | 198 | path: string |
199 | method?: string | ||
200 | body?: string | ||
170 | headers?: { [ id: string ]: string } | 201 | headers?: { [ id: string ]: string } |
171 | expecter: Function | 202 | expecter: Function |
172 | }) { | 203 | }) { |
173 | const { path, expecter, headers } = options | 204 | const { method, path, body, expecter, headers } = options |
174 | 205 | ||
175 | return new Promise((res, rej) => { | 206 | return new Promise((res, rej) => { |
176 | autocannon({ | 207 | autocannon({ |
177 | url: server.url + path, | 208 | url: server.url + path, |
209 | method, | ||
210 | body, | ||
178 | connections: 20, | 211 | connections: 20, |
179 | headers, | 212 | headers, |
180 | pipelining: 1, | 213 | pipelining: 1, |
@@ -198,14 +231,18 @@ function runBenchmark (options: { | |||
198 | } | 231 | } |
199 | 232 | ||
200 | async function prepare () { | 233 | async function prepare () { |
201 | server = await createSingleServer(1, { | 234 | servers = await createMultipleServers(3, { |
202 | rates_limit: { | 235 | rates_limit: { |
203 | api: { | 236 | api: { |
204 | max: 5_000_000 | 237 | max: 5_000_000 |
205 | } | 238 | } |
206 | } | 239 | } |
207 | }) | 240 | }) |
208 | await setAccessTokensToServers([ server ]) | 241 | server = servers[0] |
242 | |||
243 | await setAccessTokensToServers(servers) | ||
244 | await doubleFollow(servers[0], servers[1]) | ||
245 | await doubleFollow(servers[0], servers[2]) | ||
209 | 246 | ||
210 | const attributes = { | 247 | const attributes = { |
211 | name: 'my super video', | 248 | name: 'my super video', |
@@ -248,6 +285,4 @@ async function prepare () { | |||
248 | fixture: 'subtitle-good2.vtt' | 285 | fixture: 'subtitle-good2.vtt' |
249 | }) | 286 | }) |
250 | } | 287 | } |
251 | |||
252 | return { server, video, threadId } | ||
253 | } | 288 | } |