2017-07-20 15:23:23 +00:00
|
|
|
## Machinarium
|
2016-11-08 11:29:48 +00:00
|
|
|
|
2017-05-22 10:10:43 +00:00
|
|
|
Machinarium allows to create fast networked and event-driven asynchronous applications in
|
|
|
|
synchronous/procedural manner instead of using traditional callback approach.
|
2016-11-08 15:15:47 +00:00
|
|
|
|
2017-07-24 13:09:39 +00:00
|
|
|
*Public API ⇨* [sources/machinarium.h](sources/machinarium.h)
|
2017-07-20 15:08:06 +00:00
|
|
|
|
2017-07-20 15:23:23 +00:00
|
|
|
#### Threads and coroutines
|
|
|
|
|
2017-07-20 15:31:49 +00:00
|
|
|
Machinarium is based on combination of `pthreads(7)` and custom made implementation of efficient cooperative
|
|
|
|
multi-tasking primitives (coroutines).
|
2017-07-20 15:08:06 +00:00
|
|
|
|
2017-07-20 15:23:23 +00:00
|
|
|
Each coroutine executed using own stack context and transparently scheduled by `epoll(7)` event-loop logic.
|
2017-07-24 12:59:59 +00:00
|
|
|
Each working Machinarium thread can handle thousands of executing coroutines.
|
2017-07-20 15:08:06 +00:00
|
|
|
|
|
|
|
#### Messaging and Channels
|
|
|
|
|
|
|
|
Machinarium messages and channels are used to provide IPC between threads and
|
2017-07-24 13:09:39 +00:00
|
|
|
coroutines. Ideally, this approach should be sufficient to fulfill needs of most multi-threaded applications
|
2017-07-20 15:46:36 +00:00
|
|
|
without the need of using additional access synchronization.
|
2017-07-20 15:08:06 +00:00
|
|
|
|
|
|
|
#### Efficient TCP/IP networking
|
|
|
|
|
|
|
|
Machinarium IO API primitives can be used to develop high-performance client and server applications.
|
2017-07-24 13:09:39 +00:00
|
|
|
By doing blocking IO calls, currently executing coroutine suspends and switches
|
2017-07-20 15:08:06 +00:00
|
|
|
to a next one ready to go. When the original request completed, timedout or cancel event happened,
|
2017-07-24 13:09:39 +00:00
|
|
|
coroutine resumes.
|
2017-07-20 15:08:06 +00:00
|
|
|
|
2017-07-20 15:16:00 +00:00
|
|
|
One of the main goals of networking API design is performance. To reduce number of system calls
|
2017-07-20 15:08:06 +00:00
|
|
|
read operation implemented with readahead support. It is fully buffered and transparently continue to read
|
2017-07-24 13:09:39 +00:00
|
|
|
socket data even when no active calls are in progress, to reduce `epoll(7)` subscribe overhead.
|
2017-07-20 15:08:06 +00:00
|
|
|
|
2017-07-20 15:37:31 +00:00
|
|
|
Machinarium IO contexts can be transferred between threads, which allows to develop efficient
|
2017-07-20 15:16:00 +00:00
|
|
|
producer-consumer network applications.
|
2017-07-20 15:08:06 +00:00
|
|
|
|
2017-07-24 13:09:39 +00:00
|
|
|
#### Full-featured SSL/TLS support
|
|
|
|
|
|
|
|
Machinarium has easy-to-use Transport Layer Security (TLS) API methods.
|
|
|
|
|
|
|
|
Create Machinarium TLS object, associate it with any existing IO context and the connection
|
|
|
|
will be automatically upgraded.
|
|
|
|
|
2017-07-20 15:08:06 +00:00
|
|
|
#### DNS resolving
|
|
|
|
|
|
|
|
Machinarium implements separate thread-pool to run network address
|
|
|
|
and service translation functions such as `getaddrinfo()`, to avoid process blocking and to be
|
|
|
|
consistent with coroutine design.
|
|
|
|
|
2017-07-24 12:59:59 +00:00
|
|
|
#### Timeouts and Cancellation
|
2017-07-20 15:08:06 +00:00
|
|
|
|
2017-07-24 12:59:59 +00:00
|
|
|
All blocking Machinarium API methods are designed with timeout flag. If operation does not
|
|
|
|
complete during requested time interval, then method will return with appropriate `errno` status set.
|
2017-07-20 15:08:06 +00:00
|
|
|
|
2017-07-24 12:59:59 +00:00
|
|
|
Additionally, a coroutine can `Cancel` any on-going blocking call of some other coroutine. And as in
|
|
|
|
timeout handling, cancelled coroutine method will return with appropriate status.
|