How Discourse handle high HTTP request?

I just take a look at the source code, there is no Rails #stale? method on controller to return 304
or cache the entire page based on record cache key

Sorry to bother you, I’m just curious about this

People are not hitting reload like crazy on Discourse … we rarely need this kind of protection. And will just use rate limiting for that.

Instead we rely on anonymous cache for the bulk of our high load handling. It has 2 modes

  • For high hits from anon we cache home page and topic pages for up to 1 minute
  • For high hits from logged in, we revert to anon if a topic page is under extreme load

You can read through for all the gory implementation.

https://github.com/discourse/discourse/blob/be5e889b1b55de148b32ae864390a585e027b1ec/lib/middleware/anonymous_cache.rb

We also have tons of internal caching of bits and pieces to avoid high cost queries.

8 Likes

ok thanks for the enlightenment

I will read the source code more deeper

2 Likes