@torrent-tv/proxy 2.98.11 → 2.98.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@torrent-tv/proxy",
3
- "version": "2.98.11",
3
+ "version": "2.98.12",
4
4
  "description": "Torrent proxy client that exposes webseed-like HTTP stream endpoint.",
5
5
  "license": "GPL-3.0-or-later",
6
6
  "repository": {
@@ -362,6 +362,26 @@ export function planEncoders({
362
362
  const decided = new Map();
363
363
  const room = Math.max(0, maxRuns - live.length);
364
364
  const refetchPerSegment = segmentSeconds * refetchSecPerFilmSecond;
365
+ // WHAT "NEVER" IS, ONE FIGURE FOR EVERY ARRANGEMENT THIS PASS COMPARES: later
366
+ // than any encoder here can reach the last wanted number — the film's length,
367
+ // a start and a stop, the whole wanted stretch at the slowest rate any
368
+ // arrangement can run at, and every piece fetched again. Capped at the film's
369
+ // length instead, a slow encoder's arrival scored as never; and worked out
370
+ // from each arrangement's own encoders, the arrangement without an encoder
371
+ // had a smaller never than the one with it. Either way an encoder making the
372
+ // film behind the viewer at 0.57x scored no better than none, and the plan
373
+ // stopped it before its first piece, then started it again when the speed
374
+ // read 1.9x — thirteen times in three minutes on Home Assistant, each start
375
+ // copying 108-122 MB of input (r37, torrent-tv/meta#178).
376
+ const neverSec = (() => {
377
+ const first = Math.min(...wanted.map((span) => span.from));
378
+ const last = Math.max(...wanted.map((span) => span.to));
379
+ const film = (last + 1) * segmentSeconds;
380
+ const slowest = rate / contentionPenaltyFor(Math.max(maxRuns, live.length));
381
+ if (!(slowest > 0) || !Number.isFinite(film)) return film;
382
+ return film + firstByteWaitSec + killCostSec + (last - first + 2) / slowest +
383
+ (last - first + 1) * refetchPerSegment + segmentSeconds;
384
+ })();
365
385
 
366
386
  let arrangements = [{ fill: [], used: new Set(), fresh: 0 }];
367
387
  for (let index = 0; index < positions.length; index += 1) {
@@ -441,7 +461,7 @@ export function planEncoders({
441
461
  : (piece) => finishesItsPieceIn(run, piece)
442
462
  });
443
463
  }
444
- const scored = latenessOf(priced(encoders), coverage, wanted, untilNeeded, rate / contentionPenaltyFor(Math.max(0, encoders.length - 1)), refetchPerSegment, segmentSeconds);
464
+ const scored = latenessOf(priced(encoders), coverage, wanted, untilNeeded, rate / contentionPenaltyFor(Math.max(0, encoders.length - 1)), refetchPerSegment, segmentSeconds, neverSec);
445
465
  if (bestScore === null || cheaperThan(scored, bestScore)) {
446
466
  bestScore = scored;
447
467
  best = arrangement;
@@ -492,7 +512,7 @@ export function planEncoders({
492
512
  const scoreOf = (override) => {
493
513
  const encoders = encodersOf(override);
494
514
  return latenessOf(encoders, coverage, wanted, untilNeeded,
495
- rate / contentionPenaltyFor(Math.max(0, encoders.length - 1)), refetchPerSegment, segmentSeconds);
515
+ rate / contentionPenaltyFor(Math.max(0, encoders.length - 1)), refetchPerSegment, segmentSeconds, neverSec);
496
516
  };
497
517
  for (const run of live) {
498
518
  if (placement.has(run)) {
@@ -519,7 +539,7 @@ export function planEncoders({
519
539
  const kept = encodersOf(new Map());
520
540
  const without = encodersOf(new Map([[run, null]]));
521
541
  const scoreOf_ = (encoders) => latenessOf(encoders, coverage, wanted, untilNeeded,
522
- rate / contentionPenaltyFor(Math.max(0, encoders.length - 1)), refetchPerSegment, segmentSeconds);
542
+ rate / contentionPenaltyFor(Math.max(0, encoders.length - 1)), refetchPerSegment, segmentSeconds, neverSec);
523
543
  return cheaperThan(scoreOf_(kept), scoreOf_(without));
524
544
  };
525
545
 
@@ -586,7 +606,7 @@ export function planEncoders({
586
606
  continue;
587
607
  }
588
608
  const without = latenessOf(encodersOf(new Map([[run, null]])), coverage, wanted, untilNeeded,
589
- rate / contentionPenaltyFor(Math.max(0, live.length - 2)), refetchPerSegment, segmentSeconds);
609
+ rate / contentionPenaltyFor(Math.max(0, live.length - 2)), refetchPerSegment, segmentSeconds, neverSec);
590
610
  if (cheapestScore === null || cheaperThan(without, cheapestScore)) {
591
611
  cheapestScore = without;
592
612
  cheapest = run;
@@ -751,13 +771,14 @@ function ranksOf(wanted, first, last) {
751
771
  return rankAt;
752
772
  }
753
773
 
754
- function latenessOf(encoders, coverage, wanted, untilNeeded, rate, refetchSecPerSegment, segmentSeconds) {
774
+ function latenessOf(encoders, coverage, wanted, untilNeeded, rate, refetchSecPerSegment, segmentSeconds, neverSec = null) {
755
775
  const first = Math.min(...wanted.map((span) => span.from));
756
776
  const last = Math.max(...wanted.map((span) => span.to));
757
- // What a number nobody reaches at all counts as. The film's own length is the
758
- // honest bound — nothing can be later than never — and a finite figure is what
759
- // lets two hopeless arrangements still be told apart by the rest of the sum.
760
- const never = (last + 1) * segmentSeconds;
777
+ // What a number nobody reaches at all counts as: one figure for every
778
+ // arrangement the plan compares, later than any arrival (`neverSec` in
779
+ // `planEncoders`), and finite, so two hopeless arrangements are still told
780
+ // apart by the rest of the sum. Without it, the film's own length.
781
+ const never = Number.isFinite(neverSec) ? neverSec : (last + 1) * segmentSeconds;
761
782
 
762
783
  // WHICH SIDE OF THE VIEWERS a piece is on. The map states it; nothing here
763
784
  // works it out from positions, and nothing here knows where a viewer stands.
@@ -876,7 +897,7 @@ function latenessOf(encoders, coverage, wanted, untilNeeded, rate, refetchSecPer
876
897
  // gives. It is a definition rather than a guard: it also makes the score
877
898
  // total on a host whose startup measured nothing at all, where every arrival
878
899
  // is beyond reckoning and every arrangement is therefore equally hopeless.
879
- const when = byWhom === null ? never : Math.min(soonest, never);
900
+ const when = byWhom === null || !Number.isFinite(soonest) ? never : soonest;
880
901
  const rank = rankAt(index);
881
902
  doneAt.set(rank, Math.max(doneAt.get(rank) ?? 0, when));
882
903
  const deadline = untilNeeded(index);