Skip to content

Comments

feat: Add an optional argument to set memory allocation#596

Closed
dsarlis wants to merge 7 commits intomasterfrom
dimitris/memory-allocation
Closed

feat: Add an optional argument to set memory allocation#596
dsarlis wants to merge 7 commits intomasterfrom
dimitris/memory-allocation

Conversation

@dsarlis
Copy link
Contributor

@dsarlis dsarlis commented Apr 27, 2020

This patch adds an optional parameter to dfx canister install which allows the user to set a memory allocation for their canister.

I've modeled this similarly to the param for compute allocation. Let me know what you think and also feel free to push commits on this branch if it's easier and faster.

I'm also not sure what kind of testing you'd expect for this. I've used this patch to present in the last global R&D, so it works (at least it did the job I wanted).

@dsarlis dsarlis requested a review from a team April 27, 2020 15:22
@dsarlis dsarlis requested a review from a team as a code owner April 27, 2020 15:22
.long("memory-allocation")
.short("m")
.takes_value(true)
.default_value("8GB")
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you want to duplicate the information about the default here? I think the two sensible design spaces are:

  • The system defines a default, dfx will, if no --memory-allocation is passed, send none, system default applies
  • The system defines no default, the field is mandatory, dfx determines (here) what the default is.

With this code, there are now two components both defining a default value; that’s odd.

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'm fine with the first approach.

Btw, the same happens for compute allocation and I don't remember why it was done like that.

With this code, there are now two components both defining a default value; that’s odd.

No, there's two components that follow the default value set by a common reference (the public spec) :) But yeah it's probably redundant since the replica will enforce the default anyway.

Copy link
Contributor

Choose a reason for hiding this comment

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

I wouldn’t consider it “following the public spec” if the client makes an optional field mandatory and hides the default value (which may change in later versions). But this is getting philosophical and we are in agreement :-)

Maybe the public spec shouldn’t be the place to define default values… oh well.

same happens for compute allocation

Yes, we should do the same for that too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe the public spec shouldn’t be the place to define default values… oh well.

This would mean that a concrete Internet Computer implementation could choose an arbitrary (within the specified range) default value if none is specified, which would mean that if I use dfx against two different implementations of the IC, then I get different behavior for the same request. Maybe it's cool, maybe it's not.

Anyway, I already fell in your trap

But this is getting philosophical and we are in agreement :-)

and as I said I'm fine with your first suggestion.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd much prefer the first approach.

No, there's two components that follow the default value set by a common reference (the public spec) :)

I think the mistake is treating it as a "default value" at the entry point. The spec just says if the value isn't specified the system should treat it like 2^33. That's at the instanciation point. Technically we could not have a field at all and still be spec compliant.

The interface definition is clear that the field is optional, so there should be nothing on the wire.

Copy link
Contributor

Choose a reason for hiding this comment

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

Glad to see everyone in agreement :-)

nix/sources.json Outdated
},
"dfinity": {
"ref": "v0.5.4",
"ref": "master",
Copy link
Contributor

Choose a reason for hiding this comment

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

is this only for testing?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well, yes and no :)

I needed to point to a commit past v0.5.5 in dfinity to make things work for my demo last week. I'll use what I'm told here (presumably v0.5.6). Better yet, if someone bumps dfinity separately (say for a new SDK release) until this is merged and it includes the commit I'm interested in, I don't need to touch this at all.

Copy link
Contributor

Choose a reason for hiding this comment

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

Great, muting the thread without approving. Just ping us if you do need a change that needs an infra review!

Copy link
Contributor Author

@dsarlis dsarlis left a comment

Choose a reason for hiding this comment

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

I've made the requested changes. Specifically, the main change is that memory allocation was turned into a truly optional field for dfx, so if it's not set it's not even serialized into the CBOR request sent over to the replica.

@dsarlis dsarlis changed the title Add an optional argument to set memory allocation feat: Add an optional argument to set memory allocation Apr 28, 2020
@hansl hansl requested a review from lsgunnlsgunn April 28, 2020 17:27
Copy link
Contributor

@lsgunnlsgunn lsgunnlsgunn left a comment

Choose a reason for hiding this comment

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

Usage message looks reasonable.

@hansl
Copy link
Contributor

hansl commented Apr 28, 2020

This LGTM, but is blocked on NOT moving sources.json to master, which blocks the PR. As soon as Replica has a release with this change in, we can patch this PR and make it in.

@dsarlis
Copy link
Contributor Author

dsarlis commented Apr 29, 2020

This LGTM, but is blocked on NOT moving sources.json to master, which blocks the PR. As soon as Replica has a release with this change in, we can patch this PR and make it in.

SGTM. Is there an expected date to get v0.5.7? I checked v0.5.6 and it still doesn't include the commit I need.

@dsarlis
Copy link
Contributor Author

dsarlis commented May 12, 2020

This LGTM, but is blocked on NOT moving sources.json to master, which blocks the PR. As soon as Replica has a release with this change in, we can patch this PR and make it in.

@hansl Looks like there's been a v0.5.7 release that includes the changes needed on the replica side, so I was able to drop the changes to sources.json. PTAL and let me know if we need anything else here.

@nomeata
Copy link
Contributor

nomeata commented May 12, 2020

I should point out that if we want to be strict, the replica shoundn’t expose this feature until it has been part of a spec release (it’s not in 0.2), and therefore the SDK shouldn't be in it before.

See https://github.com/dfinity-lab/ic-ref/issues/44 for the ongoing disucssion what goes into 0.4.

Given the fuzz arond “focus on Tungston” it is not clear if memory allocation will make it. (Maybe the argument “it’s already almost there” will apply.)

Whether we want to be strict in using the spec to plan an implement features is not my call to make. It unquestionably adds delays and some friction.

@dsarlis
Copy link
Contributor Author

dsarlis commented May 12, 2020

I should point out that if we want to be strict, the replica shoundn’t expose this feature until it has been part of a spec release (it’s not in 0.2), and therefore the SDK shouldn't be in it before.

The replica already supports this feature (for like a month now). Are you suggesting that I revert the change?

See dfinity-lab/ic-ref#44 for the ongoing disucssion what goes into 0.4.

Given the fuzz arond “focus on Tungston” it is not clear if memory allocation will make it. (Maybe the argument “it’s already almost there” will apply.)

I assume you meant "focus on Tungsten". My understanding is that the memory allocation is something we want to be included for Tungsten and I am fairly certain that's @granstrom vision as well. Johan please correct me if I'm wrong.

Whether we want to be strict in using the spec to plan an implement features is not my call to make. It unquestionably adds delays and some friction.

The way I see it, if you can add a feature in a non-breaking way (memory allocation is such a case because there's a sensible default that is used even if SDK doesn't support it) then I don't see any problem looking ahead and implementing features that will be needed in general. But it's certainly not my call either how strict we want to be.

@dsarlis
Copy link
Contributor Author

dsarlis commented May 12, 2020

Also perhaps we should move the discussion about including memory allocation or not on the issue you mentioned to avoid unnecessary noise in the current PR.

@nomeata
Copy link
Contributor

nomeata commented May 12, 2020

Also perhaps we should move the discussion about including memory allocation or not on the issue you mentioned to avoid unnecessary noise in the current PR.

Yes, absolute! Actually, the Google doc linked from that PR is the right place to discuss. I just wanted to increase visibility of that discussion

@dsarlis
Copy link
Contributor Author

dsarlis commented Oct 6, 2020

A flag to set the memory allocation seems to be already available in latest dfx (checked against 0.6.10). Closing the current PR.

@dsarlis dsarlis closed this Oct 6, 2020
dfinity-bot added a commit that referenced this pull request Jan 19, 2021
## Changelog for advisory-db:
Branch: master
Commits: [rustsec/advisory-db@b08a98ac...89b9e106](rustsec/advisory-db@b08a98a...89b9e10)

* [`6ea698b8`](rustsec/advisory-db@6ea698b) lazy-init: Missing Send bound for Lazy (khuey/lazy-init[RustSec/advisory-db⁠#9](http://r.duckduckgo.com/l/?uddg=https://github.com/RustSec/advisory-db/issues/9))
* [`6703edaf`](rustsec/advisory-db@6703eda) apply review changes
* [`47d589b0`](rustsec/advisory-db@47d589b) Assigned RUSTSEC-2021-0004 to lazy-init
* [`efb79eff`](rustsec/advisory-db@efb79ef) report double drop issue in glsl-layout
* [`47061ba3`](rustsec/advisory-db@47061ba) Report 0025-im to RustSec
* [`4cf4c549`](rustsec/advisory-db@4cf4c54) Assigned RUSTSEC-2021-0005 to glsl-layout
* [`b2a7af1c`](rustsec/advisory-db@b2a7af1) Assigned RUSTSEC-2020-0096 to im
* [`1613b211`](rustsec/advisory-db@1613b21) Report 0063-xcb to RustSec
* [`ea867420`](rustsec/advisory-db@ea86742) Assigned RUSTSEC-2020-0097 to xcb
* [`d7de84ed`](rustsec/advisory-db@d7de84e) Add advisory for data race in rusb ([RustSec/advisory-db⁠#580](http://r.duckduckgo.com/l/?uddg=https://github.com/RustSec/advisory-db/issues/580))
* [`3fbe0648`](rustsec/advisory-db@3fbe064) Assigned RUSTSEC-2020-0098 to rusb ([RustSec/advisory-db⁠#581](http://r.duckduckgo.com/l/?uddg=https://github.com/RustSec/advisory-db/issues/581))
* [`c9886554`](rustsec/advisory-db@c988655) Add advisory for data race in aovec ([RustSec/advisory-db⁠#528](http://r.duckduckgo.com/l/?uddg=https://github.com/RustSec/advisory-db/issues/528))
* [`315e464c`](rustsec/advisory-db@315e464) Assigned RUSTSEC-2020-0099 to aovec ([RustSec/advisory-db⁠#596](http://r.duckduckgo.com/l/?uddg=https://github.com/RustSec/advisory-db/issues/596))
* [`97aa97b0`](rustsec/advisory-db@97aa97b) cache: exposes internally used raw pointer ([RustSec/advisory-db⁠#543](http://r.duckduckgo.com/l/?uddg=https://github.com/RustSec/advisory-db/issues/543))
* [`89b9e106`](rustsec/advisory-db@89b9e10) Assigned RUSTSEC-2021-0006 to cache ([RustSec/advisory-db⁠#598](http://r.duckduckgo.com/l/?uddg=https://github.com/RustSec/advisory-db/issues/598))
mergify bot pushed a commit that referenced this pull request Jan 19, 2021
## Changelog for advisory-db:
Branch: master
Commits: [rustsec/advisory-db@b08a98ac...89b9e106](rustsec/advisory-db@b08a98a...89b9e10)

* [`6ea698b8`](rustsec/advisory-db@6ea698b) lazy-init: Missing Send bound for Lazy (khuey/lazy-init[RustSec/advisory-db⁠#9](http://r.duckduckgo.com/l/?uddg=https://github.com/RustSec/advisory-db/issues/9))
* [`6703edaf`](rustsec/advisory-db@6703eda) apply review changes
* [`47d589b0`](rustsec/advisory-db@47d589b) Assigned RUSTSEC-2021-0004 to lazy-init
* [`efb79eff`](rustsec/advisory-db@efb79ef) report double drop issue in glsl-layout
* [`47061ba3`](rustsec/advisory-db@47061ba) Report 0025-im to RustSec
* [`4cf4c549`](rustsec/advisory-db@4cf4c54) Assigned RUSTSEC-2021-0005 to glsl-layout
* [`b2a7af1c`](rustsec/advisory-db@b2a7af1) Assigned RUSTSEC-2020-0096 to im
* [`1613b211`](rustsec/advisory-db@1613b21) Report 0063-xcb to RustSec
* [`ea867420`](rustsec/advisory-db@ea86742) Assigned RUSTSEC-2020-0097 to xcb
* [`d7de84ed`](rustsec/advisory-db@d7de84e) Add advisory for data race in rusb ([RustSec/advisory-db⁠#580](http://r.duckduckgo.com/l/?uddg=https://github.com/RustSec/advisory-db/issues/580))
* [`3fbe0648`](rustsec/advisory-db@3fbe064) Assigned RUSTSEC-2020-0098 to rusb ([RustSec/advisory-db⁠#581](http://r.duckduckgo.com/l/?uddg=https://github.com/RustSec/advisory-db/issues/581))
* [`c9886554`](rustsec/advisory-db@c988655) Add advisory for data race in aovec ([RustSec/advisory-db⁠#528](http://r.duckduckgo.com/l/?uddg=https://github.com/RustSec/advisory-db/issues/528))
* [`315e464c`](rustsec/advisory-db@315e464) Assigned RUSTSEC-2020-0099 to aovec ([RustSec/advisory-db⁠#596](http://r.duckduckgo.com/l/?uddg=https://github.com/RustSec/advisory-db/issues/596))
* [`97aa97b0`](rustsec/advisory-db@97aa97b) cache: exposes internally used raw pointer ([RustSec/advisory-db⁠#543](http://r.duckduckgo.com/l/?uddg=https://github.com/RustSec/advisory-db/issues/543))
* [`89b9e106`](rustsec/advisory-db@89b9e10) Assigned RUSTSEC-2021-0006 to cache ([RustSec/advisory-db⁠#598](http://r.duckduckgo.com/l/?uddg=https://github.com/RustSec/advisory-db/issues/598))
@lwshang lwshang deleted the dimitris/memory-allocation branch July 29, 2022 19:00
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.

5 participants