Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve mongo-backend-loading #336

Merged
merged 4 commits into from
Oct 22, 2020

Conversation

JoranAngevaare
Copy link
Member

What is the problem / what does the code in this PR do
Slightly tweak w.r.t. #335 (and #315). Only query the database for chunks once.

Can you briefly describe how it works?
Use find to find all chunks, save it in ram and load it from there instead of doing up to 600 queries.

Performance
Using

%%timeit
om = st.get_array('009524', 'online_peak_monitor', allow_incomplete=True) # 161 chunks

Before
23 s ± 175 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)

After
1.91 s ± 70.6 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)

Copy link
Contributor

@darrylmasson darrylmasson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The DataNotAvailable exception needs to be moved if we want it to be throwable.

chunks_registry = self.db[self.col_name].find(
{**query, **{"chunk_i": {'$exists':True}}},
{"chunk_i": 1, "data": 1})
if chunks_registry is not None:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

find returns a Cursor, which never evaluates to None, even if the cursor is empty. The pymongo documentation doesn't really give us much to go on for this.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, changed it

f'Projection failed, got doc with no "chunk_i":\n{doc}')
# Update our registry with this chunks info. Use chunk_i as
# chunk_key
self.chunks_registry[chunk_key] = doc.copy()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Integers as dictionary keys can cause issues later if you try to json-encode it. Probably not an issue here, but something to remember.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed it just to be on the safe side

@JoranAngevaare JoranAngevaare merged commit c27fcbc into AxFoundation:master Oct 22, 2020
@JoranAngevaare JoranAngevaare deleted the online_monitor branch October 22, 2020 14:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants