Changeset 201ec06 in Klonkt
- Timestamp:
- 06/28/2026 05:15:48 PM (2 months ago)
- Branches:
- main
- Children:
- a64d705
- Parents:
- 99989f9
- File:
-
- 1 edited
-
src/services/ThumbnailService.js (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/services/ThumbnailService.js
r99989f9 r201ec06 27 27 28 28 let _seq = 0; 29 30 // Limit concurrent ffmpeg spawns. A cold-cache, image-heavy page fires many thumbnail 31 // requests at once; without a cap each spawns its own ffmpeg → CPU saturation makes the 32 // WHOLE instance slow (the thundering herd). With the cap, excess requests wait briefly 33 // for a slot → bounded CPU, the page still loads (images just appear progressively). 34 const MAX_CONCURRENT = 3; 35 let _active = 0; 36 const _waiters = []; 37 function acquireSlot() { 38 if (_active < MAX_CONCURRENT) { _active++; return Promise.resolve(); } 39 return new Promise((resolve) => _waiters.push(resolve)); 40 } 41 function releaseSlot() { 42 const next = _waiters.shift(); 43 if (next) next(); // transfer the slot directly to the next waiter (_active unchanged) 44 else _active--; 45 } 46 async function runFfmpeg(args) { 47 await acquireSlot(); 48 try { await execFileP(ffmpegPath, args, { timeout: 20000 }); } 49 finally { releaseSlot(); } 50 } 29 51 30 52 function mediaRoot() { … … 57 79 const tmp = `${cached}.tmp-${process.pid}-${_seq++}`; 58 80 try { 59 await execFileP(ffmpegPath,[81 await runFfmpeg([ 60 82 '-hide_banner', '-loglevel', 'error', '-y', 61 83 '-i', orig, … … 68 90 '-f', 'webp', 69 91 tmp, 70 ] , { timeout: 20000 });92 ]); 71 93 await fs.promises.rename(tmp, cached); 72 94 return cached; … … 143 165 try { 144 166 await fs.promises.writeFile(tmpIn, buf); 145 await execFileP(ffmpegPath,[167 await runFfmpeg([ 146 168 '-hide_banner', '-loglevel', 'error', '-y', 147 169 '-i', tmpIn, … … 150 172 '-c:v', 'libwebp', '-q:v', '82', '-f', 'webp', 151 173 tmpOut, 152 ] , { timeout: 20000 });174 ]); 153 175 await fs.promises.rename(tmpOut, cached); 154 176 return cached;
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)