Reputation: 1688
I have just started to follow ballerina by reading https://ballerina.io/ documentation. when I try to run Hello World Parallel then I have no idea how internally it works?
import ballerina/io;
public function main() {
@strand {thread: "any"}
worker w1 {
io:println("Hello, World! #m");
}
@strand {thread: "any"}
worker w2 {
io:println("Hello, World! #n");
}
@strand {thread: "any"}
worker w3 {
io:println("Hello, World! #k");
}
}
Upvotes: 4
Views: 202
Reputation: 1615
Ballerina run on a thread pool configured on VM startup. The thread count is configurable with environment variable BALLERINA_MAX_POOL_SIZE
, when this is not explicitly provided it will default to thread count = (logical cpu count X 2).
Ballerina runtime scheduler work on pre-configured thread pool and it does not have a one to one correspondence with native threads, the flow of control (what usually called thread) is called a strand
and many strands will be mapped to a single OS thread. This is very similar to green threads
, user level threads
, or Project Loom fibers.
All you get is lightweight threads.
As far as I understand reactive programming was developed as a way to tame the complexities coming with programming complex asynchronous systems, similar to reactive programming, Ballerina support another way to write asynchronous systems with async await style (similar to C#) https://ballerina.io/learn/by-example/async.html
Most of the Ballerina libraries are non-blocking (does not block the OS thread), this means the Ballerina program using that library looks like the code written using straight forward blocking code, but under the hood they are multiplexed by Ballerina schedulear. So if you mean the reactive programming paradigm, then no, but if you mean the non-blockingness and simplicity (without call backs etc,) then yes.
Upvotes: 7