hmbdc
simplify-high-performance-messaging-programming
|
A Context is like a media object that facilitates the communications for the Clients that it is holding. a Client can only be added to (or started within) once to a single Context, undefined behavior otherwise. the communication model is determined by the context_property by default it is in the nature of broadcast fashion within local process indicating by broadcast<> More...
#include <Context.hpp>
Public Types | |
using | Base = context_detail::ThreadCommBase< MaxMessageSize, ContextProperties... > |
using | Buffer = typename Base::Buffer |
using | cpa = typename Base::cpa |
using | Pool = pattern::PoolT< Buffer > |
![]() | |
enum | |
using | cpa = context_property_aggregator< ContextProperties... > |
using | Buffer = typename cpa::Buffer |
using | Allocator = typename cpa::Allocator |
Public Member Functions | |
Context (uint32_t messageQueueSizePower2Num=MaxMessageSize?20:0, size_t maxPoolClientCount=MaxMessageSize?128:0, size_t maxMessageSizeRuntime=MaxMessageSize) | |
ctor for construct local non-ipc Context More... | |
Context (char const *ipcTransportName, uint32_t messageQueueSizePower2Num=MaxMessageSize?20:0, size_t maxPoolClientCount=MaxMessageSize?128:0, size_t maxMessageSizeRuntime=MaxMessageSize, uint64_t purgerCpuAffinityMask=0xfffffffffffffffful) | |
ctor for construct local ipc Context More... | |
~Context () | |
dtor More... | |
template<typename Client > | |
void | addToPool (Client &client, uint64_t poolThreadAffinityIn=0xfffffffffffffffful) |
add a client to Context's pool - the Client is run in pool mode More... | |
template<typename Client , typename... Args> | |
void | addToPool (Client &client, uint64_t poolThreadAffinityIn, Args &&...args) |
add a bunch of clients to Context's pool - the Clients are run in pool mode More... | |
size_t | clientCountInPool () const |
return the numebr of clients added into pool More... | |
size_t | parallelConsumerAlive () const |
how many parallel consummers are started More... | |
template<typename... Args> | |
void | start (uint16_t poolThreadCount, uint64_t poolThreadsCpuAffinityMask, Args &&...args) |
start the context and specify its Pool and direct Clients More... | |
template<typename Client , typename... Args> | |
std::enable_if<!std::is_integral< Client >::value, void >::type | start (Client &c, uint64_t cpuAffinity, Args &&...args) |
start the context (without its Pool) and direct Clients More... | |
void | start () |
tell hmbdc that there is no more direct mode Client to start | |
void | stop () |
stop the message dispatching - asynchronously More... | |
void | join () |
wait until all threads (Pool threads too if apply) of the Context exit More... | |
void | setSecondsBetweenPurge (uint32_t s) |
ipc_creator Context runs a StcuClientPurger to purge crashed (or slow, stuck ...) Clients from the ipc transport to make the ipc trasnport healthy (avoiding buffer full). It periodically looks for things to purge. This is to set the period (default is 60 seconds). More... | |
void | runPoolThreadOnce (uint16_t threadSerialNumber) |
normally not used until you want to run your own message loop More... | |
template<typename Client > | |
void | runClientThreadOnce (uint16_t threadSerialNumber, Client &c) |
normally not used until you want to run your own message loop More... | |
![]() | |
size_t | maxMessageSize () const |
enable_if<!std::is_integral< M1 >::value, void >::type | send (M0 &&m0, M1 &&m1, Messages &&...msgs) |
try send a batch of messages to the Context or attached ipc Contexts More... | |
void | send (ForwardIt begin, size_t n) |
send a range of messages to the Context or attached ipc Contexts More... | |
void | send (Message &&m) |
send a message to the Context or attached ipc Contexts More... | |
enable_if<!std::is_integral< M1 >::value, bool >::type | trySend (M0 &&m0, M1 &&m1, Messages &&...msgs) |
try to send a batch of message to the Context or attached ipc Contexts More... | |
bool | trySend (ForwardIt begin, size_t n) |
try send a range of messages to the Context or attached ipc Contexts More... | |
bool | trySend (Message &&m) |
try to send a message to the Context or attached ipc Contexts More... | |
void | sendInPlace (Args &&...args) |
send a message to all Clients in the Context or attached ipc Contexts More... | |
Buffer & | buffer () |
accessor - mostly used internally More... | |
Additional Inherited Members | |
![]() | |
ThreadCommBase (uint32_t messageQueueSizePower2Num, size_t maxMessageSizeRuntime=MAX_MESSAGE_SIZE, char const *shmName=nullptr) | |
![]() | |
static void | markDeadFrom (pattern::MonoLockFreeBuffer &buffer, uint16_t) |
static void | markDeadFrom (BroadCastBuf &buffer, uint16_t poolThreadCount) |
![]() | |
Allocator | allocator_ |
Buffer *HMBDC_RESTRICT | bufferptr_ |
Buffer &HMBDC_RESTRICT | buffer_ |
A Context is like a media object that facilitates the communications for the Clients that it is holding. a Client can only be added to (or started within) once to a single Context, undefined behavior otherwise. the communication model is determined by the context_property by default it is in the nature of broadcast fashion within local process indicating by broadcast<>
a broadcast Context contains a thread Pool powered by a number of OS threads. a Client running in such a Context can either run in the pool mode or a direct mode (which means the Client has its own dedicated OS thread) direct mode provides faster responses, and pool mode provides more flexibility. It is recommended that the total number of threads (pool threads + direct threads) not exceeding the number of avalibale cores.
MaxMessageSize | What is the max message size if known at compile time(compile time sized); if the value can only be determined at runtime (run time sized), set this to 0. Things can still work but will lost some compile time checking advantages, see maxMessageSizeRuntime below |
ContextProperties | see context_property namespace |
|
inline |
ctor for construct local non-ipc Context
won't compile if calling it for ipc Context
messageQueueSizePower2Num | value of 10 gives message queue if size of 1024 (messages, not bytes) |
maxPoolClientCount | up to how many Clients the pool is suppose to support, only used when pool supported in the Context with broadcast property |
maxMessageSizeRuntime | if MaxMessageSize set to 0, this value is used |
|
inline |
ctor for construct local ipc Context
won't compile if calling it for local non-ipc Context
ipcTransportName | the id to identify an ipc transport that supports a group of attached together Contexts and their Clients |
messageQueueSizePower2Num | value of 10 gives message queue if size of 1024 (messages, not bytes) |
maxPoolClientCount | up to how many Clients the pool is suppose to support, only used when pool supported in the Context with broadcast property |
maxMessageSizeRuntime | if MaxMessageSize set to 0, this value is used |
purgerCpuAffinityMask | which cores to run the low profile (sleep mostly) thread in charge of purging crashed Clients. Used only for ipc_creator Contexts. |
|
inline |
dtor
if this Context owns ipc transport, notify all attached processes that read from it that this tranport is dead
|
inline |
add a client to Context's pool - the Client is run in pool mode
if pool is already started, the client is to get current Messages immediatly
Client | client type |
client | to be added into the Pool |
poolThreadAffinityIn | pool is powered by a number of threads (thread in the pool is identified (by a number) in the mask starting from bit 0) it is possible to have a Client to use just some of the threads in the Pool |
default to use all.
|
inline |
add a bunch of clients to Context's pool - the Clients are run in pool mode
if pool is already started, the client is to get current Messages immediatly
Client | client type |
client | to be added into the Pool |
poolThreadAffinityIn | pool is powered by a number of threads (thread in the pool is identified (by a number) in the mask starting from bit 0) it is possible to have a Client to use just some of the threads in the Pool |
default to use all.
args | more client and poolThreadAffinityIn pairs can follow |
|
inline |
return the numebr of clients added into pool
the number could change since the clients could be added in another thread
|
inline |
wait until all threads (Pool threads too if apply) of the Context exit
blocking call
|
inline |
how many parallel consummers are started
the dynamic value could change after the call returns see max_parallel_consumer Context property
|
inline |
|
inline |
normally not used until you want to run your own message loop
call this function frequently to pump hmbdc message loop in its pool
threadSerialNumber | starting from 0, indicate which thread in the pool is powering the loop |
|
inline |
ipc_creator Context runs a StcuClientPurger to purge crashed (or slow, stuck ...) Clients from the ipc transport to make the ipc trasnport healthy (avoiding buffer full). It periodically looks for things to purge. This is to set the period (default is 60 seconds).
If some Client are known to take long to process messages, increase it. If you need to remove slow Clients quickly reduce it. Only effective for ipc_creator Context.
s | seconds |
|
inline |
start the context and specify its Pool and direct Clients
doesn't compile if the Context does not support a Pool. Usage example:
typename | ...Args types |
poolThreadCount | how many threads to power the Pool, 0 means no pool |
poolThreadsCpuAffinityMask | which cores, the pool threads to run on |
args | pairs of direct mode Client and its cpuAffinity; optionally followed by a bool as the last arg (default false), false to indicate there is no more direct mode Client to start. (the bool is not aplicable for IPC Context types) If a cpuAffinity is 0, the Client's affinity rotates to one of the cores in the system. |
see in example hmbdc.cpp
|
inline |
start the context (without its Pool) and direct Clients
for example
typename | ...Args types |
args | pairs of direct mode Client and its cpuAffinity; optionally followed by a bool as the last arg (default false), false to indicate there is no more direct mode Client to start. (the bool is not aplicable for IPC Context types) If a cpuAffinity is 0, the Client's affinity rotates to one of the cores in the system |
see in example server-cluster.cpp
|
inline |
stop the message dispatching - asynchronously
asynchronously means not garanteed message dispatching stops immidiately after this non-blocking call