mirror of
https://github.com/lovell/sharp.git
synced 2025-07-12 20:10:13 +02:00
Expose depth of task queue
This commit is contained in:
parent
8acb0ed5d0
commit
fbe5c18762
@ -257,9 +257,9 @@ This method always returns cache statistics, useful for determining how much wor
|
||||
Warnings such as _Application transferred too many scanlines_ are a good indicator you've set this value too low.
|
||||
|
||||
```javascript
|
||||
var stats = sharp.cache(); // { current: 98, high: 115, limit: 100 }
|
||||
sharp.cache(200); // { current: 98, high: 115, limit: 200 }
|
||||
sharp.cache(50); // { current: 49, high: 115, limit: 50 }
|
||||
var stats = sharp.cache(); // { current: 98, high: 115, limit: 100, queue: 0 }
|
||||
sharp.cache(200); // { current: 98, high: 115, limit: 200, queue: 0 }
|
||||
sharp.cache(50); // { current: 49, high: 115, limit: 50, queue: 0 }
|
||||
```
|
||||
|
||||
## Testing
|
||||
|
10
src/sharp.cc
10
src/sharp.cc
@ -54,6 +54,9 @@ unsigned char const MARKER_JPEG[] = {0xff, 0xd8};
|
||||
unsigned char const MARKER_PNG[] = {0x89, 0x50};
|
||||
unsigned char const MARKER_WEBP[] = {0x52, 0x49};
|
||||
|
||||
// How many tasks are in the queue?
|
||||
volatile int queue_length = 0;
|
||||
|
||||
static bool ends_with(std::string const &str, std::string const &end) {
|
||||
return str.length() >= end.length() && 0 == str.compare(str.length() - end.length(), end.length(), end);
|
||||
}
|
||||
@ -427,6 +430,8 @@ class ResizeWorker : public NanAsyncWorker {
|
||||
}
|
||||
delete baton;
|
||||
callback->Call(2, argv);
|
||||
// Decrement queue length
|
||||
g_atomic_int_dec_and_test(&queue_length);
|
||||
}
|
||||
|
||||
private:
|
||||
@ -480,6 +485,10 @@ NAN_METHOD(resize) {
|
||||
// Join queue for worker thread
|
||||
NanCallback *callback = new NanCallback(args[2].As<v8::Function>());
|
||||
NanAsyncQueueWorker(new ResizeWorker(callback, baton));
|
||||
|
||||
// Increment queue length
|
||||
g_atomic_int_inc(&queue_length);
|
||||
|
||||
NanReturnUndefined();
|
||||
}
|
||||
|
||||
@ -496,6 +505,7 @@ NAN_METHOD(cache) {
|
||||
cache->Set(NanNew<String>("current"), NanNew<Number>(vips_tracked_get_mem() / 1048576));
|
||||
cache->Set(NanNew<String>("high"), NanNew<Number>(vips_tracked_get_mem_highwater() / 1048576));
|
||||
cache->Set(NanNew<String>("limit"), NanNew<Number>(vips_cache_get_max_mem() / 1048576));
|
||||
cache->Set(NanNew<String>("queue"), NanNew<Number>(queue_length));
|
||||
NanReturnValue(cache);
|
||||
}
|
||||
|
||||
|
@ -8,6 +8,10 @@ var inputJpg = path.join(__dirname, "fixtures/2569067123_aca715a2ee_o.jpg"); //
|
||||
var width = 720;
|
||||
var height = 480;
|
||||
|
||||
var timer = setInterval(function() {
|
||||
console.dir(sharp.cache());
|
||||
}, 100);
|
||||
|
||||
async.mapSeries([1, 1, 2, 4, 8, 16, 32, 64, 128], function(parallelism, next) {
|
||||
var start = new Date().getTime();
|
||||
async.times(parallelism,
|
||||
@ -28,5 +32,6 @@ async.mapSeries([1, 1, 2, 4, 8, 16, 32, 64, 128], function(parallelism, next) {
|
||||
}
|
||||
);
|
||||
}, function() {
|
||||
clearInterval(timer);
|
||||
console.dir(sharp.cache());
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user