aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--scripts/benchmark.ts49
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'
2import { program } from 'commander' 2import { program } from 'commander'
3import { writeJson } from 'fs-extra' 3import { writeJson } from 'fs-extra'
4import { Video, VideoPrivacy } from '@shared/models' 4import { Video, VideoPrivacy } from '@shared/models'
5import { createSingleServer, killallServers, PeerTubeServer, setAccessTokensToServers } from '@shared/server-commands' 5import { createMultipleServers, doubleFollow, killallServers, PeerTubeServer, setAccessTokensToServers } from '@shared/server-commands'
6 6
7let servers: PeerTubeServer[]
8// First server
7let server: PeerTubeServer 9let server: PeerTubeServer
8let video: Video 10let video: Video
9let threadId: number 11let threadId: number
@@ -21,7 +23,7 @@ const outfile = options.outfile
21run() 23run()
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
27function buildAuthorizationHeader () { 29function buildAuthorizationHeader () {
@@ -36,6 +38,12 @@ function buildAPHeader () {
36 } 38 }
37} 39}
38 40
41function buildJSONHeader () {
42 return {
43 'Content-Type': 'application/json'
44 }
45}
46
39async function run () { 47async 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
168function runBenchmark (options: { 197function 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
200async function prepare () { 233async 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}