shaysquared
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # Local DM creation and room joins on Matrix.org DM creation seems to take consistently ~1-2+ seconds using Element web client to send the request with both users on Matrix.org Looking at the Jaeger traces of requests to `/matrix/client/r0/createRoom` the processing time for just that endpoint appears to be about 1-2+ seconds. Here are some example times for this request: 1.17s, 2.9s, 1.19s, 1.08s (note that the "shorter" durations were tracked later in my work day, meaning after european business hours) Digging deeper into the Jaeger traces, within the `createRoom` requests outgoing replication requests to the event persister, including persisting the event-appear to be the culprit for the slowness and are taking up significant chunks of the overall time (example: 575.66ms out of 2.9s), and happen several times within the overall request The second longest call, which tends to be much shorter but is noticible, is `db._get_state_groups_from_groups` I did notice that request processing times trend higher when there is higher traffic on Matrix.org (i.e. european business hours), which makes sense. One suggestion that has been made (by Sean) for ameliorating this is to batch up these calls to the event persister rather than making several calls throughout the processing of the request. ---- # Local room joins Local room joins apprear to be taking about 1-20s (20s being the longest join I saw). I used Jaeger and a test account that was always traced to compile these observations. The top offenders for slowness in local room joins are: - `bulk_get_push_rules` and `bulk_get_push_rules_enabled` - `_get_joined_profiles_from_event_ids` - `_get_state_groups_from_groups` - runner-up: `get_subset_users_in_room_with_profiles` Suggestions for speeding up these calls: - calculating push rules: I am unsure if there is any way around this-looking at Grafana the cache hit rate for these calls don't seem terrible (i.e. they're not zero and often range up to 75-100%) so I am not sure that there's an immediate win there. I wish there was some way to filter calulating the push actions since I suspect not many people would have rules to be notified of room joins and thus there's a lot of wasted calculation, but I can't see any immediate way to do that. - `_get_joined_profiles_from_event_ids`: This one is interesting. This function is called deep in a call chain originating with `cache_joined_hosts_for_event`, which is called when the event is persisted. It appears to be called as part of figuring out what servers are in the room. The cache hit ratio on this function is often zero and it is high on the list of top ten cache misses so I am wonering if there is some cache tuning that might be done to make these cache hit rate get better and thus the overall call go faster. Another mystery about this function call is that it is called many times in the course of one trace but originates from persisting the original join event, which should only happen once? I haven't dug into this, just noting it here. - `_get_state_groups_from_groups`: Unsure how to speed this one up, although I did see a comment about missing indexes (something about de-duping state??) so getting to the bottom of that is an obvious first place to start. I am also seeing weird mystery pauses, I have some screenshots here but these are not all of them by far. Often on the joins that took the longest you would see at least one of these, with the pauses often extending up to 6 or more seconds (the longest unexplained pause I saw was 13s). Weirdly a larger-than-random portion seem to occur on `get_local_users_in_room` but I have seen them in a large number of other calls as well. I checked the reactor tick times on Grafana for the `event_creator_users` workers and 99.9% were finishing in under ~400ms. Out of curiosity I turned it up to see what the time was for 100% of ticks and it was 5s, which I thought was notable but I am not sure how important it is. I do think something is going on here that it would be beneficial to get to the bottom of, I think adding more tracing would be the next logical step. ![](https://i.imgur.com/HodezDH.png) ![](https://i.imgur.com/MHKBRPH.png) ![](https://i.imgur.com/eayUGmJ.png) ![](https://i.imgur.com/2EpRo1Y.png) - get_auth_chain_difference_chain looks like in this case we are recusively fetching event redactions for the events fetched for state res. These events are only being used in state res- seems like fetching the reaction events for them is unnecessary and it takes a very long time (seconds) ## DMR driveby ![](https://i.imgur.com/fYF3jX7.png) This is Shay's test account trying to join synapse-dev. It seems to spend ~430ms awaiting full state. But Why: we haven't turned on faster joins; all rooms are full state as far as matrix.org is concerned. I wonder if this call [here](https://github.com/matrix-org/synapse/blob/42b11d5565ed026c7d71f433c69e7b7007f45918/synapse/state/__init__.py#L209) should check if the room is considered partial-stated using [this cached function](https://github.com/matrix-org/synapse/blob/9d2823ab70e69a90f4a54256bd32cd85eab130d9/synapse/storage/databases/main/room.py#L1204) before asking if each individual event is partial stated. I was surprised that the is_partial_state_room cache is so small and evicted from rapidly. https://grafana.matrix.org/d/000000012/synapse?orgId=1&var-datasource=default&var-bucket_size=$__auto_interval_bucket_size&var-instance=matrix.org&var-job=synapse_event_creator_users&var-index=4&from=now-2d&to=now&viewPanel=8 The is_partial_state_event cache seems like it would benefit from being bigger: https://grafana.matrix.org/d/000000012/synapse?orgId=1&var-datasource=default&var-bucket_size=$__auto_interval_bucket_size&var-instance=matrix.org&var-job=synapse_event_creator_users&var-index=4&from=now-7d&to=now&viewPanel=8 ---- get_forgotten_rooms_for_user seemed like a slow query from the trace (100ms). Wait, why do we need this to join a single room? Looks like it's from https://github.com/matrix-org/synapse/blob/84ddcd7bbfe4100101741a408a91f283a8f742c7/synapse/handlers/room_member.py#L873 That calls https://github.com/matrix-org/synapse/blob/42b11d5565ed026c7d71f433c69e7b7007f45918/synapse/storage/databases/main/roommember.py#L444-L460 which seems like overkill. It ends up looking for all possible rooms when we only want to know about one. Why!?! Why can't we look up the user's membership in the current state of that room to see if they're invited? (Out-of-band memberships?) ----

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully