Skip to content

Commit 17199d3

Browse files
Merge pull request #1181 from dfinity/jessiemongeon1-patch-12
add: Deploy to ICP Ninja + Standardize README
2 parents c22b156 + 3314541 commit 17199d3

File tree

1 file changed

+12
-119
lines changed

1 file changed

+12
-119
lines changed

motoko/low_wasm_memory/README.md

Lines changed: 12 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -2,76 +2,24 @@
22

33
The Internet Computer can automatically execute a special type of function called a low Wasm memory hook, which runs when the canister's available Wasm memory falls below the `wasm_memory_threshold`.
44

5-
This Motoko example demonstrates using the low Wasm memory hook on ICP. If you're interested in how this example is implemented in Rust, check out the [Rust variation](../../rust/low_wasm_memory).
5+
This Motoko example demonstrates using the low Wasm memory hook on ICP. For more information take a look at [low Wasm memory hook specification](https://internetcomputer.org/docs/references/ic-interface-spec#on-low-wasm-memory).
66

7-
The example consists of a canister named `low_wasm_memory_hook` that increases usage of Wasm memory in every heartbeat execution until the low Wasm memory hook is run.
7+
## Deploying from ICP Ninja
88

9-
## Prerequisites
10-
This example requires an installation of:
9+
[![](https://icp.ninja/assets/open.svg)](https://icp.ninja/editor?g=https://github.com/dfinity/examples/tree/master/motoko/low_wasm_memory)
1110

12-
- [x] Install the [IC SDK](https://internetcomputer.org/docs/current/developer-docs/getting-started/install).
13-
- [x] Clone the example dapp project: `git clone https://github.com/dfinity/examples`
11+
## Build and deploy from the command-line
1412

15-
## Using the example
13+
### 1. [Download and install the IC SDK.](https://internetcomputer.org/docs/building-apps/getting-started/install)
1614

17-
In this example, the canister will periodically increase its memory usage (as defined in the `heartbeat` function) until the low Wasm memory hook is run
18-
when the memory usage exceeds the `wasm_memory_threshold`.
15+
### 2. Download your project from ICP Ninja using the 'Download files' button on the upper left corner, or [clone the GitHub examples repository.](https://github.com/dfinity/examples/)
1916

20-
- #### Step 1: Setup project environment
17+
### 3. Navigate into the project's directory.
2118

22-
Navigate into the folder containing the project's files and start a local developer environment with the commands:
19+
### 4. Deploy the project to your local environment:
2320

24-
```sh
25-
cd examples/motoko/low_wasm_memory
26-
dfx start --clean
27-
```
28-
29-
This terminal will stay blocked, printing log messages, until the `Ctrl+C` is pressed or the `dfx stop` command is run.
30-
31-
- #### Step 2: Open another terminal window in the same directory:
32-
33-
```sh
34-
cd examples/motoko/low_wasm_memory
35-
```
36-
37-
- #### Step 3: Create the `low_wasm_memory_hook` canister
38-
39-
```sh
40-
dfx canister create low_wasm_memory_hook
41-
```
42-
43-
Example output:
44-
45-
```sh
46-
Created a wallet canister on the "local" network for user "default" with ID "uqqxf-5h777-77774-qaaaa-cai"
47-
low_wasm_memory_hook canister created with canister id: uxrrr-q7777-77774-qaaaq-cai
48-
```
49-
50-
- #### Step 4: Update canister settings
51-
52-
Update the canister's settings to modify the Wasm memory limit and threshold:
53-
54-
```sh
55-
dfx canister update-settings low_wasm_memory_hook --wasm-memory-limit 5000000 --wasm-memory-threshold 2000000
5621
```
57-
58-
- #### Step 5: Compile and deploy the `low_wasm_memory_hook` canister:
59-
60-
```sh
61-
dfx deploy low_wasm_memory_hook
62-
```
63-
64-
Example output:
65-
66-
```sh
67-
Deploying: low_wasm_memory_hook
68-
All canisters have already been created.
69-
Building canister 'low_wasm_memory_hook'.
70-
Installed code for canister low_wasm_memory_hook, with canister ID uxrrr-q7777-77774-qaaaq-cai
71-
Deployed canisters.
72-
URLs:
73-
Backend canister via Candid interface:
74-
low_wasm_memory_hook: http://127.0.0.1:4943/?canisterId=u6s2n-gx777-77774-qaaba-cai&id=uxrrr-q7777-77774-qaaaq-cai
22+
dfx start --background --clean && dfx deploy
7523
```
7624

7725
After the deployment, the memory usage periodically increases as defined in the `heartbeat` function.
@@ -87,31 +35,7 @@ You can verify that the canister settings got updated and check the current 'Mem
8735
dfx canister status low_wasm_memory_hook
8836
```
8937

90-
Example output:
91-
92-
```sh
93-
Canister status call result for low_wasm_memory_hook.
94-
Status: Running
95-
Controllers: 3apfx-fn75o-xtwmf-svjzg-hu5xt-bg2dr-ubczq-uhvlq-2a5gf-ya4fn-dqe uqqxf-5h777-77774-qaaaa-cai
96-
Memory allocation: 0 Bytes
97-
Compute allocation: 0 %
98-
Freezing threshold: 2_592_000 Seconds
99-
Idle cycles burned per day: 24_269_759 Cycles
100-
Memory Size: 2_374_914 Bytes
101-
Balance: 2_996_231_412_893 Cycles
102-
Reserved: 0 Cycles
103-
Reserved cycles limit: 5_000_000_000_000 Cycles
104-
Wasm memory limit: 5_000_000 Bytes
105-
Wasm memory threshold: 2_000_000 Bytes
106-
Module hash: 0x0c100162e1be161b9ef6fd95efb07f0541903c77a47e85a49a800705d6a09a11
107-
Number of queries: 0
108-
Instructions spent in queries: 0
109-
Total query request payload size: 0 Bytes
110-
Total query response payload size: 0 Bytes
111-
Log visibility: controllers
112-
```
113-
114-
- #### Step 6: After a few seconds, observe the output of the `getExecutedFunctionsOrder` query:
38+
After a few seconds, observe the output of the `getExecutedFunctionsOrder` query:
11539

11640
Query the canister by calling `getExecutedFunctionsOrder` to get the order of executed functions.
11741

@@ -121,37 +45,6 @@ dfx canister call low_wasm_memory_hook --query getExecutedFunctionsOrder
12145

12246
Repeat the call until the last executed method is `onLowWasmMemory`.
12347

124-
Example output:
125-
126-
```sh
127-
(
128-
vec { variant { heartbeat }; variant { heartbeat }; variant { heartbeat }; variant { heartbeat }; variant { heartbeat }; variant { heartbeat }; variant { heartbeat }; variant { heartbeat }; variant { heartbeat }; variant { heartbeat }; variant { heartbeat }; variant { heartbeat }; variant { heartbeat }; variant { heartbeat }; variant { heartbeat }; variant { heartbeat }; variant { heartbeat }; variant { heartbeat }; variant { heartbeat }; variant { heartbeat }; variant { heartbeat }; variant { onLowWasmMemory };},
129-
)
130-
```
131-
132-
To repeat the example, you can redeploy the canister and reset its state with the following command:
133-
134-
```sh
135-
dfx deploy low_wasm_memory_hook --mode reinstall
136-
```
137-
138-
## Further learning
139-
1. [Low memory hook](https://internetcomputer.org/docs/motoko/main/canister-maintenance/memory) in Motoko documentation
140-
2. Have a look at the locally running dashboard. The URL is at the end of the `dfx start` command: `Dashboard: http://localhost:...`
141-
3. Check out `low_wasm_memory_hook` canister's Candid user interface. The URLs are at the end of the `dfx deploy` command: `low_wasm_memory_hook: http://127.0.0.1:...`
142-
143-
### Canister interface
144-
145-
The `low_wasm_memory_hook` canister provides the following interface:
146-
* `getExecutedFunctionsOrder` ; returns the vector with values of `FnType` (a variant with `#heartbeat` or `#onLowWasmMemory`) representing the order of functions executed.
147-
148-
Example usage:
149-
```sh
150-
dfx canister call low_wasm_memory_hook --query getExecutedFunctionsOrder
151-
```
152-
153-
## Resources
154-
For more information take a look at [low Wasm memory hook specification](https://internetcomputer.org/docs/references/ic-interface-spec#on-low-wasm-memory).
155-
15648
## Security considerations and best practices
157-
If you base your application on this example, we recommend you familiarize yourself with and adhere to the [security best practices](https://internetcomputer.org/docs/current/references/security/) for developing on the Internet Computer. This example may not implement all the best practices.
49+
50+
If you base your application on this example, it is recommended that you familiarize yourself with and adhere to the [security best practices](https://internetcomputer.org/docs/building-apps/security/overview) for developing on ICP. This example may not implement all the best practices.

0 commit comments

Comments
 (0)