aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2022-06-17 10:48:37 +0200
committerChocobozzz <me@florianbigard.com>2022-06-17 10:48:37 +0200
commitb9e49a45f5441fd1a2d49a10b88aaf4d425dc992 (patch)
tree3dc706c226a4d56ffcabab72f017d2b56ebcd4d9
parent42e6a7a747f5349ac3434ee44273e50966630440 (diff)
downloadPeerTube-b9e49a45f5441fd1a2d49a10b88aaf4d425dc992.tar.gz
PeerTube-b9e49a45f5441fd1a2d49a10b88aaf4d425dc992.tar.zst
PeerTube-b9e49a45f5441fd1a2d49a10b88aaf4d425dc992.zip
Add simulate many viewers script
Helps us to improve views scalability on peertube
-rw-r--r--scripts/simulate-many-viewers.ts77
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 @@
1import Bluebird from 'bluebird'
2import { wait } from '@shared/core-utils'
3import { createSingleServer, doubleFollow, PeerTubeServer, setAccessTokensToServers, waitJobs } from '@shared/server-commands'
4
5let servers: PeerTubeServer[]
6const viewers: { xForwardedFor: string }[] = []
7let videoId: string
8
9run()
10 .then(() => process.exit(0))
11 .catch(err => console.error(err))
12
13async function run () {
14 await prepare()
15
16 while (true) {
17 await runViewers()
18 }
19}
20
21async 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
69async 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}