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

Document resource limiting #510

Merged
merged 14 commits into from
Oct 12, 2021
Merged

Document resource limiting #510

merged 14 commits into from
Oct 12, 2021

Conversation

maciejhirsz
Copy link
Contributor

No description provided.

@@ -404,9 +404,50 @@ impl Builder {

/// Register a new resource kind. Errors if `label` is already registered, or if number of
/// registered resources would exceed 8.
///
Copy link
Collaborator

@jsdw jsdw Oct 12, 2021

Choose a reason for hiding this comment

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

The thing that worries me about these duplicated docs is keeping them both in sync in the event that things change. I don't think that there is a nice way to share documentation though is there?

I'd be tempted to have one version of the docs link to the other version eg something like

/// Register a new reousrce kind. See [`crate::http_server::Builder::register_resource()`] for example usage.

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think that there is a nice way to share documentation though is there?

I don't know of a way either and it's quite common to see "look over here for details" in rustdocs.

Copy link
Member

Choose a reason for hiding this comment

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

I don't know of a way either and it's quite common to see "look over here for details" in rustdocs.

Yes, that's what I meant at least.

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 still have the duplicated comments on these, but the bulk of it has been moved to the resource_limiting module, link included, so I reckon this is resolved now?

@niklasad1 niklasad1 mentioned this pull request Oct 12, 2021
/// #
/// #[rpc(server)]
/// pub trait Rpc {
/// #[method(name = "my_expensive_method", resources("cpu" = 5, "mem" = 2))]
Copy link
Collaborator

@jsdw jsdw Oct 12, 2021

Choose a reason for hiding this comment

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

In the case of the macro, what is the default resource usage? IIRC (but I am rather sketchy on this code) you define the default usage when creating the Resource object, so I guess if you use the macro, it will define some default defaults? (I'd assume that the default defaults are to use 0 of a resource, and so if you don't specify resource usage in the macro, the method is assumed to use nothing?)

Either way; perhaps it'd be useful to make this clear?

Copy link
Contributor

Choose a reason for hiding this comment

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

Either way; perhaps it'd be useful to make this clear?

I agree. It is not immediately obvious. I think one important piece to understand this is to first grok the way resources are set up: not here, around the trait marked with #[rpc] or at the method definition site; resources – along with their capacity and default cost – are set up on the server when it is constructed.

The reason for this separation is that the server app might want to make the resource set up configurable (through CLI or config file) so that different instances of the server can use different caps/defaults (e.g. fast servers == higher caps). It is also technically tricky (impossible?) to have a resource defined on the rpc modules and then somehow coalesced into a server-wide singleton.

So there's a UX problem here, but one we can't really fix. I think the docs should explain this important piece, as it makes understanding the rest much easier.

http-server/src/server.rs Outdated Show resolved Hide resolved
/// #
/// #[rpc(server)]
/// pub trait Rpc {
/// #[method(name = "my_expensive_method", resources("cpu" = 5, "mem" = 2))]
Copy link
Contributor

Choose a reason for hiding this comment

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

Either way; perhaps it'd be useful to make this clear?

I agree. It is not immediately obvious. I think one important piece to understand this is to first grok the way resources are set up: not here, around the trait marked with #[rpc] or at the method definition site; resources – along with their capacity and default cost – are set up on the server when it is constructed.

The reason for this separation is that the server app might want to make the resource set up configurable (through CLI or config file) so that different instances of the server can use different caps/defaults (e.g. fast servers == higher caps). It is also technically tricky (impossible?) to have a resource defined on the rpc modules and then somehow coalesced into a server-wide singleton.

So there's a UX problem here, but one we can't really fix. I think the docs should explain this important piece, as it makes understanding the rest much easier.

Co-authored-by: David <dvdplm@gmail.com>
http-server/src/server.rs Outdated Show resolved Hide resolved
ws-server/src/server.rs Outdated Show resolved Hide resolved
http-server/Cargo.toml Outdated Show resolved Hide resolved
maciejhirsz and others added 2 commits October 12, 2021 13:00
Co-authored-by: Niklas Adolfsson <niklasadolfsson1@gmail.com>
utils/src/server/mod.rs Show resolved Hide resolved
utils/src/server/resource_limiting.rs Outdated Show resolved Hide resolved
utils/src/server/resource_limiting.rs Outdated Show resolved Hide resolved
utils/src/server/resource_limiting.rs Outdated Show resolved Hide resolved
utils/src/server/resource_limiting.rs Show resolved Hide resolved
ws-server/Cargo.toml Outdated Show resolved Hide resolved
maciejhirsz and others added 2 commits October 12, 2021 14:33
@dvdplm dvdplm merged commit 75045f4 into master Oct 12, 2021
@dvdplm dvdplm deleted the mh-resource-limiting-docs branch October 12, 2021 13:27
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.

4 participants