diff options
author | Chocobozzz <me@florianbigard.com> | 2022-06-17 10:49:37 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2022-06-17 11:55:03 +0200 |
commit | 3396e6534592865f184ee2db32a75957c42cb887 (patch) | |
tree | 324aeab92a27f2ffd1e8a16b09f0b5509bf8f477 /scripts | |
parent | b9e49a45f5441fd1a2d49a10b88aaf4d425dc992 (diff) | |
download | PeerTube-3396e6534592865f184ee2db32a75957c42cb887.tar.gz PeerTube-3396e6534592865f184ee2db32a75957c42cb887.tar.zst PeerTube-3396e6534592865f184ee2db32a75957c42cb887.zip |
Optimize broadcast job creation
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/simulate-many-viewers.ts | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/scripts/simulate-many-viewers.ts b/scripts/simulate-many-viewers.ts index 4ec928aa8..fb666c318 100644 --- a/scripts/simulate-many-viewers.ts +++ b/scripts/simulate-many-viewers.ts | |||
@@ -1,6 +1,13 @@ | |||
1 | import Bluebird from 'bluebird' | 1 | import Bluebird from 'bluebird' |
2 | import { wait } from '@shared/core-utils' | 2 | import { wait } from '@shared/core-utils' |
3 | import { createSingleServer, doubleFollow, PeerTubeServer, setAccessTokensToServers, waitJobs } from '@shared/server-commands' | 3 | import { |
4 | createSingleServer, | ||
5 | doubleFollow, | ||
6 | killallServers, | ||
7 | PeerTubeServer, | ||
8 | setAccessTokensToServers, | ||
9 | waitJobs | ||
10 | } from '@shared/server-commands' | ||
4 | 11 | ||
5 | let servers: PeerTubeServer[] | 12 | let servers: PeerTubeServer[] |
6 | const viewers: { xForwardedFor: string }[] = [] | 13 | const viewers: { xForwardedFor: string }[] = [] |
@@ -9,6 +16,7 @@ let videoId: string | |||
9 | run() | 16 | run() |
10 | .then(() => process.exit(0)) | 17 | .then(() => process.exit(0)) |
11 | .catch(err => console.error(err)) | 18 | .catch(err => console.error(err)) |
19 | .finally(() => killallServers(servers)) | ||
12 | 20 | ||
13 | async function run () { | 21 | async function run () { |
14 | await prepare() | 22 | await prepare() |
@@ -69,9 +77,13 @@ async function prepare () { | |||
69 | async function runViewers () { | 77 | async function runViewers () { |
70 | console.log('Will run views of %d viewers.', viewers.length) | 78 | console.log('Will run views of %d viewers.', viewers.length) |
71 | 79 | ||
80 | const before = new Date().getTime() | ||
81 | |||
72 | await Bluebird.map(viewers, viewer => { | 82 | await Bluebird.map(viewers, viewer => { |
73 | return servers[0].views.simulateView({ id: videoId, xForwardedFor: viewer.xForwardedFor }) | 83 | return servers[0].views.simulateView({ id: videoId, xForwardedFor: viewer.xForwardedFor }) |
74 | }, { concurrency: 100 }) | 84 | }, { concurrency: 100 }) |
75 | 85 | ||
86 | console.log('Finished to run views in %d seconds.', (new Date().getTime() - before) / 1000) | ||
87 | |||
76 | await wait(5000) | 88 | await wait(5000) |
77 | } | 89 | } |