aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/initializers
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-08-29 16:26:25 +0200
committerChocobozzz <me@florianbigard.com>2018-08-30 15:03:18 +0200
commit6b6168606bc86430f6b7821c9d5f1c80d0425ebf (patch)
tree9aea6cf0875c9fee30c373eb4924b12d47d1e23c /server/initializers
parent2d9fea161fd4fc73994fc77951bafdccdc2071fd (diff)
downloadPeerTube-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.ts20
-rw-r--r--server/initializers/database.ts4
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'
3import { JobType, VideoRateType, VideoState } from '../../shared/models' 3import { JobType, VideoRateType, VideoState } from '../../shared/models'
4import { ActivityPubActorType } from '../../shared/models/activitypub' 4import { ActivityPubActorType } from '../../shared/models/activitypub'
5import { FollowState } from '../../shared/models/actors' 5import { FollowState } from '../../shared/models/actors'
6import { VideoPrivacy, VideoAbuseState, VideoImportState } from '../../shared/models/videos' 6import { 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
8import { buildPath, isTestInstance, root, sanitizeHost, sanitizeUrl } from '../helpers/core-utils' 8import { buildPath, isTestInstance, root, sanitizeHost, sanitizeUrl } from '../helpers/core-utils'
9import { NSFWPolicyType } from '../../shared/models/videos/nsfw-policy.type' 9import { NSFWPolicyType } from '../../shared/models/videos/nsfw-policy.type'
10import { invert } from 'lodash' 10import { invert } from 'lodash'
11import { 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
13let config: IConfig = require('config') 14let 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}
95const JOB_CONCURRENCY: { [ id in JobType ]: number } = { 97const 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}
105const JOB_TTL: { [ id in JobType ]: number } = { 108const 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}
119const REPEAT_JOBS: { [ id: string ]: EveryRepeatOptions | CronRepeatOptions } = {
120 'videos-views': {
121 cron: '1 * * * *' // At 1 minutes past the hour
122 }
123}
124
115const BROADCAST_CONCURRENCY = 10 // How many requests in parallel we do in activitypub-http-broadcast job 125const BROADCAST_CONCURRENCY = 10 // How many requests in parallel we do in activitypub-http-broadcast job
116const CRAWL_REQUEST_CONCURRENCY = 1 // How many requests in parallel to fetch remote data (likes, shares...) 126const CRAWL_REQUEST_CONCURRENCY = 1 // How many requests in parallel to fetch remote data (likes, shares...)
117const JOB_REQUEST_TIMEOUT = 3000 // 3 seconds 127const 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'
25import { ScheduleVideoUpdateModel } from '../models/video/schedule-video-update' 25import { ScheduleVideoUpdateModel } from '../models/video/schedule-video-update'
26import { VideoCaptionModel } from '../models/video/video-caption' 26import { VideoCaptionModel } from '../models/video/video-caption'
27import { VideoImportModel } from '../models/video/video-import' 27import { VideoImportModel } from '../models/video/video-import'
28import { VideoViewModel } from '../models/video/video-views'
28 29
29require('pg').defaults.parseInt8 = true // Avoid BIGINT to be converted to string 30require('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