Skip to content

Commit 9d104c8

Browse files
committed
Limited sharp concurrency to reduce memory fragmentation
refs lovell/sharp#955 (comment) - we've seen Ghost hogging memory whenever images are uploaded - it seems to be due to an issue with memory fragmentation, because a heap snapshot of a container after the memory grows shows nothing in JS code - we've been using jemalloc in production but it still seems to occur - this change has been suggested on the referenced thread in order to improve fragmentation on top of using jemalloc - can easily revert if it causes issues
1 parent 6fc5dc1 commit 9d104c8

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

packages/image-transform/lib/transform.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ const unsafeResizeFromBuffer = async (originalBuffer, options = {}) => {
8686
// Disable the internal libvips cache - https://sharp.pixelplumbing.com/api-utility#cache
8787
sharp.cache(false);
8888

89+
// Limit the concurrency of sharp tasks - https://sharp.pixelplumbing.com/api-utility#concurrency
90+
sharp.concurrency(1);
91+
8992
// It is safe to set animated to true for all formats, because if the input image doesn't contain animation
9093
// nothing will change.
9194
let animated = options.animated ?? true;

packages/image-transform/test/transform.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ describe('Transform', function () {
9494
});
9595

9696
sharp.cache = sinon.stub().returns({});
97+
sharp.concurrency = sinon.stub().returns({});
9798

9899
testUtils.modules.mockNonExistentModule('sharp', sharp);
99100
});

0 commit comments

Comments
 (0)