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

feat: gateway back pressure mechanism implementation #1847

Merged
merged 2 commits into from
May 5, 2022

Conversation

saurav-malani
Copy link
Contributor

@saurav-malani saurav-malani commented Apr 13, 2022

Description of the change

To avoid OOM kill of gateway in scenarios where we have a lot of sudden spike in gateway traffic or when DB is under pressure. We have introduced a back pressure mechanism that restrict on maximum number of active request in memory, by using counting Semaphore.

Notion Link

Notion Link

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added unit tests for the code
  • I have made corresponding changes to the documentation

Security

  • The code changed/added as part of this pull request won't create any security issues with how the software is being used.

@saurav-malani saurav-malani marked this pull request as ready for review April 13, 2022 14:08
@codecov
Copy link

codecov bot commented Apr 13, 2022

Codecov Report

Merging #1847 (63b88b4) into master (24252a0) will increase coverage by 0.00%.
The diff coverage is 9.67%.

@@           Coverage Diff           @@
##           master    #1847   +/-   ##
=======================================
  Coverage   25.54%   25.54%           
=======================================
  Files         116      116           
  Lines       28738    28736    -2     
=======================================
  Hits         7340     7340           
+ Misses      21056    21054    -2     
  Partials      342      342           
Impacted Files Coverage Δ
gateway/gateway.go 50.68% <3.44%> (+0.27%) ⬆️
gateway/configuration.go 96.36% <100.00%> (+0.13%) ⬆️
...ebugger/destination/eventDeliveryStatusUploader.go 90.12% <0.00%> (-3.71%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 24252a0...63b88b4. Read the comment docs.

gateway/configuration.go Outdated Show resolved Hide resolved
gateway/configuration.go Outdated Show resolved Hide resolved
gateway/gateway.go Outdated Show resolved Hide resolved
gateway/gateway.go Outdated Show resolved Hide resolved
gateway/gateway.go Outdated Show resolved Hide resolved
gateway/gateway.go Outdated Show resolved Hide resolved
gateway/gateway.go Outdated Show resolved Hide resolved
gateway/gateway.go Outdated Show resolved Hide resolved
gateway/gateway.go Outdated Show resolved Hide resolved
gateway/gateway.go Outdated Show resolved Hide resolved
@saurav-malani saurav-malani changed the title WIP: feat: Gateway back pressure mechanism implementation feat: Gateway back pressure mechanism implementation Apr 14, 2022
gateway/gateway.go Outdated Show resolved Hide resolved
gateway/gateway.go Outdated Show resolved Hide resolved
gateway/gateway.go Outdated Show resolved Hide resolved
@atzoum atzoum changed the title feat: Gateway back pressure mechanism implementation feat: gateway back pressure mechanism implementation Apr 18, 2022
gateway/gateway.go Outdated Show resolved Hide resolved
gateway/response/response.go Outdated Show resolved Hide resolved
gateway/response/response.go Outdated Show resolved Hide resolved
gateway/configuration.go Outdated Show resolved Hide resolved
gateway/gateway.go Outdated Show resolved Hide resolved
gateway/gateway.go Outdated Show resolved Hide resolved
gateway/gateway.go Outdated Show resolved Hide resolved
@lvrach
Copy link
Member

lvrach commented Apr 26, 2022

removed the Ready for Review, until changes are addressed/pushed

@saurav-malani saurav-malani marked this pull request as draft April 26, 2022 12:03
@saurav-malani saurav-malani marked this pull request as ready for review April 27, 2022 06:35
middleware/middleware.go Outdated Show resolved Hide resolved
middleware/middleware.go Outdated Show resolved Hide resolved
middleware/middleware.go Outdated Show resolved Hide resolved
middleware/middleware_test.go Outdated Show resolved Hide resolved
Comment on lines +38 to +42
name: "max concurrent request: 10",
maxConcurrentRequests: 10,
totalReq: 10,
},
Copy link
Member

Choose a reason for hiding this comment

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

[minor] and subjective. I would prefer to see expected responses here, instead of computing them in:

require.Equal(t, tt.totalReq-tt.maxConcurrentRequests, resp503, "actual 503 resp different than expected.")

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the reason I have written it like this is, to make it more intuitive that anything over allowed concurrentRequests would be 503. tt.totalReq-tt.maxConcurrentRequests mathematically indicates that. @lvrach WDYT?

gateway/gateway.go Outdated Show resolved Hide resolved
gateway/gateway.go Outdated Show resolved Hide resolved
Copy link
Contributor

@atzoum atzoum left a comment

Choose a reason for hiding this comment

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

LGTM

middleware/middleware.go Outdated Show resolved Hide resolved
Copy link
Collaborator

@fracasula fracasula left a comment

Choose a reason for hiding this comment

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

Looks fairly good, I've added very few comments, the blocking one is the one about doing atomic.LoadInt32(&concurrentRequests). Let me know if it doesn't make sense of course.

@fracasula
Copy link
Collaborator

fracasula commented Apr 28, 2022 via email

@chandumlg chandumlg merged commit c9b6f02 into master May 5, 2022
@chandumlg chandumlg deleted the feat.gatewayBackPressure branch May 5, 2022 19:32
This was referenced Jun 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants