Skip to content

Commit 86d744c

Browse files
committed
Merge pull request #325 from 10gen/INT-1242-perf-big-minute
INT-1242 handle maxTimeMS timeouts correctly
2 parents f6a6a15 + 1df7ba3 commit 86d744c

File tree

5 files changed

+47
-36
lines changed

5 files changed

+47
-36
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@
8787
"mongodb-js-metrics": "^1.0.0",
8888
"mongodb-language-model": "^0.3.3",
8989
"mongodb-ns": "^1.0.3",
90-
"mongodb-schema": "^4.1.0",
90+
"mongodb-schema": "^4.2.0",
9191
"ms": "^0.7.1",
9292
"node-notifier": "^4.3.1",
9393
"numeral": "^1.5.3",

src/app/models/sampled-schema.js

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ module.exports = Schema.extend({
106106
if (success) {
107107
success(model, resp, options);
108108
}
109-
model.trigger('sync');
110109
};
111110

112111
var start = new Date();
@@ -159,6 +158,7 @@ module.exports = Schema.extend({
159158
'total analysis time': totalTime - timeToFirstDoc,
160159
'average analysis time per doc': (totalTime - timeToFirstDoc) / sampleCount
161160
});
161+
model.trigger('sync');
162162
options.success({});
163163
};
164164

@@ -174,8 +174,6 @@ module.exports = Schema.extend({
174174
return options.success({});
175175
}
176176

177-
debug('count', count);
178-
179177
var status = 0;
180178
var numSamples = Math.min(options.size, count);
181179
var stepSize = Math.ceil(Math.max(1, numSamples / 10));
@@ -193,7 +191,8 @@ module.exports = Schema.extend({
193191

194192
model.samplingStream
195193
.on('error', function(sampleErr) {
196-
this.destroy();
194+
model.samplingStream.destroy();
195+
model.analyzingStream.destroy();
197196
onFail(sampleErr);
198197
})
199198
.pipe(model.analyzingStream)
@@ -214,14 +213,10 @@ module.exports = Schema.extend({
214213
schemaStatusSubview.error = true;
215214
onFail(analysisErr);
216215
})
217-
.on('data', function() {
218-
if (sampleCount >= numSamples) {
216+
.on('end', function() {
217+
if (sampleCount === numSamples) {
219218
return onEnd();
220219
}
221-
// workaround, as 'data' seems to be emitted even when sample stage
222-
// has an error. @ChristianKvalheim investigating.
223-
debug('did not receive data from the driver.');
224-
onFail(new Error('did not receive data from driver.'));
225220
});
226221
});
227222
},
@@ -230,17 +225,13 @@ module.exports = Schema.extend({
230225
this.fetch();
231226
},
232227
stopAnalyzing: function() {
233-
if (!this.is_fetching) {
234-
return;
228+
if (this.is_fetching) {
229+
this.is_fetching = false;
230+
this.samplingStream.destroy();
231+
this.analyzingStream.destroy();
235232
}
236-
this.is_fetching = false;
237-
// @todo thomasr, uncomment this line once we figured out why
238-
// app.client.sample() is not emitting any events anymore.
239-
// for now, we can use app.client.find instead.
240-
241-
// this.samplingStream.destroy();
242-
this.analyzingStream.destroy();
243233
app.statusbar.hide(true);
234+
this.trigger('sync');
244235
},
245236
serialize: function() {
246237
var res = this.getAttributes({

src/app/statusbar/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,8 @@ var StatusbarView = View.extend({
118118
trickle: function(bool) {
119119
if (bool) {
120120
this.trickleTimer = setInterval(function() {
121-
this.width = Math.min(98, this.width + _.random(1, 3));
122-
}.bind(this), 400);
121+
this.width = Math.min(98, this.width + 1);
122+
}.bind(this), 600);
123123
} else {
124124
clearInterval(this.trickleTimer);
125125
}

src/app/statusbar/schema-subview.jade

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ div#schema-status-subview
1010
| Analyzing Documents
1111

1212
div.buttons(data-hook='buttons')
13-
div#buttons-sampling
13+
div#buttons-error
1414
div.alert.alert-warning(role='alert', data-hook='sampling-info')
1515
| Sampling took longer than 
1616
span(data-hook='maxtimems') 10 seconds
@@ -20,9 +20,9 @@ div#schema-status-subview
2020
i.fa.fa-fw.fa-info-circle
2121
br
2222
div.btn.btn-info(data-hook='increase-maxtimems-button') Try for 1 minute
23-
div.btn.btn-info(data-hook='create-new-query-button') Create new query
23+
div.btn.btn-info(data-hook='next-action-button')
2424

25-
div#buttons-analyzing
25+
div#buttons-waiting
2626
div.alert.alert-info(role='alert', data-hook='analyzing-info') Document analysis is taking longer than expected.  
2727
a.help(data-hook='schema-long-running-queries')
2828
| Learn More

src/app/statusbar/schema-subview.js

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ var subviewTemplate = jade.compileFile(path.resolve(__dirname, 'schema-subview.j
99

1010

1111
var SHOW_STEPS_MS = 3000;
12-
var SHOW_ANALYZING_BUTTONS_MS = 10000;
12+
var SHOW_ANALYZING_BUTTONS_MS = app.queryOptions.maxTimeMS + 1000;
1313

1414
module.exports = View.extend({
1515
template: subviewTemplate,
@@ -41,6 +41,13 @@ module.exports = View.extend({
4141
}
4242
},
4343
derived: {
44+
nextActionLabel: {
45+
deps: ['activeStep'],
46+
fn: function() {
47+
return this.activeStep === 'sampling' ?
48+
'Create new Query' : 'Show partial results';
49+
}
50+
},
4451
samplingState: {
4552
deps: ['activeStep', 'error'],
4653
fn: function() {
@@ -67,6 +74,10 @@ module.exports = View.extend({
6774
}
6875
},
6976
bindings: {
77+
nextActionLabel: {
78+
hook: 'next-action-button',
79+
type: 'text'
80+
},
7081
stepsVisible: {
7182
type: 'toggle',
7283
hook: 'steps',
@@ -77,15 +88,20 @@ module.exports = View.extend({
7788
hook: 'buttons',
7889
mode: 'visibility'
7990
},
91+
error: {
92+
type: 'toggle',
93+
no: '#buttons-waiting',
94+
yes: '#buttons-error'
95+
},
8096
activeStep: [
81-
{
82-
type: 'switch',
83-
hook: 'buttons',
84-
cases: {
85-
sampling: '#buttons-sampling',
86-
analyzing: '#buttons-analyzing'
87-
}
88-
},
97+
// {
98+
// type: 'switch',
99+
// hook: 'buttons',
100+
// cases: {
101+
// sampling: '#buttons-sampling',
102+
// analyzing: '#buttons-analyzing'
103+
// }
104+
// },
89105
{
90106
type: 'switchClass',
91107
name: 'is-active',
@@ -123,7 +139,8 @@ module.exports = View.extend({
123139
},
124140
events: {
125141
'click [data-hook=stop-analyzing-button]': 'stopAnalyzingClicked',
126-
'click [data-hook=create-new-query-button]': 'createNewQueryClicked',
142+
'click [data-hook=partial-results-button]': 'stopAnalyzingClicked',
143+
'click [data-hook=next-action-button]': 'nextActionClicked',
127144
'click [data-hook=increase-maxtimems-button]': 'resampleWithLongerTimoutClicked'
128145
},
129146
render: function() {
@@ -150,7 +167,10 @@ module.exports = View.extend({
150167
resampleWithLongerTimoutClicked: function() {
151168
this.schema.reSampleWithLongerTimeout();
152169
},
153-
createNewQueryClicked: function() {
170+
nextActionClicked: function() {
171+
if (this.schema && this.schema.count > 0) {
172+
return this.schema.stopAnalyzing();
173+
}
154174
app.statusbar.hide();
155175
},
156176
remove: function() {

0 commit comments

Comments
 (0)