Skip to content

File Rate Limiter #751

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

Merged
merged 6 commits into from
Jul 24, 2022
Merged

File Rate Limiter #751

merged 6 commits into from
Jul 24, 2022

Conversation

avanaur
Copy link
Contributor

@avanaur avanaur commented Jul 12, 2022

Changes

File Rate Limiter on upload and download.
When file_rate_limiter = 0, rate limiter is disabled.

As part of changes, TryParseForm() and GetField() were moved to common pkg

Fixes

Resolves #671

Tests

Tasks to complete before merging PR:

  • Ensure system tests are passing. If not Run them manually to check for any regressions 📋
  • Do any new system tests need added to test this change? do any existing system tests need updated? If so create a PR at 0chain/system_test
  • Merge your system tests PR to master AFTER merging this PR

Associated PRs (Link as appropriate):

  • 0chain:
  • gosdk:
  • system_test:
  • zboxcli:
  • zwalletcli:
  • Other: ...

@codecov-commenter
Copy link

codecov-commenter commented Jul 12, 2022

Codecov Report

Merging #751 (18ef400) into staging (f43a67c) will decrease coverage by 0.74%.
The diff coverage is 68.31%.

@@             Coverage Diff             @@
##           staging     #751      +/-   ##
===========================================
- Coverage    30.01%   29.26%   -0.75%     
===========================================
  Files           68       77       +9     
  Lines         7653     8002     +349     
===========================================
+ Hits          2297     2342      +45     
- Misses        5014     5316     +302     
- Partials       342      344       +2     
Flag Coverage Δ
Unit-Tests 29.26% <68.31%> (-0.75%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...ain.net/blobbercore/handler/file_command_delete.go 0.00% <0.00%> (ø)
code/go/0chain.net/blobbercore/handler/helper.go 0.00% <ø> (-62.97%) ⬇️
code/go/0chain.net/core/common/request_form.go 25.00% <25.00%> (ø)
.../0chain.net/blobbercore/handler/storage_handler.go 39.30% <66.66%> (ø)
code/go/0chain.net/core/common/rate_limiter.go 58.51% <78.57%> (ø)
code/go/0chain.net/blobbercore/handler/context.go 34.93% <100.00%> (ø)
code/go/0chain.net/blobbercore/handler/handler.go 64.14% <100.00%> (ø)
...et/blobbercore/handler/object_operation_handler.go 43.03% <100.00%> (ø)
code/go/0chain.net/core/common/lookup.go 0.00% <0.00%> (ø)
code/go/0chain.net/core/common/errors.go 25.00% <0.00%> (ø)
... and 6 more

Help us with your feedback. Take ten seconds to tell us how you rate us.

@avanaur avanaur marked this pull request as ready for review July 12, 2022 09:50
@avanaur avanaur requested a review from cnlangzi July 12, 2022 11:13
}

func requestField(r *http.Request, key string) (string, bool) {
if r.Form != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

We can get URL query data from r.Form as well, so don't have to call the r.URL.Query below, and the code could be like:

if err := r.ParseForm(); err != nil {
  return "", err
}

return r.Form.Get(key), nil

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 opted to just moved TryParseForm() and GetField() from handler package to common and reuse that GetField() instead.

@@ -69,6 +69,7 @@ block_worker: http://198.18.0.98:9091

handlers:
rate_limit: 0 # 10 per second . it can't too small one if a large file is download with blocks
file_rate_limit: 1000 # 100 files per second
Copy link
Contributor

Choose a reason for hiding this comment

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

1000 is too fast for both upload/download by default, the blobber would be under DDoS, so perhaps 100. And if the upload/download process get affected, then we might need to optimize the block size to reduce the requests number.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Make sense. Adjust the chunk size instead of creating too many API requests for upload, and block size for download.

Copy link
Contributor

@peterlimg peterlimg left a comment

Choose a reason for hiding this comment

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

lgtm

@peterlimg peterlimg merged commit 6aeb594 into staging Jul 24, 2022
@cnlangzi cnlangzi deleted the feature/file-rate-limit branch January 29, 2023 01:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

request limit on CRUD operations
3 participants