Skip to content

Instantly share code, notes, and snippets.

@jakub300
Created May 25, 2012 14:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jakub300/2788573 to your computer and use it in GitHub Desktop.
Save jakub300/2788573 to your computer and use it in GitHub Desktop.
gm vs canvas przy generowaniu miniaturek

Na wstępie:

  • gm spawnuje procesy więc wykorzystuje wszystkie rdzenie (w teście 4)
  • canvas działa jako biblioteka node więc tylko w procesie node (tylko 1 rdzeń)
  • lepiej dostarczać node-canvas odczytany plik (buffer) niż nazwę pliku
  • zużycie RAMu prze node-canvas nie przekraczało 300 MB (nawet przy -c 500)

node-canvas miażdży gm :)

https://github.com/LearnBoost/node-canvas

var http = require("http"),
Canvas = require('canvas'),
fs = require('fs')
http.createServer(function (req, res) {
res.writeHead(200, {"Content-Type": "image/jpeg"});
var canvas = new Canvas(100,100),
ctx = canvas.getContext('2d');
fs.readFile('image.jpg', function(err, file){
if(!err) {
var img = new Canvas.Image;
img.src = file;
ctx.drawImage(img, 0, 0, 100, 100);
canvas.createJPEGStream().pipe(res);
} else {
res.end();
}
});
}).listen(9293, "0.0.0.0");
Concurrency Level: 100
Time taken for tests: 11.144 seconds
Complete requests: 1000
Failed requests: 0
Write errors: 0
Total transferred: 3051000 bytes
HTML transferred: 2987000 bytes
Requests per second: 89.74 [#/sec] (mean)
Time per request: 1114.378 [ms] (mean)
Time per request: 11.144 [ms] (mean, across all concurrent requests)
Transfer rate: 267.37 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.5 0 2
Processing: 90 1065 173.1 1106 1270
Waiting: 87 1063 173.1 1104 1267
Total: 92 1065 172.7 1106 1270
user 0m10.964s
sys 0m0.335s
Concurrency Level: 100
Time taken for tests: 16.390 seconds
Complete requests: 1000
Failed requests: 0
Write errors: 0
Total transferred: 2554000 bytes
HTML transferred: 2490000 bytes
Requests per second: 61.01 [#/sec] (mean)
Time per request: 1638.968 [ms] (mean)
Time per request: 16.390 [ms] (mean, across all concurrent requests)
Transfer rate: 152.18 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 2 8.7 0 52
Processing: 176 1622 402.9 1583 3171
Waiting: 176 1421 430.7 1505 3087
Total: 178 1624 403.8 1583 3171
user 0m59.760s
sys 0m2.968s
Gratis :)
Concurrency Level: 500
Time taken for tests: 110.762 seconds
Complete requests: 10000
Failed requests: 0
Write errors: 0
Total transferred: 30510000 bytes
HTML transferred: 29870000 bytes
Requests per second: 90.28 [#/sec] (mean)
Time per request: 5538.097 [ms] (mean)
Time per request: 11.076 [ms] (mean, across all concurrent requests)
Transfer rate: 269.00 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 1 1.7 0 12
Processing: 145 5405 659.8 5531 5716
Waiting: 143 5402 659.8 5529 5716
Total: 156 5405 658.2 5531 5721
user 1m49.712s
sys 0m2.045s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment