Send views in a dedicated queue

pull/5067/head
Chocobozzz 2022-06-17 14:08:13 +02:00
parent 3396e65345
commit f27b7a750f
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
6 changed files with 24 additions and 5 deletions

View File

@ -25,6 +25,7 @@ export class JobsComponent extends RestTable implements OnInit {
'activitypub-follow',
'activitypub-http-broadcast',
'activitypub-http-broadcast-parallel',
'activitypub-http-fetcher',
'activitypub-http-unicast',
'activitypub-refresher',

View File

@ -139,6 +139,7 @@ const REMOTE_SCHEME = {
const JOB_ATTEMPTS: { [id in JobType]: number } = {
'activitypub-http-broadcast': 1,
'activitypub-http-broadcast-parallel': 1,
'activitypub-http-unicast': 1,
'activitypub-http-fetcher': 2,
'activitypub-follow': 5,
@ -159,6 +160,7 @@ const JOB_ATTEMPTS: { [id in JobType]: number } = {
// Excluded keys are jobs that can be configured by admins
const JOB_CONCURRENCY: { [id in Exclude<JobType, 'video-transcoding' | 'video-import'>]: number } = {
'activitypub-http-broadcast': 1,
'activitypub-http-broadcast-parallel': 30,
'activitypub-http-unicast': 10,
'activitypub-http-fetcher': 3,
'activitypub-cleaner': 1,
@ -176,6 +178,7 @@ const JOB_CONCURRENCY: { [id in Exclude<JobType, 'video-transcoding' | 'video-im
}
const JOB_TTL: { [id in JobType]: number } = {
'activitypub-http-broadcast': 60000 * 10, // 10 minutes
'activitypub-http-broadcast-parallel': 60000 * 10, // 10 minutes
'activitypub-http-unicast': 60000 * 10, // 10 minutes
'activitypub-http-fetcher': 1000 * 3600 * 10, // 10 hours
'activitypub-follow': 60000 * 10, // 10 minutes

View File

@ -26,7 +26,7 @@ async function sendView (options: {
return buildViewActivity({ url, byActor, video, audience, type })
}
return sendVideoRelatedActivity(activityBuilder, { byActor, video, transaction, contextType: 'View' })
return sendVideoRelatedActivity(activityBuilder, { byActor, video, transaction, contextType: 'View', parallelizable: true })
}
// ---------------------------------------------------------------------------

View File

@ -15,9 +15,10 @@ async function sendVideoRelatedActivity (activityBuilder: (audience: ActivityAud
byActor: MActorLight
video: MVideoImmutable | MVideoAccountLight
contextType: ContextType
parallelizable?: boolean
transaction?: Transaction
}) {
const { byActor, video, transaction, contextType } = options
const { byActor, video, transaction, contextType, parallelizable } = options
// Send to origin
if (video.isOwned() === false) {
@ -38,6 +39,7 @@ async function sendVideoRelatedActivity (activityBuilder: (audience: ActivityAud
toFollowersOf: actorsInvolvedInVideo,
transaction,
actorsException,
parallelizable,
contextType
})
}
@ -130,9 +132,10 @@ async function broadcastToFollowers (options: {
transaction: Transaction
contextType: ContextType
parallelizable?: boolean
actorsException?: MActorWithInboxes[]
}) {
const { data, byActor, toFollowersOf, transaction, contextType, actorsException = [] } = options
const { data, byActor, toFollowersOf, transaction, contextType, actorsException = [], parallelizable } = options
const uris = await computeFollowerUris(toFollowersOf, actorsException, transaction)
@ -141,6 +144,7 @@ async function broadcastToFollowers (options: {
uris,
data,
byActor,
parallelizable,
contextType
})
})
@ -173,8 +177,9 @@ function broadcastTo (options: {
data: any
byActor: MActorId
contextType: ContextType
parallelizable?: boolean // default to false
}) {
const { uris, data, byActor, contextType } = options
const { uris, data, byActor, contextType, parallelizable } = options
if (uris.length === 0) return undefined
@ -200,7 +205,13 @@ function broadcastTo (options: {
contextType
}
JobQueue.Instance.createJob({ type: 'activitypub-http-broadcast', payload })
JobQueue.Instance.createJob({
type: parallelizable
? 'activitypub-http-broadcast-parallel'
: 'activitypub-http-broadcast',
payload
})
}
for (const unicastUri of unicastUris) {

View File

@ -43,6 +43,7 @@ import { processVideosViewsStats } from './handlers/video-views-stats'
type CreateJobArgument =
{ type: 'activitypub-http-broadcast', payload: ActivitypubHttpBroadcastPayload } |
{ type: 'activitypub-http-broadcast-parallel', payload: ActivitypubHttpBroadcastPayload } |
{ type: 'activitypub-http-unicast', payload: ActivitypubHttpUnicastPayload } |
{ type: 'activitypub-http-fetcher', payload: ActivitypubHttpFetcherPayload } |
{ type: 'activitypub-http-cleaner', payload: {} } |
@ -68,6 +69,7 @@ export type CreateJobOptions = {
const handlers: { [id in JobType]: (job: Job) => Promise<any> } = {
'activitypub-http-broadcast': processActivityPubHttpBroadcast,
'activitypub-http-broadcast-parallel': processActivityPubHttpBroadcast,
'activitypub-http-unicast': processActivityPubHttpUnicast,
'activitypub-http-fetcher': processActivityPubHttpFetcher,
'activitypub-cleaner': processActivityPubCleaner,
@ -89,6 +91,7 @@ const handlers: { [id in JobType]: (job: Job) => Promise<any> } = {
const jobTypes: JobType[] = [
'activitypub-follow',
'activitypub-http-broadcast',
'activitypub-http-broadcast-parallel',
'activitypub-http-fetcher',
'activitypub-http-unicast',
'activitypub-cleaner',

View File

@ -9,6 +9,7 @@ export type JobState = 'active' | 'completed' | 'failed' | 'waiting' | 'delayed'
export type JobType =
| 'activitypub-http-unicast'
| 'activitypub-http-broadcast'
| 'activitypub-http-broadcast-parallel'
| 'activitypub-http-fetcher'
| 'activitypub-cleaner'
| 'activitypub-follow'