diff options
author | Chocobozzz <me@florianbigard.com> | 2018-08-29 16:26:25 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-08-30 15:03:18 +0200 |
commit | 6b6168606bc86430f6b7821c9d5f1c80d0425ebf (patch) | |
tree | 9aea6cf0875c9fee30c373eb4924b12d47d1e23c /server/initializers | |
parent | 2d9fea161fd4fc73994fc77951bafdccdc2071fd (diff) | |
download | PeerTube-6b6168606bc86430f6b7821c9d5f1c80d0425ebf.tar.gz PeerTube-6b6168606bc86430f6b7821c9d5f1c80d0425ebf.tar.zst PeerTube-6b6168606bc86430f6b7821c9d5f1c80d0425ebf.zip |
Bufferize videos views in redis
Diffstat (limited to 'server/initializers')
-rw-r--r-- | server/initializers/constants.ts | 20 | ||||
-rw-r--r-- | server/initializers/database.ts | 4 |
2 files changed, 19 insertions, 5 deletions
diff --git a/server/initializers/constants.ts b/server/initializers/constants.ts index 7f1b25654..2d9a2e670 100644 --- a/server/initializers/constants.ts +++ b/server/initializers/constants.ts | |||
@@ -3,11 +3,12 @@ import { dirname, join } from 'path' | |||
3 | import { JobType, VideoRateType, VideoState } from '../../shared/models' | 3 | import { JobType, VideoRateType, VideoState } from '../../shared/models' |
4 | import { ActivityPubActorType } from '../../shared/models/activitypub' | 4 | import { ActivityPubActorType } from '../../shared/models/activitypub' |
5 | import { FollowState } from '../../shared/models/actors' | 5 | import { FollowState } from '../../shared/models/actors' |
6 | import { VideoPrivacy, VideoAbuseState, VideoImportState } from '../../shared/models/videos' | 6 | import { VideoAbuseState, VideoImportState, VideoPrivacy } from '../../shared/models/videos' |
7 | // Do not use barrels, remain constants as independent as possible | 7 | // Do not use barrels, remain constants as independent as possible |
8 | import { buildPath, isTestInstance, root, sanitizeHost, sanitizeUrl } from '../helpers/core-utils' | 8 | import { buildPath, isTestInstance, root, sanitizeHost, sanitizeUrl } from '../helpers/core-utils' |
9 | import { NSFWPolicyType } from '../../shared/models/videos/nsfw-policy.type' | 9 | import { NSFWPolicyType } from '../../shared/models/videos/nsfw-policy.type' |
10 | import { invert } from 'lodash' | 10 | import { invert } from 'lodash' |
11 | import { CronRepeatOptions, EveryRepeatOptions } from 'bull' | ||
11 | 12 | ||
12 | // Use a variable to reload the configuration if we need | 13 | // Use a variable to reload the configuration if we need |
13 | let config: IConfig = require('config') | 14 | let config: IConfig = require('config') |
@@ -90,7 +91,8 @@ const JOB_ATTEMPTS: { [ id in JobType ]: number } = { | |||
90 | 'video-file-import': 1, | 91 | 'video-file-import': 1, |
91 | 'video-file': 1, | 92 | 'video-file': 1, |
92 | 'video-import': 1, | 93 | 'video-import': 1, |
93 | 'email': 5 | 94 | 'email': 5, |
95 | 'videos-views': 1 | ||
94 | } | 96 | } |
95 | const JOB_CONCURRENCY: { [ id in JobType ]: number } = { | 97 | const JOB_CONCURRENCY: { [ id in JobType ]: number } = { |
96 | 'activitypub-http-broadcast': 1, | 98 | 'activitypub-http-broadcast': 1, |
@@ -100,7 +102,8 @@ const JOB_CONCURRENCY: { [ id in JobType ]: number } = { | |||
100 | 'video-file-import': 1, | 102 | 'video-file-import': 1, |
101 | 'video-file': 1, | 103 | 'video-file': 1, |
102 | 'video-import': 1, | 104 | 'video-import': 1, |
103 | 'email': 5 | 105 | 'email': 5, |
106 | 'videos-views': 1 | ||
104 | } | 107 | } |
105 | const JOB_TTL: { [ id in JobType ]: number } = { | 108 | const JOB_TTL: { [ id in JobType ]: number } = { |
106 | 'activitypub-http-broadcast': 60000 * 10, // 10 minutes | 109 | 'activitypub-http-broadcast': 60000 * 10, // 10 minutes |
@@ -110,8 +113,15 @@ const JOB_TTL: { [ id in JobType ]: number } = { | |||
110 | 'video-file-import': 1000 * 3600, // 1 hour | 113 | 'video-file-import': 1000 * 3600, // 1 hour |
111 | 'video-file': 1000 * 3600 * 48, // 2 days, transcoding could be long | 114 | 'video-file': 1000 * 3600 * 48, // 2 days, transcoding could be long |
112 | 'video-import': 1000 * 3600 * 5, // 5 hours | 115 | 'video-import': 1000 * 3600 * 5, // 5 hours |
113 | 'email': 60000 * 10 // 10 minutes | 116 | 'email': 60000 * 10, // 10 minutes |
117 | 'videos-views': undefined // Unlimited | ||
114 | } | 118 | } |
119 | const REPEAT_JOBS: { [ id: string ]: EveryRepeatOptions | CronRepeatOptions } = { | ||
120 | 'videos-views': { | ||
121 | cron: '1 * * * *' // At 1 minutes past the hour | ||
122 | } | ||
123 | } | ||
124 | |||
115 | const BROADCAST_CONCURRENCY = 10 // How many requests in parallel we do in activitypub-http-broadcast job | 125 | const BROADCAST_CONCURRENCY = 10 // How many requests in parallel we do in activitypub-http-broadcast job |
116 | const CRAWL_REQUEST_CONCURRENCY = 1 // How many requests in parallel to fetch remote data (likes, shares...) | 126 | const CRAWL_REQUEST_CONCURRENCY = 1 // How many requests in parallel to fetch remote data (likes, shares...) |
117 | const JOB_REQUEST_TIMEOUT = 3000 // 3 seconds | 127 | const JOB_REQUEST_TIMEOUT = 3000 // 3 seconds |
@@ -591,6 +601,7 @@ if (isTestInstance() === true) { | |||
591 | SCHEDULER_INTERVALS_MS.badActorFollow = 10000 | 601 | SCHEDULER_INTERVALS_MS.badActorFollow = 10000 |
592 | SCHEDULER_INTERVALS_MS.removeOldJobs = 10000 | 602 | SCHEDULER_INTERVALS_MS.removeOldJobs = 10000 |
593 | SCHEDULER_INTERVALS_MS.updateVideos = 5000 | 603 | SCHEDULER_INTERVALS_MS.updateVideos = 5000 |
604 | REPEAT_JOBS['videos-views'] = { every: 5000 } | ||
594 | 605 | ||
595 | VIDEO_VIEW_LIFETIME = 1000 // 1 second | 606 | VIDEO_VIEW_LIFETIME = 1000 // 1 second |
596 | 607 | ||
@@ -652,6 +663,7 @@ export { | |||
652 | USER_PASSWORD_RESET_LIFETIME, | 663 | USER_PASSWORD_RESET_LIFETIME, |
653 | IMAGE_MIMETYPE_EXT, | 664 | IMAGE_MIMETYPE_EXT, |
654 | SCHEDULER_INTERVALS_MS, | 665 | SCHEDULER_INTERVALS_MS, |
666 | REPEAT_JOBS, | ||
655 | STATIC_DOWNLOAD_PATHS, | 667 | STATIC_DOWNLOAD_PATHS, |
656 | RATES_LIMIT, | 668 | RATES_LIMIT, |
657 | VIDEO_EXT_MIMETYPE, | 669 | VIDEO_EXT_MIMETYPE, |
diff --git a/server/initializers/database.ts b/server/initializers/database.ts index 0be752363..78bc8101c 100644 --- a/server/initializers/database.ts +++ b/server/initializers/database.ts | |||
@@ -25,6 +25,7 @@ import { CONFIG } from './constants' | |||
25 | import { ScheduleVideoUpdateModel } from '../models/video/schedule-video-update' | 25 | import { ScheduleVideoUpdateModel } from '../models/video/schedule-video-update' |
26 | import { VideoCaptionModel } from '../models/video/video-caption' | 26 | import { VideoCaptionModel } from '../models/video/video-caption' |
27 | import { VideoImportModel } from '../models/video/video-import' | 27 | import { VideoImportModel } from '../models/video/video-import' |
28 | import { VideoViewModel } from '../models/video/video-views' | ||
28 | 29 | ||
29 | require('pg').defaults.parseInt8 = true // Avoid BIGINT to be converted to string | 30 | require('pg').defaults.parseInt8 = true // Avoid BIGINT to be converted to string |
30 | 31 | ||
@@ -83,7 +84,8 @@ async function initDatabaseModels (silent: boolean) { | |||
83 | VideoModel, | 84 | VideoModel, |
84 | VideoCommentModel, | 85 | VideoCommentModel, |
85 | ScheduleVideoUpdateModel, | 86 | ScheduleVideoUpdateModel, |
86 | VideoImportModel | 87 | VideoImportModel, |
88 | VideoViewModel | ||
87 | ]) | 89 | ]) |
88 | 90 | ||
89 | // Check extensions exist in the database | 91 | // Check extensions exist in the database |