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

Performance issue on rendering of home feed #681

Closed
adrienjoly opened this issue Aug 26, 2023 · 5 comments
Closed

Performance issue on rendering of home feed #681

adrienjoly opened this issue Aug 26, 2023 · 5 comments
Assignees
Labels

Comments

@adrienjoly
Copy link
Member

Problem

A lot of time seems to be wasted between querying the logged user's subscriptions (cf orange blocks on the left) and posts (cf orange blocks on the right)

image

This gets worse on profiles that have a lot of subscriptions.

This performance problem is probably the root cause of recent performance and availability issues, cf:

@adrienjoly
Copy link
Member Author

adrienjoly commented Aug 26, 2023

Logs when accessing my homefeed, after deploying v1.55.29:

0|app  | ▶ 2023-08-26T07:39:23.532Z GET / (userLibrary.controller) {}
0|app  | fetchByAuthors>arrayToSet_4d94501d1f78ac091dbc9b4d: 313.329ms
0|app  | prepareSidebar_fetchRecentActivity: 263.748ms
0|app  | ◀ 2023-08-26T07:39:23.532Z GET / responds 200 after 716 ms

This matches with the trace from Datadog's APM:

image

(source: https://app.datadoghq.com/apm/trace/1360823663931202456?colorBy=service&env=production&graphType=flamegraph&shouldShowLegend=true&sort=time&spanID=1360823663931202456&spanViewType=metadata&timeHint=1693035563520.005)

=> Observations:

  • snip.arrayToSet takes almost half of full request's processing time! (313ms / 716ms)
  • fetchRecentActivity mongodb query is also quite costly, and potentially worse on user accounts that are subscribed to thousands of users.

adrienjoly added a commit that referenced this issue Aug 26, 2023
partially reverts #666.
contributes to #681.
@adrienjoly
Copy link
Member Author

adrienjoly commented Aug 26, 2023

Logs for same request, after optimisation (see commit above):

0|app  | ▶ 2023-08-26T08:26:26.654Z GET / (userLibrary.controller) {}
0|app  | fetchByAuthors>arrayToSet_4d94501d1f78ac091dbc9b4d: 1.185ms
0|app  | prepareSidebar_fetchRecentActivity: 10.33ms
0|app  | ◀ 2023-08-26T08:26:26.654Z GET / responds 200 after 63 ms

=> arrayToSet is 300x faster than the previous version based on reduce() 🎉

APM span confirms the improvement:

image

source: https://app.datadoghq.com/apm/trace/6625358628523903867?colorBy=service&env=production&graphType=flamegraph&shouldShowLegend=true&sort=time&spanID=6625358628523903867&spanViewType=metadata&timeHint=1693038386648.0042

@adrienjoly
Copy link
Member Author

Next steps:

  • let's make sure that home feed rendering time is reasonable, even with profiles that have many subscribers and/or subscriptions.
  • remove calls to console.time() and console.timeEnd()

adrienjoly added a commit that referenced this issue Sep 2, 2023
temporary workaround to reduce stress on mongodb, until we find a solution to solve #681 and #682.
root cause may be caused/related to #630 and/or #634.
adrienjoly pushed a commit that referenced this issue Sep 2, 2023
## [1.55.61](v1.55.60...v1.55.61) (2023-09-02)

### Bug Fixes

* linter issues caused by previous commit ([17998a1](17998a1))
* **perf:** disable history on home page ([52536d3](52536d3)), closes [#681](#681) [#682](#682) [#630](#630) [#634](#634)
@adrienjoly
Copy link
Member Author

the "activity" sidebar section seems to put high stress on our mongodb instance.

image

...which makes sense because it starts non-optimized and heavy db queries against all the users followed by the logged user.

=> after several outages in production, I decided to turn that feature off by commenting out the corresponding code, in 52536d3 and 17998a1

=> if there are no outages in the coming week, we should probably just get rid of this feature, for good, by deleting the commented code.

@adrienjoly
Copy link
Member Author

Issue fixed by 4e15f75.

Performance problems reduced by disabling fetching of followed users' activity on feed/home page. (52536d3)

=> remaining tasks were transfered over to issue #682.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant