diff options
author | Chocobozzz <me@florianbigard.com> | 2018-04-18 16:04:49 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-04-18 16:04:49 +0200 |
commit | f55e5a7bf81c2c27db1514273e3366511aabf4ae (patch) | |
tree | 7374d57557b770fbbea8b9410ec6f2e133a086c0 /server | |
parent | 5350fd8e5b2b2d017b16d97828893a8a4a40bd89 (diff) | |
download | PeerTube-f55e5a7bf81c2c27db1514273e3366511aabf4ae.tar.gz PeerTube-f55e5a7bf81c2c27db1514273e3366511aabf4ae.tar.zst PeerTube-f55e5a7bf81c2c27db1514273e3366511aabf4ae.zip |
Process broadcast requests in parallel
Diffstat (limited to 'server')
-rw-r--r-- | server/initializers/constants.ts | 2 | ||||
-rw-r--r-- | server/lib/job-queue/handlers/activitypub-http-broadcast.ts | 17 |
2 files changed, 9 insertions, 10 deletions
diff --git a/server/initializers/constants.ts b/server/initializers/constants.ts index ffcbe69b8..5ee13389d 100644 --- a/server/initializers/constants.ts +++ b/server/initializers/constants.ts | |||
@@ -77,6 +77,7 @@ const JOB_CONCURRENCY: { [ id in JobType ]: number } = { | |||
77 | 'video-file': 1, | 77 | 'video-file': 1, |
78 | 'email': 5 | 78 | 'email': 5 |
79 | } | 79 | } |
80 | const BROADCAST_CONCURRENCY = 5 // How many requests in parallel we do in activitypub-http-broadcast job | ||
80 | // 2 days | 81 | // 2 days |
81 | const JOB_COMPLETED_LIFETIME = 60000 * 60 * 24 * 2 | 82 | const JOB_COMPLETED_LIFETIME = 60000 * 60 * 24 * 2 |
82 | 83 | ||
@@ -463,6 +464,7 @@ export { | |||
463 | LAST_MIGRATION_VERSION, | 464 | LAST_MIGRATION_VERSION, |
464 | OAUTH_LIFETIME, | 465 | OAUTH_LIFETIME, |
465 | OPENGRAPH_AND_OEMBED_COMMENT, | 466 | OPENGRAPH_AND_OEMBED_COMMENT, |
467 | BROADCAST_CONCURRENCY, | ||
466 | PAGINATION_COUNT_DEFAULT, | 468 | PAGINATION_COUNT_DEFAULT, |
467 | ACTOR_FOLLOW_SCORE, | 469 | ACTOR_FOLLOW_SCORE, |
468 | PREVIEWS_SIZE, | 470 | PREVIEWS_SIZE, |
diff --git a/server/lib/job-queue/handlers/activitypub-http-broadcast.ts b/server/lib/job-queue/handlers/activitypub-http-broadcast.ts index 78878fc01..38b8393f4 100644 --- a/server/lib/job-queue/handlers/activitypub-http-broadcast.ts +++ b/server/lib/job-queue/handlers/activitypub-http-broadcast.ts | |||
@@ -1,8 +1,10 @@ | |||
1 | import * as kue from 'kue' | 1 | import * as kue from 'kue' |
2 | import * as Bluebird from 'bluebird' | ||
2 | import { logger } from '../../../helpers/logger' | 3 | import { logger } from '../../../helpers/logger' |
3 | import { doRequest } from '../../../helpers/requests' | 4 | import { doRequest } from '../../../helpers/requests' |
4 | import { ActorFollowModel } from '../../../models/activitypub/actor-follow' | 5 | import { ActorFollowModel } from '../../../models/activitypub/actor-follow' |
5 | import { buildSignedRequestOptions, computeBody } from './utils/activitypub-http-utils' | 6 | import { buildSignedRequestOptions, computeBody } from './utils/activitypub-http-utils' |
7 | import { BROADCAST_CONCURRENCY } from '../../../initializers' | ||
6 | 8 | ||
7 | export type ActivitypubHttpBroadcastPayload = { | 9 | export type ActivitypubHttpBroadcastPayload = { |
8 | uris: string[] | 10 | uris: string[] |
@@ -28,16 +30,11 @@ async function processActivityPubHttpBroadcast (job: kue.Job) { | |||
28 | const badUrls: string[] = [] | 30 | const badUrls: string[] = [] |
29 | const goodUrls: string[] = [] | 31 | const goodUrls: string[] = [] |
30 | 32 | ||
31 | for (const uri of payload.uris) { | 33 | await Bluebird.map(payload.uris, uri => { |
32 | options.uri = uri | 34 | return doRequest(Object.assign({}, options, { uri })) |
33 | 35 | .then(() => goodUrls.push(uri)) | |
34 | try { | 36 | .catch(() => badUrls.push(uri)) |
35 | await doRequest(options) | 37 | }, { concurrency: BROADCAST_CONCURRENCY }) |
36 | goodUrls.push(uri) | ||
37 | } catch (err) { | ||
38 | badUrls.push(uri) | ||
39 | } | ||
40 | } | ||
41 | 38 | ||
42 | return ActorFollowModel.updateActorFollowsScore(goodUrls, badUrls, undefined) | 39 | return ActorFollowModel.updateActorFollowsScore(goodUrls, badUrls, undefined) |
43 | } | 40 | } |