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

Optimize work horse forking #4314

Merged
merged 1 commit into from
Oct 30, 2019
Merged

Optimize work horse forking #4314

merged 1 commit into from
Oct 30, 2019

Conversation

rauchy
Copy link
Contributor

@rauchy rauchy commented Oct 29, 2019

What type of PR is this? (check all applicable)

  • Bug Fix

Description

We've noticed that worker horses are consuming a lot of CPU. After some profiling, I realized that configure_mapping is called every time a work horse is forked (i.e. for every job). This PR calls configure_mapping once in the parent worker process, which is then available to the forked horses. We've seen significant performance improvement with this.

Related Tickets & Documents

Mobile & Desktop Screenshots/Recordings (if there are UI changes)

@rauchy rauchy requested a review from arikfr October 29, 2019 13:44
# Configure any SQLAlchemy mappers loaded until now so that the mapping configuration
# will already be available to the forked work horses and they won't need
# to spend valuable time re-doing that on every fork.
configure_mappers()
Copy link
Member

Choose a reason for hiding this comment

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

I've noticed that in redash.models.base we use the flask_sqlalchemy.SQLAlchemy's instance configure_mappers. I wonder what's the difference?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

WTF. Why did they do that? 😕

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So you can access everything through flask_sqlalchemy.SQLAlchemy, I guess.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, the idea being that you define a db object like db = SQLAlchemy() when using flask-sqlalchemy and then can call anything inside the sqlalchemy.orm module. In other words, it's to simplify the Flask-like API of flask-sqlalchemy.

@rauchy rauchy merged commit 36638be into master Oct 30, 2019
@rauchy rauchy deleted the optimize-work-horse-forking branch October 30, 2019 07:53
@rauchy rauchy mentioned this pull request Nov 19, 2019
1 task
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.

3 participants