Skip to content

Commit 066a4e1

Browse files
authored
Server graph only (#114)
* 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.
1 parent 647239b commit 066a4e1

File tree

2 files changed

+103
-10
lines changed

2 files changed

+103
-10
lines changed

Diff for: bin/serve.js

100644100755
+21-10
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ const OPTS_META = [].concat([{
2727
type: 'string',
2828
alias: ['windowMaxNumber', 'maxNumberOfWindows'],
2929
description: 'Sets maximum number of browser windows the server can keep open at a given time.'
30+
}, {
31+
name: 'graph-only',
32+
type: 'boolean',
33+
alias: ['graphOnly'],
34+
description: 'Launches only the graph component (not thumbnails, dash, etc.) to save memory and reduce the number of processes.'
3035
}, {
3136
name: 'quiet',
3237
type: 'boolean',
@@ -72,15 +77,14 @@ function main (args) {
7277
console.log(`Spinning up server with pid: ${process.pid}`)
7378
}
7479

75-
app = orca.serve({
76-
port: opts.port,
77-
maxNumberOfWindows: opts.maxNumberOfWindows,
78-
debug: opts.debug,
79-
component: [{
80-
name: 'plotly-graph',
81-
route: '/',
82-
options: plotlyJsOpts
83-
}, {
80+
let component = [{
81+
name: 'plotly-graph',
82+
route: '/',
83+
options: plotlyJsOpts
84+
}]
85+
86+
if (!opts.graphOnly) {
87+
component.push({
8488
name: 'plotly-dashboard',
8589
route: '/dashboard'
8690
}, {
@@ -98,7 +102,14 @@ function main (args) {
98102
}, {
99103
name: 'plotly-dash-preview',
100104
route: '/dash-preview'
101-
}]
105+
})
106+
}
107+
108+
app = orca.serve({
109+
port: opts.port,
110+
maxNumberOfWindows: opts.maxNumberOfWindows,
111+
debug: opts.debug,
112+
component: component
102113
})
103114

104115
app.on('after-connect', (info) => {

Diff for: test/integration/orca_serve_graph-only_test.js

+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
const tap = require('tap')
2+
const Application = require('spectron').Application
3+
const request = require('request')
4+
5+
const { paths } = require('../common')
6+
const PORT = 9109
7+
const SERVER_URL = `http://localhost:${PORT}`
8+
9+
const app = new Application({
10+
path: paths.bin,
11+
args: ['serve', '--port', PORT, '--graph-only']
12+
})
13+
14+
tap.tearDown(() => {
15+
if (app && app.isRunning()) {
16+
app.stop()
17+
}
18+
})
19+
20+
tap.test('should launch', t => {
21+
app.start().then(() => {
22+
app.client.getWindowCount().then(cnt => {
23+
// Only one window since only graph component should be running
24+
t.equal(cnt, 1)
25+
t.end()
26+
})
27+
})
28+
})
29+
30+
tap.test('should reply pong to ping POST', t => {
31+
request.post(SERVER_URL + '/ping', (err, res, body) => {
32+
if (err) t.fail(err)
33+
34+
t.equal(res.statusCode, 200, 'code')
35+
t.equal(body, 'pong', 'body')
36+
t.end()
37+
})
38+
})
39+
40+
tap.test('should work for *plotly-graph* component', t => {
41+
request({
42+
method: 'POST',
43+
url: SERVER_URL + '/',
44+
body: JSON.stringify({
45+
figure: {
46+
layout: {
47+
data: [{y: [1, 2, 1]}]
48+
}
49+
}
50+
})
51+
}, (err, res, body) => {
52+
if (err) t.fail(err)
53+
54+
t.equal(res.statusCode, 200, 'code')
55+
t.type(body, 'string')
56+
t.end()
57+
})
58+
})
59+
60+
tap.test('should teardown', t => {
61+
app.stop()
62+
.catch(t.fail)
63+
.then(t.end)
64+
})
65+
66+
tap.test('should not work for *plotly-thumbnail* component', t => {
67+
request({
68+
method: 'POST',
69+
url: SERVER_URL + '/thumbnail',
70+
body: JSON.stringify({
71+
figure: {
72+
layout: {
73+
data: [{y: [1, 2, 1]}]
74+
}
75+
}
76+
})
77+
}, (err, res) => {
78+
t.equal(err.code, 'ECONNREFUSED')
79+
t.equal(res, undefined, 'should be undefined')
80+
t.end()
81+
})
82+
})

0 commit comments

Comments
 (0)