Comparing Canister Cycles vs Performance Counter
From Internet Computer Wiki
Revision as of 20:38, 28 November 2022 by Diego.prats (talk | contribs)
The example walks through a scenario of charging cycles that includes inter-canister calls and how the performance counter relates to the work done by canisters.
Setup
- The User sends an 1KiB Ingress Message to Canister A
- The Canister A calls Canister B with an 2KiB Update Call
- The Canister B responds to Canister A with an 300-byte reply
- The Canister A responds to User with an 500-byte reply
Example Cycles Flow
Naming conventions:
1K == 1'0001KiB == 1'024 bytes1M == 1'000'0001MiB == 1'048'576 bytes1B == 1'000'000'0001T == 1'000'000'000'000
| Example Step | Canister A Cycles Balance |
Canister A Perf Counter |
Canister B Cycles Balance |
Canister B Perf Counter |
|---|---|---|---|---|
| 1. Initial state | 1T |
N/A1) |
1T |
N/A1)
|
| 2. Canister A receives 1KiB Ingress Message | -1,2M -1KiB*2K ≈999'996M |
N/A1) |
1T |
N/A1)
|
| 3. Canister A starts execution 2) | -590K -5B/10*4 ≈997'996M |
0(5B limit) |
1T |
N/A1)
|
| 4. Canister A executes 100M WASM instructions | 997'996M |
+100M=100M(5B limit) |
1T |
N/A1)
|
| 5. Canister A sends 2KiB call to Canister B 3) | -260K -2KiB*1K -2MiB*1K -590K -5B/10*4 ≈993'897M |
+3*21 +2KiB ≈100M(5B limit) |
1T |
N/A1)
|
| 6. Canister A finishes execution 4) | +(5B-100M)*4/10≈995'857M |
N/A1) |
1T |
N/A1)
|
| 7. Canister B starts execution 2) | 995'857M |
N/A1) |
-590K -5B/10*4 ≈997'999M |
0(5B limit) |
| 8. Canister B executes 100M WASM instructions | 995'857M |
N/A1) |
997'999M |
+100M=100M(5B limit) |
| 9. Canister B sends 300-byte reply to Canister A | 995'857M |
N/A1) |
997'999M |
+2*21 +300 ≈100M(5B limit) |
| 10. Canister B finishes execution 4) | 995'857M |
N/A1) |
+(5B-100M)*4/10≈999'959M |
N/A1)
|
| 11. Canister A receives a reply from Canister B 5) | +(2MiB-300)*1K≈997'953M |
N/A1) |
999'959M |
N/A1)
|
| 12. Canister A starts reply callback execution 6) | 997'953M |
0(5B limit) |
999'959M |
N/A1)
|
| 13. Canister A executes 100M WASM instructions | 997'953M |
+100M=100M(5B limit) |
999'959M |
N/A1)
|
| 14. Canister A sends 500-byte reply to User | 997'953M |
+2*21 +500 ≈100M(5B limit) |
999'959M |
N/A1)
|
| 15. Canister A finishes execution 4) | +(5B-100M)*4/10≈999'913M |
N/A1) |
999'959M |
N/A1)
|
| Total: | ~87M Cyclesfor ~200M WASM Instructions Executed + messaging |
~41M Cyclesfor ~100M WASM Instructions Executed + messaging |
Notes:
- The Performance Counter is available only during execution, so it's marked as
N/Awhen the execution has not started yet. - The Canister get charged:
- 590K
- for the update message execution
- 5B/10*4
- for 5B instructions it can potentially execute
- The Canister get charged:
- 260K
- for the inter-canister call
- 2KiB * 1'000
- for byte transmission
- 2MiB * 1K
- for the maximum reply size
- 590K
- for the reply update message execution
- 5B/10*4
- for 5B instructions limit it can potentially execute in the reply handler
- The Canister gets a refund for the unused Instructions.
- The Canister gets a refund for the unused reply bytes.
- The Canister has already been charged in step 5 for the reply execution and 5B instructions.