Difference between revisions of "Parallelism"

From Internet Computer Wiki
Jump to: navigation, search
(Created page with "==Canisters as actors== The actor model is a mathematical model of concurrent computation, where, in response to a message, an actor can modify its state, send messages, and...")
 
 
(5 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 +
'''A single canister smart contract has one thread of execution for updates, but the Internet Computer can execute a ''massive number'' of canisters in parallel. In addition, a distinction is made between requests that need to update the state of a canister, and queries, which cannot modify the state of a canister.'''
 +
 +
The programming model of the Internet Computer consists of '''memory-isolated canisters''' communicating by '''asynchronous''' message passing of binary data encoding Candid values. A canister processes its messages one-at-a-time, preventing race conditions. A canister uses call-backs to register what needs to be done with the result of any inter-canister messages it issues.
 +
 
==Canisters as actors==
 
==Canisters as actors==
  
Line 12: Line 16:
  
 
In actor terminology, each actor has a mailing address that is used to receive messages. A canister also has a mailing address, which happens to look similar to an IPv6 address.
 
In actor terminology, each actor has a mailing address that is used to receive messages. A canister also has a mailing address, which happens to look similar to an IPv6 address.
 
A single canister has only one thread of execution for updates, but the Internet Computer executes a potentially massive number of canisters in parallel. In addition, we make a distinction between requests that need to update the state of a canister, and queries, which cannot modify the state of a canister.
 
  
 
While a canister's update throughput is limited by consensus of the blockchain and the single thread of execution, a canister can serve hundreds of queries concurrently, achieving throughput in the order of thousands of queries per second, and latency measured in milliseconds.  
 
While a canister's update throughput is limited by consensus of the blockchain and the single thread of execution, a canister can serve hundreds of queries concurrently, achieving throughput in the order of thousands of queries per second, and latency measured in milliseconds.  
Line 20: Line 22:
  
 
In addition, the Motoko programming language, which is tailored to the Internet Computer, is inspired by the actor model.
 
In addition, the Motoko programming language, which is tailored to the Internet Computer, is inspired by the actor model.
 +
 +
==See Also==
 +
* '''The Internet Computer project website (hosted on the IC): [https://internetcomputer.org/ internetcomputer.org]'''

Latest revision as of 13:02, 27 February 2023

A single canister smart contract has one thread of execution for updates, but the Internet Computer can execute a massive number of canisters in parallel. In addition, a distinction is made between requests that need to update the state of a canister, and queries, which cannot modify the state of a canister.

The programming model of the Internet Computer consists of memory-isolated canisters communicating by asynchronous message passing of binary data encoding Candid values. A canister processes its messages one-at-a-time, preventing race conditions. A canister uses call-backs to register what needs to be done with the result of any inter-canister messages it issues.

Canisters as actors

The actor model is a mathematical model of concurrent computation, where, in response to a message, an actor can modify its state, send messages, and create more actors.

A canister is like an actor in many respects. For example, an actor has:

  • a private state that can only be modified by the canister itself;
  • a single thread of execution, so it does not need lock-based synchronization;
  • the ability to communicate with other canisters through asynchronous messages; and
  • the ability to create new canisters.

An important difference between traditional actors and canisters is that canisters on the Internet Computer have bidirectional message passing. Messages are divided into requests and responses, where requests can be replied to and the Internet Computer keeps track of the callback for responses.

In actor terminology, each actor has a mailing address that is used to receive messages. A canister also has a mailing address, which happens to look similar to an IPv6 address.

While a canister's update throughput is limited by consensus of the blockchain and the single thread of execution, a canister can serve hundreds of queries concurrently, achieving throughput in the order of thousands of queries per second, and latency measured in milliseconds.

To complete this picture, it should be added that end users also participate as actors in the model. This means that browsers and mobile apps can directly perform update and query operations on canisters.

In addition, the Motoko programming language, which is tailored to the Internet Computer, is inspired by the actor model.

See Also