summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThiago Marcos P. Santos <thiago@mapbox.com>2017-04-10 16:41:38 +0300
committerThiago Marcos P. Santos <tmpsantos@gmail.com>2017-04-20 18:46:35 +0300
commitd767545f72e5a3e05d37e1d71b2c1f9a86522ca9 (patch)
tree0c4f3f2e3314e8370761213ba2e4a553c1581aad
parent761cd136a897d58c74855869ac9324de864234e3 (diff)
downloadqtlocation-mapboxgl-d767545f72e5a3e05d37e1d71b2c1f9a86522ca9.tar.gz
[node] Benchmark/stress test
Tries to simulate the workload from api-gl.
-rw-r--r--platform/node/test/benchmark.js104
1 files changed, 104 insertions, 0 deletions
diff --git a/platform/node/test/benchmark.js b/platform/node/test/benchmark.js
new file mode 100644
index 0000000000..38c416ed34
--- /dev/null
+++ b/platform/node/test/benchmark.js
@@ -0,0 +1,104 @@
+'use strict';
+
+var mockfs = require('./mockfs');
+var mbgl = require('../index');
+var test = require('tape');
+
+var firstRequest = "mapbox://sprites/mapbox/streets-v9@2x.json";
+
+var params = {
+ mapPoolSize: 10,
+ numRenderings: 1000,
+ failurePercentage: 0,
+ timeoutPercentage: 0,
+ renderingTimeout: 5000,
+ ratio: 2
+};
+
+test('Benchmark', function(t) {
+ console.time('Time');
+
+ var renderCount = 0;
+ var failureCount = 0;
+ var timeoutCount = 0;
+
+ var options = {
+ request: function(req, callback) {
+ setTimeout(function() {
+ var num = Math.floor(Math.random() * 100);
+
+ if (req.url == firstRequest && num < params.failurePercentage) {
+ callback(new Error('Failure'));
+ } else if (req.url == firstRequest && num > 99 - params.timeoutPercentage) {
+ setTimeout(function() { callback(new Error('Timeout')); }, params.renderingTimeout * 5);
+ } else {
+ var data = mockfs.dataForRequest(req);
+ callback(null, { data: mockfs.dataForRequest(req) });
+ }
+ }, 0);
+ },
+ ratio: params.ratio,
+ };
+
+ var mapPool = []
+
+ for (var i = 0; i < params.mapPoolSize; ++i) {
+ var map = new mbgl.Map(options);
+ mapPool.push(map);
+ }
+
+ var interval = setInterval(function () {
+ if (mapPool.length == 0 || renderCount == params.numRenderings) {
+ return;
+ }
+
+ var map = mapPool.shift();
+
+ map.load('{ "version": 8, "sources": {}, "layers": [] }');
+ map.load(mockfs.style_vector);
+
+ renderCount += 1;
+
+ if (renderCount % (params.numRenderings / 100) == 0) {
+ // Print some progress, so slow build bots don't timeout.
+ t.comment('Rendering (' + renderCount.toString() +
+ '/' + params.numRenderings.toString() + ')');
+ }
+
+ if (renderCount == params.numRenderings) {
+ clearInterval(interval);
+ t.end();
+ console.timeEnd('Time');
+ console.log('Failures: ' + failureCount);
+ console.log('Timeouts: ' + timeoutCount);
+
+ return;
+ }
+
+ var mapTimeout = setTimeout(function() {
+ map.release();
+ mapPool.push(new mbgl.Map(options));
+ timeoutCount += 1;
+ }, params.renderingTimeout);
+
+ map.render({ zoom: 16 }, function(err, pixels) {
+ clearTimeout(mapTimeout);
+
+ if (err) {
+ if (err.message == 'Failure') {
+ failureCount += 1;
+ }
+
+ if (err.message == 'Timeout') {
+ t.fail('should never happen');
+ }
+
+ map.release();
+ mapPool.push(new mbgl.Map(options));
+ return;
+ }
+
+ mapPool.push(map);
+ });
+ }, 1);
+});