Skip to content
This repository was archived by the owner on Jan 23, 2025. It is now read-only.

Limit # of requests per service #13

Merged
merged 4 commits into from
Mar 10, 2023
Merged

Conversation

jradhakrishnan
Copy link
Contributor

[ch14893]

Limit # of requests per service in addition to rate limiting at a per request level within a service

@jradhakrishnan jradhakrishnan requested a review from a team March 9, 2023 12:28
)

type serviceQueues struct {
config *Config
Copy link

Choose a reason for hiding this comment

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

Nit: taking a reference to the whole Config seems unnecessary. Just copying the two limit settings is better.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was in two minds about it but decided to keep the pointer. It looks like both pointer and int are 8 bytes on 64bit OS. So it's more efficient to use the pointer instead of two int types.

@xujiaxj xujiaxj requested a review from a team March 9, 2023 20:20
type serviceQueues struct {
config *Config
requestStates *sync.Map
requestCount int
Copy link
Contributor

Choose a reason for hiding this comment

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

requestStates is a map. Why not use map's len function instead of having a separate variable to track the map size?

Copy link

Choose a reason for hiding this comment

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

See golang/go#20680.

Guess a len function on a current map is not preferred by the library developer. Java ConcurrentHashMap has the same concern about performance.

@jradhakrishnan jradhakrishnan merged commit edfaa7e into main Mar 10, 2023
@jradhakrishnan jradhakrishnan deleted the request_limit_enforcement branch March 10, 2023 21:55
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants