juju models is O(N^2) wrt modelUsers collection
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
Canonical Juju |
Fix Released
|
High
|
John A Meinel |
Bug Description
Model.Users does:
coll, closer := m.st.db(
defer closer()
var userDocs []userAccessDoc
err := coll.Find(
if err != nil {
return nil, errors.Trace(err)
}
I did a quick peek, and it seems that our collectionWrapper only munges queries if they include _id, and so a 'nil' query will read *all* docs from the collection.
Which means that if you have 200 models, that means at least 200 modelUser entries (assuming each model has at least 1 owner).
Which then means that doing:
juju list-models
will go to each model, and load all 200 modelUser docs, to filter back down to only the users relevant for this model.
Now, it looks like we might auto-munge in a "model-uuid: X" query. However, there is no model-uuid index defined on the collection:
> db.modelusers.
[
{
"v" : 1,
},
}
]
I'm looking to rewrite this to do more batching, and less potato-ing anyway, but this is definitely Quadratic in the number of models a controller has.
tags: | added: list-models performance |
Changed in juju: | |
status: | Triaged → In Progress |
milestone: | none → 2.3-rc2 |
Changed in juju: | |
status: | Fix Committed → Fix Released |
The easy fix might be to just put an index on model-uuid on that collection.