From d98600d1368608c250ad3aea7094aff3273753ee Mon Sep 17 00:00:00 2001 From: Jon Mease Date: Thu, 9 Aug 2018 08:25:23 -0400 Subject: [PATCH 1/2] Added `--graph-only` option for the `orca serve` entry point When this option is present, only the plotly-graph component is run (not thumbnail, dash, etc.). When graph conversion is the only service needed, this option reduces the number of electron processes, the memory usage, and startup time. --- bin/serve.js | 31 ++++--- .../integration/orca_serve_graph-only_test.js | 82 +++++++++++++++++++ 2 files changed, 103 insertions(+), 10 deletions(-) mode change 100644 => 100755 bin/serve.js create mode 100644 test/integration/orca_serve_graph-only_test.js diff --git a/bin/serve.js b/bin/serve.js old mode 100644 new mode 100755 index b926baaf..81d7ed58 --- a/bin/serve.js +++ b/bin/serve.js @@ -27,6 +27,11 @@ const OPTS_META = [].concat([{ type: 'string', alias: ['windowMaxNumber', 'maxNumberOfWindows'], description: 'Sets maximum number of browser windows the server can keep open at a given time.' +}, { + name: 'graph-only', + type: 'boolean', + alias: ['graphOnly'], + description: 'Launches only the graph component (not thumbnails, dash, etc.) to save memory and reduce the number of processes' }, { name: 'quiet', type: 'boolean', @@ -72,15 +77,14 @@ function main (args) { console.log(`Spinning up server with pid: ${process.pid}`) } - app = orca.serve({ - port: opts.port, - maxNumberOfWindows: opts.maxNumberOfWindows, - debug: opts.debug, - component: [{ - name: 'plotly-graph', - route: '/', - options: plotlyJsOpts - }, { + let component = [{ + name: 'plotly-graph', + route: '/', + options: plotlyJsOpts + }] + + if (!opts.graphOnly) { + component.push({ name: 'plotly-dashboard', route: '/dashboard' }, { @@ -98,7 +102,14 @@ function main (args) { }, { name: 'plotly-dash-preview', route: '/dash-preview' - }] + }) + } + + app = orca.serve({ + port: opts.port, + maxNumberOfWindows: opts.maxNumberOfWindows, + debug: opts.debug, + component: component }) app.on('after-connect', (info) => { diff --git a/test/integration/orca_serve_graph-only_test.js b/test/integration/orca_serve_graph-only_test.js new file mode 100644 index 00000000..f2330a18 --- /dev/null +++ b/test/integration/orca_serve_graph-only_test.js @@ -0,0 +1,82 @@ +const tap = require('tap') +const Application = require('spectron').Application +const request = require('request') + +const { paths } = require('../common') +const PORT = 9109 +const SERVER_URL = `http://localhost:${PORT}` + +const app = new Application({ + path: paths.bin, + args: ['serve', '--port', PORT, '--graph-only'] +}) + +tap.tearDown(() => { + if (app && app.isRunning()) { + app.stop() + } +}) + +tap.test('should launch', t => { + app.start().then(() => { + app.client.getWindowCount().then(cnt => { + // Only one window since only graph component should be running + t.equal(cnt, 1) + t.end() + }) + }) +}) + +tap.test('should reply pong to ping POST', t => { + request.post(SERVER_URL + '/ping', (err, res, body) => { + if (err) t.fail(err) + + t.equal(res.statusCode, 200, 'code') + t.equal(body, 'pong', 'body') + t.end() + }) +}) + +tap.test('should work for *plotly-graph* component', t => { + request({ + method: 'POST', + url: SERVER_URL + '/', + body: JSON.stringify({ + figure: { + layout: { + data: [{y: [1, 2, 1]}] + } + } + }) + }, (err, res, body) => { + if (err) t.fail(err) + + t.equal(res.statusCode, 200, 'code') + t.type(body, 'string') + t.end() + }) +}) + +tap.test('should teardown', t => { + app.stop() + .catch(t.fail) + .then(t.end) +}) + +tap.test('should not work for *plotly-thumbnail* component', t => { + request({ + method: 'POST', + url: SERVER_URL + '/thumbnail', + body: JSON.stringify({ + figure: { + layout: { + data: [{y: [1, 2, 1]}] + } + } + }) + }, (err, res) => { + t.equal(err.code, 'ECONNREFUSED') + t.equal(res, undefined, 'should be undefined') + t.end() + }) +}) From 95812df46f736e34a9fe9fb16a07efedb37dcfdd Mon Sep 17 00:00:00 2001 From: Jon Mease Date: Thu, 9 Aug 2018 10:44:57 -0400 Subject: [PATCH 2/2] Add . --- bin/serve.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/serve.js b/bin/serve.js index 81d7ed58..7ff44123 100755 --- a/bin/serve.js +++ b/bin/serve.js @@ -31,7 +31,7 @@ const OPTS_META = [].concat([{ name: 'graph-only', type: 'boolean', alias: ['graphOnly'], - description: 'Launches only the graph component (not thumbnails, dash, etc.) to save memory and reduce the number of processes' + description: 'Launches only the graph component (not thumbnails, dash, etc.) to save memory and reduce the number of processes.' }, { name: 'quiet', type: 'boolean',