Repository navigation
Index Variable.measure_id to keep analysis creation fast (179D-310 backport of #894) - #895
Merged
Merged
Conversation
Measure.create_from_os_json calls measure.variables.include? for each measure argument. Without an index on measure_id, each call scans the whole variables collection, so creating an analysis gets slower as analyses build up. With 601k variables, POST /projects/:id/analyses.json took about 90 s; with the index it takes about 5 s. (cherry picked from commit eb1e985)
Contributor
Author
|
@anchapin this look good to also get into the '179D-310' branch? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Cherry-pick of #894 (by @anchapin) onto the
179D-310rollback branch, which serves the3.10.0-179D-testimages where the slowdown was observed. Same two-file change; only the target branch differs. Credit and the deploy note belong to the original PR.What broke
POST /projects/:id/analyses.jsongets slower with every analysis on the server. In a 179D run of 3648 batches it went from ~14 s to ~90 s per batch by batch 1560.Measure.create_from_os_jsoncallsmeasure.variables.include?(new_var)once per measure argument. On ahas_manyproxy that resolves to Ruby'sEnumerable#include?, which loads the whole relation with a{measure_id: X}filter (no_id, no limit).variableshad no index onmeasure_id, so every call was a COLLSCAN over the full collection (441 ms at 601k variables on the live server).What changed
server/app/models/variable.rb:belongs_to :measure, optional: true, index: true(Mongoid declares{measure_id: 1}).server/spec/models/variable_spec.rb(new): asserts themeasure_idindex is declared.Existing databases pick the index up from
rake db:mongoid:create_indexes, whichdocker/server/start-server.shruns at every web boot. If the index was already created by hand under a name other than Mongoid's defaultmeasure_id_1, drop the hand-made one first orcreate_indexeswill log an IndexOptionsConflict on each boot.How verified
explainwent from COLLSCAN 441 ms to IXSCAN 2 ms after adding the index by hand; request time ~90 s to ~5 s.measure.variables.include?issuesfind variables {measure_id: ...}with no_id;explainon that shape is COLLSCAN without the index.linux-test/macos-testunit-test step (rspec fromserver/with tag filters only, no file list; see Index Variable.measure_id to keep analysis creation fast #894 discussion).