Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Support the stable endpoint from MSC2946 #11329

Merged
merged 9 commits into from
Nov 29, 2021
7 changes: 5 additions & 2 deletions synapse/handlers/room_summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
SynapseError,
UnsupportedRoomVersionError,
)
from synapse.api.ratelimiting import Ratelimiter
from synapse.events import EventBase
from synapse.types import JsonDict, Requester
from synapse.util.caches.response_cache import ResponseCache
Expand Down Expand Up @@ -93,7 +94,9 @@ def __init__(self, hs: "HomeServer"):
self._event_serializer = hs.get_event_client_serializer()
self._server_name = hs.hostname
self._federation_client = hs.get_federation_client()
self._request_ratelimiter = hs.get_request_ratelimiter()
self._ratelimiter = Ratelimiter(
store=self._store, clock=hs.get_clock(), rate_hz=5, burst_count=10
Copy link
Contributor

Choose a reason for hiding this comment

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

Where did these numbers come from, out of interest?

Copy link
Member Author

Choose a reason for hiding this comment

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

I made them up, they should allow for 5 queries per second without enforcing any ratelimiting until 10 queries. This might be a bit high, but I'm never quite sure what to put here and usually err on the side of allowing more. 🤷

Copy link
Contributor

Choose a reason for hiding this comment

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

Fair enough. We can always tighten the limits!

(Though there's a part of me that wonders if rate limiting ought to be handled by the load balancer to keep Synapse itself simpler.)

Copy link
Member Author

Choose a reason for hiding this comment

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

Some rate limits can be tweaked by the Synapse config, FWIW. They can also depend on particular data, e.g. you could limit the message rate per user, per room, per message type (or something like that).

)

# If a user tries to fetch the same page multiple times in quick succession,
# only process the first attempt and return its result to subsequent requests.
Expand Down Expand Up @@ -277,7 +280,7 @@ async def get_room_hierarchy(
Returns:
The JSON hierarchy dictionary.
"""
await self._request_ratelimiter.ratelimit(requester)
await self._ratelimiter.ratelimit(requester)

# If a user tries to fetch the same page multiple times in quick succession,
# only process the first attempt and return its result to subsequent requests.
Expand Down