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

Rough sketch of user quota and bandwidth limiting #1118

Merged
merged 22 commits into from Apr 14, 2015
Merged

Conversation

kuenishi
Copy link
Contributor

@kuenishi kuenishi commented Apr 6, 2015

  • Still no tests
  • only applies for object and object part uploads / gets
  • riak_cs_quota is a behaviour where programmers can make thier own module (see callback definition)
  • riak_cs_simple_quota is a simple quota limiter which takes care of Object puts
  • riak_cs_bw_limitter is a stupid bandwidth / access rate limitter on objects
  • they are only controllable from attached console: type riak_cs_simple_quota:help() for detail usage
  • to use them, write {quota_modules, [riak_cs_simple_quota, riak_cs_bw_limitter]} in advanced.config
  • to change quota modules, config change and restart are required
  • All data size units are in Bytes.

For @joecaswell 's review.

Remaining works or notes on usage:

  • separate owner and accessor case: bandwidth and access is for accessor, whild owner is for usage
  • retrieving user's latest storage usage from moss.storage won't scale for many CS nodes
  • add tests
  • Add some cool http headers
  • Multibag

@kuenishi
Copy link
Contributor Author

kuenishi commented Apr 6, 2015

Quota

simple idea of quota

  • Bahaviour named riak_cs_quota that define callback spec
  • Plugin-architecture
  • Live users' usage, access and bandwidth monitoring
  • Limits of users' usage, access and bandwidth

Use cases

  • Stop upload as Quota over
  • Stop upload as too much bandwidth
  • Stop upload as too much request rate, rate limitation

-> three infos stored in moss.users? no nah

  • Quota => on bucket owners

** For usage: cluster-wide / soft quota / both user and bucket level / persistent state
** For bandwidth and counts: Node-wide / soft quota / both user and bucket level / non-persistent

  • check hook point is right after policy chedck
  • update hook point is right after in riak_cs_access_log_handler

@kuenishi
Copy link
Contributor Author

kuenishi commented Apr 6, 2015

Other notification style on rate limiting / quota: below are all quotations -

Twitter API

Note that these HTTP headers are contextual. When using app-only auth, they indicate the rate limit for the application context. When using user-based auth, they indicate the rate limit for that user-application context.

  • X-Rate-Limit-Limit: the rate limit ceiling for that given request
  • X-Rate-Limit-Remaining: the number of requests left for the 15 minute window
  • X-Rate-Limit-Reset: the remaining window before the rate limit resets in UTC epoch seconds

When an application exceeds the rate limit for a given API endpoint, the Twitter API will now return an HTTP 429 “Too Many Requests” response code instead of the variety of codes you would find across the v1’s Search and REST APIs.

Foursquare

Please note that rate limits are not per endpoint, but per top-level endpoint group. For example, in an hour, if you make 2,500 userless requests to venues/search and 2,500 userless requests to venues/explore, you would have exhausted your venues/* rate limits for that hour; however, you would still have 500 requests left for tips/*.

Generally rate limits follow the rules above; however, some endpoints may have different limits due to security or other considerations. For the most current and accurate rate limit usage information for a particular request type, inspect the X-RateLimit-Remaining and X-RateLimit-Limit HTTP headers of API responses.

If you are currently over limits, our API will return a 403 error, and the response object returned by our API will be empty. We will also include a X-RateLimit-Reset header in the response, which is a timestamp that corresponds to when your rate limits will reset.

Etsy

Headers: Every API response bears rate limit headers, as described below:

X-RateLimit-Limit: 10000
X-RateLimit-Remaining: 9924

These default rate limits are subject to change at any time, without notice.

Calais

@kuenishi kuenishi added this to the 2.0.1 milestone Apr 6, 2015
@kuenishi
Copy link
Contributor Author

kuenishi commented Apr 9, 2015

They're done.

@kuenishi
Copy link
Contributor Author

kuenishi commented Apr 9, 2015

r_t passed for me. I believe it's ready for review.

%% This is experimental feature. These interfaces and behaviousr
%% may or may not change until general availability.
%%
%% To use 'inherited' your own module, it should be configured in
Copy link
Contributor

Choose a reason for hiding this comment

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

What does inherited mean?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Behaviour implementation.

@kuenishi
Copy link
Contributor Author

I need more to please dialyzer

@kuenishi
Copy link
Contributor Author

I think this is ready for review again. Will run r_t next week, and if we agree on basic ideas, then I'll squash commits and create a cleanly rebased pull request.

Len when is_integer(Len) ->
case Method of
'PUT' -> Len;
'DELETE' -> - Len
Copy link
Contributor

Choose a reason for hiding this comment

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

DELETE request length is almost zero.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ooops

get_latest_usage(_Pid, _User, _, N, N) -> {error, notfound};
get_latest_usage(Pid, User, EndSec, N, Max) ->
End = calendar:gregorian_seconds_to_datetime(EndSec),
ADayAgo = calendar:gregorian_seconds_to_datetime(EndSec - 86400),
Copy link
Contributor

Choose a reason for hiding this comment

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

If hard coded 86400 is meant for the default value of storage_archive_period, using application environment value would be better.

@shino
Copy link
Contributor

shino commented Apr 13, 2015

Both bw and quota limiter modules work well, great! ☀️
I will 👍 after above comments are addressed and dialyzer failure is fixed.

@kuenishi
Copy link
Contributor Author

Updated ^^;

Detailed storage stats

Reviewed-by: kuenishi
get_latest_usage(Pid, User) ->
Now = calendar:now_to_datetime(os:timestamp()),
NowASec = calendar:datetime_to_gregorian_seconds(Now),
LeewaySeconds = riak_cs_gc:leeway_seconds(),
Copy link
Contributor

Choose a reason for hiding this comment

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

riak_cs_storage:archive_period() ?

@shino
Copy link
Contributor

shino commented Apr 14, 2015

Added the last comment 😅

@kuenishi
Copy link
Contributor Author

oh, conflicts....

Conflicts:
	src/riak_cs_config.erl
	src/riak_cs_storage_d.erl
@kuenishi
Copy link
Contributor Author

Conflicts resolved.

borshop added a commit that referenced this pull request Apr 14, 2015
Rough sketch of user quota and bandwidth limiting

Reviewed-by: shino
@kuenishi
Copy link
Contributor Author

@borshop merge

@borshop borshop merged commit bd6f4a2 into 2.0 Apr 14, 2015
@kuenishi kuenishi deleted the feature/quota-hook branch April 14, 2015 07:04
@kuenishi kuenishi restored the feature/quota-hook branch April 28, 2015 01:23
@kuenishi kuenishi deleted the feature/quota-hook branch April 28, 2015 01:24
kuenishi added a commit that referenced this pull request Apr 28, 2015
@kuenishi kuenishi modified the milestones: 2.1.0, 2.0.1 Apr 28, 2015
borshop added a commit that referenced this pull request Apr 28, 2015
Revert #1118, #1120 and #1123 from release notes

Reviewed-by: shino
@kuenishi kuenishi modified the milestones: 2.2.0, 2.1.0 Apr 28, 2015
@Basho-JIRA
Copy link

Release note already written: see an item starting "Module-level hook point for .." in https://github.com/basho/riak_cs/blob/develop/RELEASE-NOTES.md#additions

_[posted via JIRA by Kota Uenishi]_

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.

None yet

5 participants