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

Home page load becomes abnormally slow #93

Closed
hunghvu opened this issue Dec 20, 2023 · 6 comments
Closed

Home page load becomes abnormally slow #93

hunghvu opened this issue Dec 20, 2023 · 6 comments
Labels
aws bug Something isn't working mongodb-atlas performance urgent Happen in production, need to patch ASAP
Milestone

Comments

@hunghvu
Copy link
Owner

hunghvu commented Dec 20, 2023

For some reasons, loading a home page becomes abnormally slow (>5s, even 30s). The server does not seem to have any error. This did not happen a few days ago, and the server has been online since then.

That said, loading an article is still as fast. This leans towards the possibility of MongoDB free tier throttle. Homepage uses dynamic fetching, so it is affected, meanwhile, article page is cached, hence only the first load is slow (but need to validate).

  • Try to restart the server.
  • See if there is a throttle or bottleneck somewhere (AWS, Cloudflare, MongoDB Atlas).
@hunghvu hunghvu added this to the 1.1 milestone Dec 20, 2023
@hunghvu
Copy link
Owner Author

hunghvu commented Dec 20, 2023

More than 30s from Postman.

image

@hunghvu
Copy link
Owner Author

hunghvu commented Dec 20, 2023

Indeed the issue is due to MongoDB 10gb bandwidth throttle for M0 tier.
https://www.mongodb.com/docs/atlas/reference/free-shared-limitations/

Because of that, we move to self-hosting the database via Docker for now. It is not mission critical, so we can stand the risk. M2 from MongoDB still has 20 GB limitation per 7 days. Since we are not even sure why 10 GB of M0 is exceeded in the first place, M2 probably will not cut it. The below are steps to migrate from Atlas to Docker host.

  1. Install mongodb tool on the local machine (https://www.mongodb.com/try/download/bi-connector, deb package).
  2. Perform mongodump --out /path/to/dump --uri="mongodb+srv://username:password". Note, the username and password cannot contains certain character like @, *, &, or else, mongodb tool cannot parse the string.
  3. Create a key pair in EC2 Network & security, download the pem file. ED25519 is preferred than RSA.
  4. Derive the public key via ssh-keygen -y -f file.pem.
  5. Change file permission via sudo chmod 400 file.pem, or else an error due to open permission will show up.
  6. Copy and paste the public key to ~/.ssh/authorized_keys on EC2 instance (via AWS console).
  7. Copy database dump to EC2 instance via rsync -avzh -e "ssh -i file.pem" /path/to/mongodump/ ec2-user@ip:/path/on/ec2.
  8. Install mongodb tool on EC2 instance.
  9. Perform mongodb restore via mongorestore --authenticationDatabase=admin mongodb://username:password@host /path/to/mongodump. Keep in mind there should be authenticationDatabase, or else, we see SCRAM-SHA-1 error. Still not sure why, but here is the reference: https://stackoverflow.com/questions/68927857/mongoexport-auth-error-using-mechanism-scram-sha-1

@hunghvu
Copy link
Owner Author

hunghvu commented Dec 20, 2023

Note: the deployment is done, but we will monitor the issue for the next few days. I all go well, we will close this issue afterward.

@hunghvu
Copy link
Owner Author

hunghvu commented Dec 20, 2023

That said, we can keep looking for an alternative managed solution with a better price point.

@hunghvu
Copy link
Owner Author

hunghvu commented Dec 21, 2023

Now utilize the uses of indexes to speed up queries. Also, remove indexes from fields that are underutilized at this stage. In the future, after the search function is implemented, we can update the indexes again.

Theoretically, this should improve performance. Note, indexes creates by Payload are single indexes, not compound indexes.

@hunghvu
Copy link
Owner Author

hunghvu commented Dec 22, 2023

The M0 throttle seems to be lifted now. Anyway, the cluster is upgraded to M2, now we use the self-host container as a backup. The main DB solution is still Atlas.

Consider this issue as resolved now.

@hunghvu hunghvu closed this as completed Dec 22, 2023
hunghvu added a commit that referenced this issue Dec 30, 2023
* chore: bump packages

* chore: mark development tasks as no-cache and non-persistent

* chore: bump packages

* feat: add self-host container for mongodb, relates to #93

* feat: expose containers to only localhost (#94)

* feat: optimize indexes to improve performance, relates to #93

* feat: closes #78, enable AVIF image support

* chore: change some parameters to improve experience in development environement

* fix: closes #88, prevent long string overflows

* feat: use animated SVG background, related to #92

* feat: closes #92, overhaul article page UI to improve accessibility and make theme suitable with animated background

* fix: closes #84, increase line height

* fix: closes #89, make letters start at the same place in ordered list, and align ol with ul

* feat: closes #91, overhaul blog page UI and make it SSR

* chore: bump packages

* chore: bump Geist font to v1.2.0, and rename files

* fix: closes #101, now code snippet uses GeistMono font

* feat: load SVG background via next/image to utilize optimization (preload LCP), related to #99

* feat: enforce cache-control on Next.js, relates to #98

* feat: minimize highlight.js import, and change CSS import location, related to #99

* feat: disable external page prefetch, related to #99

* fix: bundle public folder in production

* fix: closes #102, CSS layer order issue

* feat: make divider appear on lg screen and make it dimmer

* feat: adjust navbar color and border to further emphasize articles

* feat: multiple adjusment to text and border, divider color to increase separation and readability

* fix: closes #103, make toast message bottom-center, and remove white border

* feat: adjust font size to improve readability

* feat: remove primeicons to reduce bundle size (blocking and unused CSS), related to #99

* chore: bump packages

* fix: disable AVIF support in an attempt to resolve #105

* fix: remove redundant scrollbar in main page

* feat: use native browser scroll to reduce bundled JS size, related to #99

* feat: massively remove unused CSS bytes by reconfiguring the interaction between PrimeReact and Tailwind, related to #99
@hunghvu hunghvu added the urgent Happen in production, need to patch ASAP label Mar 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
aws bug Something isn't working mongodb-atlas performance urgent Happen in production, need to patch ASAP
Projects
None yet
Development

No branches or pull requests

1 participant