aboutsummaryrefslogtreecommitdiffhomepage
path: root/scripts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2022-06-17 14:17:06 +0200
committerChocobozzz <me@florianbigard.com>2022-06-17 14:17:06 +0200
commitfba911e2c89708a166636e3a93fcd8fcbc3de7e1 (patch)
tree8ad1e9c9abf3b021e343ed35618aa5d606fe03e5 /scripts
parente69d1ed5cd4cc2b40914af98ffd8d54dff04cc9e (diff)
parentf27b7a750f1876632e84d594608d3d64ce974efc (diff)
downloadPeerTube-fba911e2c89708a166636e3a93fcd8fcbc3de7e1.tar.gz
PeerTube-fba911e2c89708a166636e3a93fcd8fcbc3de7e1.tar.zst
PeerTube-fba911e2c89708a166636e3a93fcd8fcbc3de7e1.zip
Merge branch 'release/4.2.0' into develop
Diffstat (limited to 'scripts')
-rw-r--r--scripts/simulate-many-viewers.ts89
1 files changed, 89 insertions, 0 deletions
diff --git a/scripts/simulate-many-viewers.ts b/scripts/simulate-many-viewers.ts
new file mode 100644
index 000000000..fb666c318
--- /dev/null
+++ b/scripts/simulate-many-viewers.ts
@@ -0,0 +1,89 @@
1import Bluebird from 'bluebird'
2import { wait } from '@shared/core-utils'
3import {
4 createSingleServer,
5 doubleFollow,
6 killallServers,
7 PeerTubeServer,
8 setAccessTokensToServers,
9 waitJobs
10} from '@shared/server-commands'
11
12let servers: PeerTubeServer[]
13const viewers: { xForwardedFor: string }[] = []
14let videoId: string
15
16run()
17 .then(() => process.exit(0))
18 .catch(err => console.error(err))
19 .finally(() => killallServers(servers))
20
21async function run () {
22 await prepare()
23
24 while (true) {
25 await runViewers()
26 }
27}
28
29async function prepare () {
30 console.log('Preparing servers...')
31
32 const config = {
33 log: {
34 level: 'info'
35 },
36 rates_limit: {
37 api: {
38 max: 5_000_000
39 }
40 },
41 views: {
42 videos: {
43 local_buffer_update_interval: '30 minutes',
44 ip_view_expiration: '1 hour'
45 }
46 }
47 }
48
49 servers = await Promise.all([
50 createSingleServer(1, config, { nodeArgs: [ '--inspect' ] }),
51 createSingleServer(2, config),
52 createSingleServer(3, config)
53 ])
54
55 await setAccessTokensToServers(servers)
56 await doubleFollow(servers[0], servers[1])
57 await doubleFollow(servers[0], servers[2])
58
59 const { uuid } = await servers[0].videos.quickUpload({ name: 'video' })
60 videoId = uuid
61
62 await waitJobs(servers)
63
64 const THOUSAND_VIEWERS = 2
65
66 for (let i = 2; i < 252; i++) {
67 for (let j = 2; j < 6; j++) {
68 for (let k = 2; k < THOUSAND_VIEWERS + 2; k++) {
69 viewers.push({ xForwardedFor: `0.${k}.${j}.${i},127.0.0.1` })
70 }
71 }
72 }
73
74 console.log('Servers preparation finished.')
75}
76
77async function runViewers () {
78 console.log('Will run views of %d viewers.', viewers.length)
79
80 const before = new Date().getTime()
81
82 await Bluebird.map(viewers, viewer => {
83 return servers[0].views.simulateView({ id: videoId, xForwardedFor: viewer.xForwardedFor })
84 }, { concurrency: 100 })
85
86 console.log('Finished to run views in %d seconds.', (new Date().getTime() - before) / 1000)
87
88 await wait(5000)
89}