diff options
author | Chocobozzz <me@florianbigard.com> | 2022-06-17 10:48:37 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2022-06-17 10:48:37 +0200 |
commit | b9e49a45f5441fd1a2d49a10b88aaf4d425dc992 (patch) | |
tree | 3dc706c226a4d56ffcabab72f017d2b56ebcd4d9 /scripts/simulate-many-viewers.ts | |
parent | 42e6a7a747f5349ac3434ee44273e50966630440 (diff) | |
download | PeerTube-b9e49a45f5441fd1a2d49a10b88aaf4d425dc992.tar.gz PeerTube-b9e49a45f5441fd1a2d49a10b88aaf4d425dc992.tar.zst PeerTube-b9e49a45f5441fd1a2d49a10b88aaf4d425dc992.zip |
Add simulate many viewers script
Helps us to improve views scalability on peertube
Diffstat (limited to 'scripts/simulate-many-viewers.ts')
-rw-r--r-- | scripts/simulate-many-viewers.ts | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/scripts/simulate-many-viewers.ts b/scripts/simulate-many-viewers.ts new file mode 100644 index 000000000..4ec928aa8 --- /dev/null +++ b/scripts/simulate-many-viewers.ts | |||
@@ -0,0 +1,77 @@ | |||
1 | import Bluebird from 'bluebird' | ||
2 | import { wait } from '@shared/core-utils' | ||
3 | import { createSingleServer, doubleFollow, PeerTubeServer, setAccessTokensToServers, waitJobs } from '@shared/server-commands' | ||
4 | |||
5 | let servers: PeerTubeServer[] | ||
6 | const viewers: { xForwardedFor: string }[] = [] | ||
7 | let videoId: string | ||
8 | |||
9 | run() | ||
10 | .then(() => process.exit(0)) | ||
11 | .catch(err => console.error(err)) | ||
12 | |||
13 | async function run () { | ||
14 | await prepare() | ||
15 | |||
16 | while (true) { | ||
17 | await runViewers() | ||
18 | } | ||
19 | } | ||
20 | |||
21 | async function prepare () { | ||
22 | console.log('Preparing servers...') | ||
23 | |||
24 | const config = { | ||
25 | log: { | ||
26 | level: 'info' | ||
27 | }, | ||
28 | rates_limit: { | ||
29 | api: { | ||
30 | max: 5_000_000 | ||
31 | } | ||
32 | }, | ||
33 | views: { | ||
34 | videos: { | ||
35 | local_buffer_update_interval: '30 minutes', | ||
36 | ip_view_expiration: '1 hour' | ||
37 | } | ||
38 | } | ||
39 | } | ||
40 | |||
41 | servers = await Promise.all([ | ||
42 | createSingleServer(1, config, { nodeArgs: [ '--inspect' ] }), | ||
43 | createSingleServer(2, config), | ||
44 | createSingleServer(3, config) | ||
45 | ]) | ||
46 | |||
47 | await setAccessTokensToServers(servers) | ||
48 | await doubleFollow(servers[0], servers[1]) | ||
49 | await doubleFollow(servers[0], servers[2]) | ||
50 | |||
51 | const { uuid } = await servers[0].videos.quickUpload({ name: 'video' }) | ||
52 | videoId = uuid | ||
53 | |||
54 | await waitJobs(servers) | ||
55 | |||
56 | const THOUSAND_VIEWERS = 2 | ||
57 | |||
58 | for (let i = 2; i < 252; i++) { | ||
59 | for (let j = 2; j < 6; j++) { | ||
60 | for (let k = 2; k < THOUSAND_VIEWERS + 2; k++) { | ||
61 | viewers.push({ xForwardedFor: `0.${k}.${j}.${i},127.0.0.1` }) | ||
62 | } | ||
63 | } | ||
64 | } | ||
65 | |||
66 | console.log('Servers preparation finished.') | ||
67 | } | ||
68 | |||
69 | async function runViewers () { | ||
70 | console.log('Will run views of %d viewers.', viewers.length) | ||
71 | |||
72 | await Bluebird.map(viewers, viewer => { | ||
73 | return servers[0].views.simulateView({ id: videoId, xForwardedFor: viewer.xForwardedFor }) | ||
74 | }, { concurrency: 100 }) | ||
75 | |||
76 | await wait(5000) | ||
77 | } | ||