Giter Club home page Giter Club logo

canbench's Introduction

Apache-2.0 Chat on the Forum

canbench

canbench is a tool for benchmarking canisters on the Internet Computer.

Background

Canister smart contracts on the Internet Computer consume compute and memory resources. Given that resources are finite, there are bounds in place when canisters execute a message (transaction):

  1. Instructions: a monotonically increasing counter that's corelated with the amount of computation and memory accesses.
  2. Dirty Pages: the number of memory pages that are written to.

A single message execution must stay within the allowed bounds, otherwise it's terminated. canbench provides developers the tools and insights to understand how their code is using instructions and memory. Support for reporting dirty pages will be available once there's a way to retrieve dirty page information from the IC.

Use Cases

  • Understanding how a canister consumes instructions, heap memory, and stable memory.
  • Detecting performance regressions locally or on CI.
  • Analyzing where performance bottlenecks are present.

Features

  • Metrics that are relevant

    Typically benchmarking tools run a benchmark multiple times and return the average time. On the Internet Computer, where instrumentation is deterministic, this approach is neither ideal nor insightful. Instead, canbench reports the number of instructions consumed, as well as changes to both heap and stable memories.

  • Easy detection of regressions

    canbench allows you to persist the benchmarking results in your canister's repository. Storing the benchmarking results allows canbench to determine how the performance has changed relative to the past to detect regressions.

  • Generous instruction limit

    While messages on the Internet Computer are bound to a few billion instructions, canbench can run benchmarks that are up to 10 trillion instructions, giving you the freedom to write resource-intensive benchmarks as needed.

  • Language Agnostic

    canbench can, in theory, benchmark canisters written in any language. Initially support for only Rust exists, but support for additional languages can easily be introduced.

Installation

cargo install canbench

Quickstart (Rust)

See the crate's documentation.

Github CI Support

canbench can be included in Github CI to automatically detect performance changes. Have a look at the workflows in this repository for working examples. You'll need the following:

  1. Scripts for executing the benchmark, which can be found in the scripts directory.
  2. A workflow for canbench to post a comment with the benchmarking results. See canbench-post-comment.yml.
  3. A job for uploading the PR number to the artifacts. This is necessary for step #2 to work correctly. See upload-pr-number in ci.yml.
  4. The benchmarking job in CI. See benchmark-fibonacci-example in ci.yml.

Once you have the CI workflow set up, the job will pass if there are no significant performance changes detected and fail otherwise. A comment is added to the PR to show the results. See this PR for an example.

canbench's People

Contributors

ielashi avatar dependabot[bot] avatar frederikrothenberger avatar maksymar avatar jasonz-dfinity avatar michael-weigelt avatar

Stargazers

 avatar Antonio Ventilii avatar Moritz Fuller avatar Yota avatar Tanguy avatar Luca Bertelli avatar Jordan Last avatar Dominic Wörner avatar Ethan Celletti avatar  avatar

Watchers

Claudio Russo avatar Gabor Greif avatar Roel Storms avatar Yotam Harchol avatar Dimitris Sarlis avatar  avatar Tony Pernicano avatar Marko Kosmerl avatar Linwei Shang avatar Maria Dubovitskaya avatar Ben Zhai avatar Thomas Locher avatar  avatar  avatar Artem Korotkikh avatar

canbench's Issues

`canbench` as a blackbox performance monitoring tool

In separate discussions with @frederikrothenberger and @jasonz-dfinity, there was the question of whether canbench supports benchmarking asynchronous methods. In these discussions, the idea we gravitated to was to create some kind of library support within canbench, where a developer can annotate a canister's endpoints, and then receive useful metrics/stats on the performance of these endpoints. These stats can be used in production for general performance monitoring, or in integration tests with PocketIC to benchmark async workflows.

cc @mbjorkqvist who had a similar request.

Enhancement: Avoid dependency on ic-cdk

Currently the bench macro requires users to depend on ic-cdk. That dependency can potentially be avoided by exporting the method as a query directly and handling the serialization/deserialization of the args/reply manually as opposed to relying the ic-cdk's query macro.

Support installing benchmarking canister with args

canbench currently can only deploy a canister to benchmark if that canister takes no arguments. It'd be desirable for many users to be able to specify some arguments. Perhaps an option to specify the args can be added to canbench.yml.

Improve error message when installing the benchmarking canister fails

If canbench fails to install the benchmarking canister, it currently returns a cryptic error:

Error executing benchmark create_account_bench. Error:
ingress Completed: Reply: 0x4449444c016c01b3c4b1f204680100010a00000000000000000101
ingress Err: IC0503: Canister rwlgt-iiaaa-aaaaa-aaaaa-cai trapped explicitly: failed to decode call arguments: Custom(Cannot parse header 

Caused by:
    binary parser error: io error)
Err: IC0304: Attempt to execute a message on canister rwlgt-iiaaa-aaaaa-aaaaa-cai which contains no Wasm module

canbench should return a more explicit error message that states:

  1. The canister installation failed.
  2. Why it failed.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.