TykTechnologies / tyk

Tyk Open Source API Gateway written in Go, supporting REST, GraphQL, TCP and gRPC protocols
Other
9.62k stars 1.08k forks source link

[TT-2380] - (hybrid) use singleflight when Recreating session for key #2620

Open asoorm opened 4 years ago

asoorm commented 4 years ago

Branch/Environment/Version

all

Describe the bug

[Oct 15 00:07:44]  INFO Recreating session for key: ****8e86 api_id=60c036eea7a842b3728ca493a228b83f api_name=httpbin mw=AuthKey org_id=5bffbf8ef461e30001136627 origin=172.18.0.1 path=/httpbin/get
[Oct 15 00:07:44]  INFO Recreating session for key: ****8e86 api_id=60c036eea7a842b3728ca493a228b83f api_name=httpbin mw=AuthKey org_id=5bffbf8ef461e30001136627 origin=172.18.0.1 path=/httpbin/get
[Oct 15 00:07:44]  INFO Recreating session for key: ****8e86 api_id=60c036eea7a842b3728ca493a228b83f api_name=httpbin mw=AuthKey org_id=5bffbf8ef461e30001136627 origin=172.18.0.1 path=/httpbin/get
[Oct 15 00:07:44]  INFO Recreating session for key: ****8e86 api_id=60c036eea7a842b3728ca493a228b83f api_name=httpbin mw=AuthKey org_id=5bffbf8ef461e30001136627 origin=172.18.0.1 path=/httpbin/get
[Oct 15 00:07:44]  INFO Recreating session for key: ****8e86 api_id=60c036eea7a842b3728ca493a228b83f api_name=httpbin mw=AuthKey org_id=5bffbf8ef461e30001136627 origin=172.18.0.1 path=/httpbin/get
[Oct 15 00:07:44]  INFO Recreating session for key: ****8e86 api_id=60c036eea7a842b3728ca493a228b83f api_name=httpbin mw=AuthKey org_id=5bffbf8ef461e30001136627 origin=172.18.0.1 path=/httpbin/get
...
...

What happens:

API key does not exist in hybrid cluster of gateways. Hybrid Gateway calls MDCB to obtain the API key. Under high RPS, multiple calls to MDCB occur for the same information in parallel. This is particularly problematic when client is using incorrect credentials.

What should happen:

A single call in-flight to the hybrid layer at a given point in time for given api key would be a more efficient solution. especially in the case of the key not being found or if the api key is being used at a high RPS.

https://godoc.org/golang.org/x/sync/singleflight

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs, please add comments to this ticket if you would like it to stay open. Thank you for your contributions.

asoorm commented 4 years ago

not stale