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

Remove upper bound of 1 for quotas #514

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ext/semian/resource.c
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ check_quota_arg(VALUE quota)
if (TYPE(quota) != T_FIXNUM && TYPE(quota) != T_FLOAT) {
rb_raise(rb_eTypeError, "expected decimal type for quota");
}
if (NUM2DBL(quota) <= 0 || NUM2DBL(quota) > 1) {
if (NUM2DBL(quota) <= 0) {
Copy link
Member

Choose a reason for hiding this comment

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

a quota ratio > 1 should have the same effect as a quota of 1.

This would mean that there as many (or more) available tickets as there are protected resources.

I don't see any benefit to removing this restriction, can you elaborate on your reasoning for removing it?

Copy link
Author

Choose a reason for hiding this comment

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

In the case where I expect a worker to access the same resource multiple times concurrently, I think we need a quota > 1.

Copy link
Member

Choose a reason for hiding this comment

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

Is that the case in Puma or something, where we have a single linux process with multiple ruby threads? I thought that they were backed by pthreads though (which linux should see as separate processes in the context of sysv api, i think?), so wouldn't it be better to have each worker register accordingly?

Unless it is somehow impossible based on the threading model, I think having each worker register (and thus, inherently raise the number of available tickets) is preferable to changing the quota logic.

Offhand, I can only think this could possible be the case for ruby fibers, but even then, only one can actually be active at a given time so they should be able to release the resource when they are done with it.

Can you elaborate more on in what context a worker would need to access the same resource concurrently? And in this context, what is a "worker" as it relates to the ruby and linux threading models?

rb_raise(rb_eArgError, "quota must be a decimal between 0 and 1");
}
c_quota = NUM2DBL(quota);
Expand Down
Loading