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

Speed up search by avoiding the creation of intermediary objects #162

Merged
merged 19 commits into from
Feb 6, 2024

Conversation

Flix6x
Copy link
Collaborator

@Flix6x Flix6x commented Dec 30, 2023

I'm trying to skip having the ORM create a potentially large number of TimedBelief objects.

@Flix6x Flix6x added the Database support Dealing with databases label Dec 30, 2023
@Flix6x Flix6x added this to the 2.0.0 milestone Dec 30, 2023
@Flix6x Flix6x self-assigned this Dec 30, 2023
Signed-off-by: F.N. Claessen <[email protected]>
… used whatever was passed in the DataFrame, which was belief_horizon, so we need to convert

Signed-off-by: F.N. Claessen <[email protected]>
Signed-off-by: F.N. Claessen <[email protected]>
Signed-off-by: F.N. Claessen <[email protected]>
Base automatically changed from issue-159-Support_SQLAlchemy_2_0 to main January 9, 2024 11:33
Signed-off-by: F.N. Claessen <[email protected]>
Signed-off-by: F.N. Claessen <[email protected]>
@Flix6x Flix6x marked this pull request as ready for review January 9, 2024 11:50
@victorgarcia98
Copy link
Contributor

victorgarcia98 commented Jan 17, 2024

Awesome!!

I created a small benchmark where I compare the speed of fetching the beliefs of 200 sensors that I have in my DB. The average improvement is of $4.53\pm 1.76$.

Two observations:

  • It appears to cause a greater improvement when the base query takes more time (>=0.5)
  • The new approach appears to be worse in 2 queries (not significant), but it happens for two queries that take very short on the baseline.
from flexmeasures.app import create
from flexmeasures.data.models.time_series import TimedBelief
from flexmeasures.data.models.time_series import Sensor

from flexmeasures.data.models.time_series import TimedBelief

app = create()

import time

FILENAME ="old.txt"

with app.app_context():
    sensors = Sensor.query.all()[:200]
    
    with open(FILENAME, "w+") as f:
        try:
            for sensor in sensors:
                t = time.process_time()
                TimedBelief.search_session(app.db.session, sensor)
                t1 = time.process_time() - t
                print(t1)
                f.write(str(t1) + "\n")
                f.flush()
        except KeyboardInterrupt:
            pass

benchmark.xlsx

@Flix6x
Copy link
Collaborator Author

Flix6x commented Jan 18, 2024

@Ahmad-Wahid in our private meeting you mentioned a flexmeasures issue that was related to this PR, and that you posted relevant info on GitHub. Can you point me to it? Maybe it was this one, but it doesn't seem related to me.

@Flix6x Flix6x merged commit a93c61f into main Feb 6, 2024
5 checks passed
@Flix6x Flix6x deleted the feature/search-avoids-creating-TimedBelief-objects branch February 6, 2024 12:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Database support Dealing with databases
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants