try use p-limit instead of bottleneck

This commit is contained in:
TheBeastLT
2024-01-28 02:12:41 +02:00
parent 64b8a55f3b
commit 3bf13e68ba
3 changed files with 31 additions and 2 deletions

View File

@@ -10,6 +10,7 @@ import applyFilters from './lib/filter.js';
import { applyMochs, getMochCatalog, getMochItemMeta } from './moch/moch.js';
import StaticLinks from './moch/static.js';
import { createNamedQueue } from "./lib/namedQueue.js";
import pLimit from "p-limit";
const CACHE_MAX_AGE = parseInt(process.env.CACHE_MAX_AGE) || 60 * 60; // 1 hour in seconds
const CACHE_MAX_AGE_EMPTY = 60; // 60 seconds
@@ -24,6 +25,7 @@ const limiter = new Bottleneck({
highWater: process.env.LIMIT_QUEUE_SIZE || 100,
strategy: Bottleneck.strategy.OVERFLOW
});
const newLimiter = pLimit(40)
const limiterOptions = { expiration: 2 * 60 * 1000 }
builder.defineStreamHandler((args) => {
@@ -69,14 +71,14 @@ builder.defineMetaHandler((args) => {
})
async function resolveStreams(args) {
return cacheWrapStream(args.id, () => limiter.schedule(limiterOptions, () => streamHandler(args)
return cacheWrapStream(args.id, () => newLimiter(() => streamHandler(args)
.then(records => records
.sort((a, b) => b.torrent.seeders - a.torrent.seeders || b.torrent.uploadDate - a.torrent.uploadDate)
.map(record => toStreamInfo(record)))));
}
async function streamHandler(args) {
console.log(`Current stats: `, limiter.counts())
console.log(`Pending count: ${newLimiter.pendingCount}, active count: ${newLimiter.activeCount}`, )
if (args.type === Type.MOVIE) {
return movieRecordsHandler(args);
} else if (args.type === Type.SERIES) {

View File

@@ -22,6 +22,7 @@
"name-to-imdb": "^3.0.4",
"named-queue": "^2.2.1",
"offcloud-api": "^1.0.2",
"p-limit": "^5.0.0",
"parse-torrent-title": "git://github.com/TheBeastLT/parse-torrent-title.git#022408972c2a040f846331a912a6a8487746a654",
"pg": "^8.10.0",
"premiumize-api": "^1.0.3",
@@ -1428,6 +1429,20 @@
"node": ">=0.10.0"
}
},
"node_modules/p-limit": {
"version": "5.0.0",
"resolved": "https://registry.npmjs.org/p-limit/-/p-limit-5.0.0.tgz",
"integrity": "sha512-/Eaoq+QyLSiXQ4lyYV23f14mZRQcXnxfHrN0vCai+ak9G0pp9iEQukIIZq5NccEvwRB8PUnZT0KsOoDCINS1qQ==",
"dependencies": {
"yocto-queue": "^1.0.0"
},
"engines": {
"node": ">=18"
},
"funding": {
"url": "https://github.com/sponsors/sindresorhus"
}
},
"node_modules/packet-reader": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/packet-reader/-/packet-reader-1.0.0.tgz",
@@ -2499,6 +2514,17 @@
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz",
"integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A=="
},
"node_modules/yocto-queue": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/yocto-queue/-/yocto-queue-1.0.0.tgz",
"integrity": "sha512-9bnSc/HEW2uRy67wc+T8UwauLuPJVn28jb+GtJY16iiKWyvmYJRXVT4UamsAEGQfPohgr2q4Tq0sQbQlxTfi1g==",
"engines": {
"node": ">=12.20"
},
"funding": {
"url": "https://github.com/sponsors/sindresorhus"
}
}
}
}

View File

@@ -22,6 +22,7 @@
"name-to-imdb": "^3.0.4",
"named-queue": "^2.2.1",
"offcloud-api": "^1.0.2",
"p-limit": "^5.0.0",
"parse-torrent-title": "git://github.com/TheBeastLT/parse-torrent-title.git#022408972c2a040f846331a912a6a8487746a654",
"pg": "^8.10.0",
"premiumize-api": "^1.0.3",