aboutsummaryrefslogtreecommitdiffhomepage
path: root/scripts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-03-30 08:57:17 +0200
committerChocobozzz <me@florianbigard.com>2021-03-30 08:57:17 +0200
commit47099aba46be7757d833422f1706b99a3c0e28ea (patch)
tree46daf080e034f87801905b700226ba5bc1b60732 /scripts
parent6794d1005ff1c1766223e7d45af3feab3cdb0785 (diff)
downloadPeerTube-47099aba46be7757d833422f1706b99a3c0e28ea.tar.gz
PeerTube-47099aba46be7757d833422f1706b99a3c0e28ea.tar.zst
PeerTube-47099aba46be7757d833422f1706b99a3c0e28ea.zip
Fix benchmark
Diffstat (limited to 'scripts')
-rw-r--r--scripts/benchmark.ts101
1 files changed, 40 insertions, 61 deletions
diff --git a/scripts/benchmark.ts b/scripts/benchmark.ts
index 45b2a7a79..0cadb36d9 100644
--- a/scripts/benchmark.ts
+++ b/scripts/benchmark.ts
@@ -50,126 +50,102 @@ async function run () {
50 title: 'AP - account peertube', 50 title: 'AP - account peertube',
51 path: '/accounts/peertube', 51 path: '/accounts/peertube',
52 headers: buildAPHeader(), 52 headers: buildAPHeader(),
53 expecter: (client, statusCode) => { 53 expecter: (body, status) => {
54 const body = client.resData[0].body 54 return status === 200 && body.startsWith('{"type":')
55
56 return statusCode === 200 && body.startsWith('{"type":')
57 } 55 }
58 }, 56 },
59 { 57 {
60 title: 'AP - video', 58 title: 'AP - video',
61 path: '/videos/watch/' + video.uuid, 59 path: '/videos/watch/' + video.uuid,
62 headers: buildAPHeader(), 60 headers: buildAPHeader(),
63 expecter: (client, statusCode) => { 61 expecter: (body, status) => {
64 const body = client.resData[0].body 62 return status === 200 && body.startsWith('{"type":"Video"')
65
66 return statusCode === 200 && body.startsWith('{"type":"Video"')
67 } 63 }
68 }, 64 },
69 { 65 {
70 title: 'Misc - webfinger peertube', 66 title: 'Misc - webfinger peertube',
71 path: '/.well-known/webfinger?resource=acct:peertube@' + server.host, 67 path: '/.well-known/webfinger?resource=acct:peertube@' + server.host,
72 expecter: (client, statusCode) => { 68 expecter: (body, status) => {
73 const body = client.resData[0].body 69 return status === 200 && body.startsWith('{"subject":')
74
75 return statusCode === 200 && body.startsWith('{"subject":')
76 } 70 }
77 }, 71 },
78 { 72 {
79 title: 'API - unread notifications', 73 title: 'API - unread notifications',
80 path: '/api/v1/users/me/notifications?start=0&count=0&unread=true', 74 path: '/api/v1/users/me/notifications?start=0&count=0&unread=true',
81 headers: buildAuthorizationHeader(), 75 headers: buildAuthorizationHeader(),
82 expecter: (_client, statusCode) => { 76 expecter: (_body, status) => {
83 return statusCode === 200 77 return status === 200
84 } 78 }
85 }, 79 },
86 { 80 {
87 title: 'API - me', 81 title: 'API - me',
88 path: '/api/v1/users/me', 82 path: '/api/v1/users/me',
89 headers: buildAuthorizationHeader(), 83 headers: buildAuthorizationHeader(),
90 expecter: (client, statusCode) => { 84 expecter: (body, status) => {
91 const body = client.resData[0].body 85 return status === 200 && body.startsWith('{"id":')
92
93 return statusCode === 200 && body.startsWith('{"id":')
94 } 86 }
95 }, 87 },
96 { 88 {
97 title: 'API - videos list', 89 title: 'API - videos list',
98 path: '/api/v1/videos', 90 path: '/api/v1/videos',
99 expecter: (client, statusCode) => { 91 expecter: (body, status) => {
100 const body = client.resData[0].body 92 return status === 200 && body.startsWith('{"total":10')
101
102 return statusCode === 200 && body.startsWith('{"total":10')
103 } 93 }
104 }, 94 },
105 { 95 {
106 title: 'API - video get', 96 title: 'API - video get',
107 path: '/api/v1/videos/' + video.uuid, 97 path: '/api/v1/videos/' + video.uuid,
108 expecter: (client, statusCode) => { 98 expecter: (body, status) => {
109 const body = client.resData[0].body 99 return status === 200 && body.startsWith('{"id":')
110
111 return statusCode === 200 && body.startsWith('{"id":')
112 } 100 }
113 }, 101 },
114 { 102 {
115 title: 'API - video captions', 103 title: 'API - video captions',
116 path: '/api/v1/videos/' + video.uuid + '/captions', 104 path: '/api/v1/videos/' + video.uuid + '/captions',
117 expecter: (client, statusCode) => { 105 expecter: (body, status) => {
118 const body = client.resData[0].body 106 return status === 200 && body.startsWith('{"total":4')
119
120 return statusCode === 200 && body.startsWith('{"total":4')
121 } 107 }
122 }, 108 },
123 { 109 {
124 title: 'API - video threads', 110 title: 'API - video threads',
125 path: '/api/v1/videos/' + video.uuid + '/comment-threads', 111 path: '/api/v1/videos/' + video.uuid + '/comment-threads',
126 expecter: (client, statusCode) => { 112 expecter: (body, status) => {
127 const body = client.resData[0].body 113 return status === 200 && body.startsWith('{"total":10')
128
129 return statusCode === 200 && body.startsWith('{"total":10')
130 } 114 }
131 }, 115 },
132 { 116 {
133 title: 'API - video replies', 117 title: 'API - video replies',
134 path: '/api/v1/videos/' + video.uuid + '/comment-threads/' + threadId, 118 path: '/api/v1/videos/' + video.uuid + '/comment-threads/' + threadId,
135 expecter: (client, statusCode) => { 119 expecter: (body, status) => {
136 const body = client.resData[0].body 120 return status === 200 && body.startsWith('{"comment":{')
137
138 return statusCode === 200 && body.startsWith('{"comment":{')
139 } 121 }
140 }, 122 },
141 { 123 {
142 title: 'HTML - video watch', 124 title: 'HTML - video watch',
143 path: '/videos/watch/' + video.uuid, 125 path: '/videos/watch/' + video.uuid,
144 expecter: (client, statusCode) => { 126 expecter: (body, status) => {
145 const body = client.resData[0].body 127 return status === 200 && body.includes('<title>my super')
146
147 return statusCode === 200 && body.includes('<title>my super')
148 } 128 }
149 }, 129 },
150 { 130 {
151 title: 'HTML - video embed', 131 title: 'HTML - video embed',
152 path: '/videos/embed/' + video.uuid, 132 path: '/videos/embed/' + video.uuid,
153 expecter: (client, statusCode) => { 133 expecter: (body, status) => {
154 const body = client.resData[0].body 134 return status === 200 && body.includes('embed')
155
156 return statusCode === 200 && body.includes('embed')
157 } 135 }
158 }, 136 },
159 { 137 {
160 title: 'HTML - homepage', 138 title: 'HTML - homepage',
161 path: '/', 139 path: '/',
162 expecter: (_client, statusCode) => { 140 expecter: (_body, status) => {
163 return statusCode === 200 141 return status === 200
164 } 142 }
165 }, 143 },
166 { 144 {
167 title: 'API - config', 145 title: 'API - config',
168 path: '/api/v1/config', 146 path: '/api/v1/config',
169 expecter: (client, statusCode) => { 147 expecter: (body, status) => {
170 const body = client.resData[0].body 148 return status === 200 && body.startsWith('{"instance":')
171
172 return statusCode === 200 && body.startsWith('{"instance":')
173 } 149 }
174 } 150 }
175 ] 151 ]
@@ -197,24 +173,27 @@ function runBenchmark (options: {
197 const { path, expecter, headers } = options 173 const { path, expecter, headers } = options
198 174
199 return new Promise((res, rej) => { 175 return new Promise((res, rej) => {
200 const instance = autocannon({ 176 autocannon({
201 url: server.url + path, 177 url: server.url + path,
202 connections: 20, 178 connections: 20,
203 headers, 179 headers,
204 pipelining: 1, 180 pipelining: 1,
205 duration: 10 181 duration: 10,
182 requests: [
183 {
184 onResponse: (status, body) => {
185 if (expecter(body, status) !== true) {
186 console.error('Expected result failed.', { body, status })
187 throw new Error('Invalid expectation')
188 }
189 }
190 }
191 ]
206 }, (err, result) => { 192 }, (err, result) => {
207 if (err) return rej(err) 193 if (err) return rej(err)
208 194
209 return res(result) 195 return res(result)
210 }) 196 })
211
212 instance.on('response', (client, statusCode) => {
213 if (expecter(client, statusCode) !== true) {
214 console.error('Expected result failed.', { data: client.resData })
215 process.exit(-1)
216 }
217 })
218 }) 197 })
219} 198}
220 199