I’m developing a dApp with a Rust canister on the Internet Computer that has a supply function (e.g., for users supplying tokens/assets). What happens if 1000 users call this supply function at the exact same time?
Does ICP allow this many concurrent calls?
Are the calls processed sequentially or concurrently?
Is there a limit on concurrency that might cause calls to fail or queue up?
How should I design my Rust canister’s supply function to handle such load efficiently?
Canisters are actors, so they execute messages (ingress, request, response, timer, etc.) sequentially.
That being said, an update call is not necessarily a single message. If your update method makes no downstream calls (i.e. there is no await), then it will be executed as a single message, so all 1000 calls will execute sequentially.
If OTOH your canister does make calls, then every await becomes a commit point, breaking the update call into separate message executions. In this case, message executions associated to different calls can be arbitrarily interleaved.
Yes, a canister may handle up to 1M concurrent calls and have a similar number of enqueued ingress messages and incoming requests (just don’t expect amazing latency from this setup).
See above.
There are various limits in the protocol implementation (message memory, ingress history size, callbacks per canister and per subnet, etc.) that may kick in, depending on subnet load. But with nothing else of note going on on the subnet, your canister is allowed more concurrent calls than it can usefully handle.
Make it fast. If you expect that kind of concurrent load, route the actual workload to other canisters (4 of them can run concurrently on a subnet), potentially across multiple subnets. Essentually, act as a router. If there isn’t much work to do (e.g. you’re just incrementing and returning a counter), then there’s not much left to do, except don’t do anything extra. Just common sense stuff.
Wanted to know !
What is the concurrency threshold for ICP canister functions? Specifically, can our system successfully handle 1000 simultaneous user function calls, or is ICP infrastructure limited to processing only 100-200 concurrent requests?
Thanks for confirming the concurrency details. We’ll design our system with these ICP limitations in mind - ensuring critical operations can handle the scenario where only 50 concurrent calls are guaranteed to succeed, if subnet load is hight then it can increase