Skip to content

Commit

Permalink
Server graph only (#114)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
jonmmease authored Aug 9, 2018
1 parent 647239b commit 066a4e1
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 10 deletions.
31 changes: 21 additions & 10 deletions bin/serve.js
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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'
}, {
Expand All @@ -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) => {
Expand Down
82 changes: 82 additions & 0 deletions test/integration/orca_serve_graph-only_test.js
Original file line number Diff line number Diff line change
@@ -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()
})
})

0 comments on commit 066a4e1

Please sign in to comment.