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 update replies #1046

Merged
merged 1 commit into from
Apr 3, 2020
Merged

Speed update replies #1046

merged 1 commit into from
Apr 3, 2020

Conversation

rmol
Copy link
Contributor

@rmol rmol commented Apr 2, 2020

Description

A bit more progress toward #1009.

Test Plan

  • Run the dev server with 1000 sources.
  • Check out this branch and run the client.
  • Ensure that syncing completes, that the source list and conversation view populate correctly, and that you can reply to sources. If you grep duration in the client log, update_replies should take around 2.5 seconds on this branch, compared to just over three on the minimize_sync_lookups branch upon which this is based.

Checklist

If these changes modify code paths involving cryptography, the opening of files in VMs or network (via the RPC service) traffic, Qubes testing in the staging environment is required. For fine tuning of the graphical user interface, testing in any environment in Qubes is required. Please check as applicable:

  • I have tested these changes in the appropriate Qubes environment
  • I do not have an appropriate Qubes OS workstation set up (the reviewer will need to test these changes)
  • These changes should not need testing in Qubes

If these changes add or remove files other than client code, the AppArmor profile may need to be updated. Please check as applicable:

  • I have updated the AppArmor profile
  • No update to the AppArmor profile is required for these changes
  • I don't know and would appreciate guidance

@rmol rmol force-pushed the speed-update-replies branch 5 times, most recently from b5c58ee to debd85a Compare April 2, 2020 19:58
def find_or_create_user(uuid: str,
username: str,
session: Session) -> User:
def find_or_create_user(uuid: str, username: str, session: Session, commit: bool = True) -> User:
Copy link
Contributor

Choose a reason for hiding this comment

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

since this is now only used once where commit=False, should we remove the commit boolean parameter, or do you think we'll need it elsewhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The find_or_create_user function is also called in update_and_get_user, which is called in Controller.on_authenticate_success. If no commit is issued there, the database will be locked and prevent syncing. (The functional tests catch this! 🎉)

We could and probably should merge these two functions, and resolve the commit handling, in a separate PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

ah i see, so we could create a new user in the following two cases:

(1) in update_replies if we see that a reply has come in from an admin or journalist who doesn't exist yet in our local db
(2) in on_authenticate_success if the user logging in exists on the server but not yet locally

in case 2 we want to commit since it's a one-off sign in. in case 1, we could be adding many new users for many new replies if it's the first time we are updating our local db against a server that has many users for instance, so we want to delay a commit until the end of a sync in order to improve performance... mmmkay we can refactor later, but this optimization makes sense.

Add boolean "commit" argument to find_or_create_user and
update_draft_replies.

Also make utils.chronometer log at INFO, so you don't have to run at
DEBUG to time things. Debug logging is significantly slower in
intensive loops like storage.update_replies, which can take up to a
couple of seconds longer with debug enabled, given 1000 sources with
two replies each.
@rmol rmol force-pushed the speed-update-replies branch from debd85a to 9b63de9 Compare April 3, 2020 18:18
@rmol rmol self-assigned this Apr 3, 2020
Copy link
Contributor

@sssoleileraaa sssoleileraaa left a comment

Choose a reason for hiding this comment

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

lgtm

def find_or_create_user(uuid: str,
username: str,
session: Session) -> User:
def find_or_create_user(uuid: str, username: str, session: Session, commit: bool = True) -> User:
Copy link
Contributor

Choose a reason for hiding this comment

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

ah i see, so we could create a new user in the following two cases:

(1) in update_replies if we see that a reply has come in from an admin or journalist who doesn't exist yet in our local db
(2) in on_authenticate_success if the user logging in exists on the server but not yet locally

in case 2 we want to commit since it's a one-off sign in. in case 1, we could be adding many new users for many new replies if it's the first time we are updating our local db against a server that has many users for instance, so we want to delay a commit until the end of a sync in order to improve performance... mmmkay we can refactor later, but this optimization makes sense.

@sssoleileraaa sssoleileraaa merged commit 56e0981 into master Apr 3, 2020
@sssoleileraaa sssoleileraaa deleted the speed-update-replies branch April 3, 2020 20:26
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.

2 participants