Loading...
Searching...
No Matches
MqContextC_SlaveApi_C_API

MqContextC - create and manage a slave context … More...

+ Collaboration diagram for MqContextC_SlaveApi_C_API:

Functions

MQ_EXTERN enum MkErrorE MqSlaveWorker_RT (MK_RT const mkrt, MQ_CTX const ctx, MQ_SLAVE_ID const id, MK_STRN fct, MK_BAC args)
 create a master/slave link using the image of the ctx object self. …
 
MQ_EXTERN enum MkErrorE MqSlaveCreate_RT (MK_RT const mkrt, MQ_CTX const ctx, MQ_SLAVE_ID const id, MQ_CTX const slave)
 create a master/slave link between the master-parent-context and the slave-parent-context …
 
MQ_EXTERN enum MkErrorE MqSlaveDelete_RT (MK_RT const mkrt, MQ_CTX const ctx, MQ_SLAVE_ID const id)
 Delete a slave object from a master/slave link identified by id. …
 
bool MqSlaveCheck (MQ_CTXN const ctx, MQ_SLAVE_ID const id)
 check if slave-id is valid
 
MQ_EXTERN enum MkErrorE MqSlaveGet_RT (MK_RT const mkrt, MQ_CTX const ctx, MQ_SLAVE_ID const id, MQ_CTX *ctx_out)
 get the slave-context from a master-context
 
MQ_EXTERN enum MkErrorE MqSlaveGetProxy_RT (MK_RT const mkrt, MQ_CTX const ctx, MQ_SLAVE_ID const id, MQ_CTX *ctx_out)
 on slave return the master and on master return the slave identified by id.
 
MQ_EXTERN enum MkErrorE MqSlaveGetFilter_RT (MK_RT const mkrt, MQ_CTX const ctx, MQ_CTX *ctx_out)
 get the filter-ctx or the master-ctx
 
MQ_CTX MqSlaveGetMaster (MQ_CTX const ctx)
 opposite function of MqSlaveGetFilter
 
bool MqSlaveIs (MQ_CTXN const ctx)
 is the context a slave-context ? …
 

MqContextC - MqContextC_SlaveApi_Slave_C_API - function

MQ_CTX MqSlaveGetMasterP (MQ_CTX const ctx)
 Non-inline replacement for MqSlaveGetMaster
 
MK_BOOL MqSlaveCheckP (MQ_CTXN const ctx, MQ_SLAVE_ID const id)
 Non-inline replacement for MqSlaveCheck
 
MK_BOOL MqSlaveIsP (MQ_CTXN const ctx)
 Non-inline replacement for MqSlaveIs
 

MqContextC - MqContextC_SlaveApi_Slave_C_API - overload

#define MqSlaveGet_NULL(...)
 
#define MqSlaveGet(...)
 
#define MqSlaveGet_E(...)
 
#define MqSlaveGet_C(...)
 
#define MqSlaveGet_e(...)
 
#define MqSlaveGetFilter_NULL(...)
 
#define MqSlaveGetFilter(...)
 
#define MqSlaveGetFilter_E(...)
 
#define MqSlaveGetFilter_C(...)
 
#define MqSlaveGetFilter_e(...)
 
#define MqSlaveGetProxy_NULL(...)
 
#define MqSlaveGetProxy(...)
 
#define MqSlaveGetProxy_E(...)
 
#define MqSlaveGetProxy_C(...)
 
#define MqSlaveGetProxy_e(...)
 
#define MqSlaveCreate_NULL(...)
 
#define MqSlaveCreate(...)
 
#define MqSlaveCreate_E(...)
 
#define MqSlaveCreate_C(...)
 
#define MqSlaveDelete_NULL(...)
 
#define MqSlaveDelete(...)
 
#define MqSlaveDelete_E(...)
 
#define MqSlaveDelete_C(...)
 
#define MqSlaveWorker_NULL(...)
 
#define MqSlaveWorker(...)
 
#define MqSlaveWorker_3(ctx, id, fct)
 
#define MqSlaveWorker_2(ctx, id)
 
#define MqSlaveWorker_E(...)
 
#define MqSlaveWorker_C(...)
 

Detailed Description

MqContextC - create and manage a slave context …

The master-slave-link is used to create a mesh of nodes defined by different parent-context. The master control the slave.

The master-slave-link is used to perform the following tasks:

In difference to the client-server-link the master-slave-link connect two independent parent-context in the same process or thread (e.g. node). This leads to the restriction that only the master-context can be a server-context because only one server-context per node is possible.

   node-0   |           node-1/2        |   node-3/4/5
===================================================================

| <- client/server link -> | <- client/server link -> |

             | <-- master/slave link --> |

                           |- client1-0 -|- server3 ...
             |-  server1  -|
             |             |- client1-1 -|- server4 ...
  client0-0 -|
             |-  server2  -|- client1-2 -|- server5 ...

Definition of the "master-context"

Definition of the "slave-context"

Definition of the "worker-context"

Definition of the "slave-id"

Definition of the "LOOPBACK" (0) slave

Performance analyse

The performance-test is created with:
  • pipe
    • Nhi1Exec perfclient.c --parent --wrk ? @ perfserver.c
  • spawn, fork, thread
    • Nhi1Exec -r=uds perfserver.c --spawn|fork|thread
    • Nhi1Exec -r=uds perfclient.c --parent --wrk ?
  • the number of workers are set with the –wrk option
  • the cpu is a xeon with 4/8
  • the performance is calculated as worker-context-created / time-in-sec with a ~2sec (default) measurement period.
performance-test code:
  • The test-setup is done as:
      perfclient                                worker                            perfserver
      ==========                                ======                            ==========
      |
      |- loop --wrk x
        |- MqSlaveWorker(...)               ->  worker[1] 
        |- MqSend(worker[1],"E","STR0..")   ->  PerfWorker_I160(...)
                                                |- loop endless
                                                  |- MqContextCreate(...)
                                                  |- MqLinkCreate(...)      <->   MqContextCreate(...)
                                                  |- MqContextDelete(...)   <->   MqContextDelete(...)
      |- sleep x sec
      |- loop --wrk x
        |- MqSend(worker[1],"C"..,"END0")   ->  PerfWorker_END0(...)
        |                                       |- stop loop
        |- "callback" - add number to all   <-  |- return #context 
performance-test results:
  • results generated using the debug environment
    setup –wrk # worker-context performance info
    pipe 1 2500 1000 the pipe start a new worker-context with spawn
    spawn 1 2500 <1000 same as pipe but use network-protocoll
    fork 1 3800 4000 the fork is faster than spawn
    thread 1 16500 9000 the thread is faster than fork
    pipe 4 8000 4500 the worker scale linear up to number of processors
    spawn 4 7600 <4500 -
    fork 4 23200 11500 -
    thread 4 55500 27500 -
    pipe 8 10000 5500 the additional scaling up to the max hyper-threading does not really help
    spawn 8 9100 <5500 -
    fork 8 23200 11500 -
    thread 8 55500 27500 -

Macro Definition Documentation

◆ MqSlaveCreate

#define MqSlaveCreate ( ...)
Value:
#define MK_RT_CALL
MQ_EXTERN enum MkErrorE MqSlaveCreate_RT(MK_RT const mkrt, MQ_CTX const ctx, MQ_SLAVE_ID const id, MQ_CTX const slave)
create a master/slave link between the master-parent-context and the slave-parent-context …

Definition at line 771 of file msgque_overload_mq.h.

◆ MqSlaveCreate_C

#define MqSlaveCreate_C ( ...)
Value:
if (MkErrorCheckI(MqSlaveCreate(__VA_ARGS__)))
#define MqSlaveCreate(...)

Definition at line 773 of file msgque_overload_mq.h.

◆ MqSlaveCreate_E

#define MqSlaveCreate_E ( ...)
Value:
MkErrorCheck(MqSlaveCreate(__VA_ARGS__))

Definition at line 772 of file msgque_overload_mq.h.

◆ MqSlaveCreate_NULL

#define MqSlaveCreate_NULL ( ...)
Value:
#define MK_RT_CALL_NULL

Definition at line 770 of file msgque_overload_mq.h.

◆ MqSlaveDelete

#define MqSlaveDelete ( ...)
Value:
MQ_EXTERN enum MkErrorE MqSlaveDelete_RT(MK_RT const mkrt, MQ_CTX const ctx, MQ_SLAVE_ID const id)
Delete a slave object from a master/slave link identified by id. …

Definition at line 775 of file msgque_overload_mq.h.

◆ MqSlaveDelete_C

#define MqSlaveDelete_C ( ...)
Value:
if (MkErrorCheckI(MqSlaveDelete(__VA_ARGS__)))
#define MqSlaveDelete(...)

Definition at line 777 of file msgque_overload_mq.h.

◆ MqSlaveDelete_E

#define MqSlaveDelete_E ( ...)
Value:
MkErrorCheck(MqSlaveDelete(__VA_ARGS__))

Definition at line 776 of file msgque_overload_mq.h.

◆ MqSlaveDelete_NULL

#define MqSlaveDelete_NULL ( ...)
Value:

Definition at line 774 of file msgque_overload_mq.h.

◆ MqSlaveGet

#define MqSlaveGet ( ...)
Value:
MQ_EXTERN enum MkErrorE MqSlaveGet_RT(MK_RT const mkrt, MQ_CTX const ctx, MQ_SLAVE_ID const id, MQ_CTX *ctx_out)
get the slave-context from a master-context …

Definition at line 754 of file msgque_overload_mq.h.

◆ MqSlaveGet_C

#define MqSlaveGet_C ( ...)
Value:
if (MkErrorCheckI(MqSlaveGet(__VA_ARGS__)))
#define MqSlaveGet(...)

Definition at line 756 of file msgque_overload_mq.h.

◆ MqSlaveGet_E

#define MqSlaveGet_E ( ...)
Value:
MkErrorCheck(MqSlaveGet(__VA_ARGS__))

Definition at line 755 of file msgque_overload_mq.h.

◆ MqSlaveGet_e

#define MqSlaveGet_e ( ...)
Value:
#define MK_EMBEDDED(type, call,...)
PUBLIC data structure for the pymqmsgque-specific-data

Definition at line 757 of file msgque_overload_mq.h.

◆ MqSlaveGet_NULL

#define MqSlaveGet_NULL ( ...)
Value:

Definition at line 753 of file msgque_overload_mq.h.

◆ MqSlaveGetFilter

#define MqSlaveGetFilter ( ...)
Value:
MQ_EXTERN enum MkErrorE MqSlaveGetFilter_RT(MK_RT const mkrt, MQ_CTX const ctx, MQ_CTX *ctx_out)
get the filter-ctx or the master-ctx …

Definition at line 759 of file msgque_overload_mq.h.

◆ MqSlaveGetFilter_C

#define MqSlaveGetFilter_C ( ...)
Value:
if (MkErrorCheckI(MqSlaveGetFilter(__VA_ARGS__)))
#define MqSlaveGetFilter(...)

Definition at line 761 of file msgque_overload_mq.h.

◆ MqSlaveGetFilter_E

#define MqSlaveGetFilter_E ( ...)
Value:
MkErrorCheck(MqSlaveGetFilter(__VA_ARGS__))

Definition at line 760 of file msgque_overload_mq.h.

◆ MqSlaveGetFilter_e

#define MqSlaveGetFilter_e ( ...)
Value:

Definition at line 762 of file msgque_overload_mq.h.

◆ MqSlaveGetFilter_NULL

#define MqSlaveGetFilter_NULL ( ...)
Value:

Definition at line 758 of file msgque_overload_mq.h.

◆ MqSlaveGetProxy

#define MqSlaveGetProxy ( ...)
Value:
MQ_EXTERN enum MkErrorE MqSlaveGetProxy_RT(MK_RT const mkrt, MQ_CTX const ctx, MQ_SLAVE_ID const id, MQ_CTX *ctx_out)
on slave return the master and on master return the slave identified by id.

Definition at line 764 of file msgque_overload_mq.h.

◆ MqSlaveGetProxy_C

#define MqSlaveGetProxy_C ( ...)
Value:
if (MkErrorCheckI(MqSlaveGetProxy(__VA_ARGS__)))
#define MqSlaveGetProxy(...)

Definition at line 766 of file msgque_overload_mq.h.

◆ MqSlaveGetProxy_E

#define MqSlaveGetProxy_E ( ...)
Value:
MkErrorCheck(MqSlaveGetProxy(__VA_ARGS__))

Definition at line 765 of file msgque_overload_mq.h.

◆ MqSlaveGetProxy_e

#define MqSlaveGetProxy_e ( ...)
Value:

Definition at line 767 of file msgque_overload_mq.h.

◆ MqSlaveGetProxy_NULL

#define MqSlaveGetProxy_NULL ( ...)
Value:

Definition at line 763 of file msgque_overload_mq.h.

◆ MqSlaveWorker

#define MqSlaveWorker ( ...)
Value:
MQ_EXTERN enum MkErrorE MqSlaveWorker_RT(MK_RT const mkrt, MQ_CTX const ctx, MQ_SLAVE_ID const id, MK_STRN fct, MK_BAC args)
create a master/slave link using the image of the ctx object self. …

Definition at line 779 of file msgque_overload_mq.h.

◆ MqSlaveWorker_2

#define MqSlaveWorker_2 ( ctx,
id )
Value:
MqSlaveWorker(ctx,id,"WORKER",NULL)
#define MqSlaveWorker(...)

Definition at line 781 of file msgque_overload_mq.h.

◆ MqSlaveWorker_3

#define MqSlaveWorker_3 ( ctx,
id,
fct )
Value:
MqSlaveWorker(ctx,id,fct,NULL)

Definition at line 780 of file msgque_overload_mq.h.

◆ MqSlaveWorker_C

#define MqSlaveWorker_C ( ...)
Value:
if (MkErrorCheckI(MqSlaveWorker(__VA_ARGS__)))

Definition at line 783 of file msgque_overload_mq.h.

◆ MqSlaveWorker_E

#define MqSlaveWorker_E ( ...)
Value:
MkErrorCheck(MqSlaveWorker(__VA_ARGS__))

Definition at line 782 of file msgque_overload_mq.h.

◆ MqSlaveWorker_NULL

#define MqSlaveWorker_NULL ( ...)
Value:

Definition at line 778 of file msgque_overload_mq.h.

Function Documentation

◆ MqSlaveCheck()

bool MqSlaveCheck ( MQ_CTXN const ctx,
MQ_SLAVE_ID const id )
inline

check if slave-id is valid

Parameters
[in]ctxthe master-context as PARENT or CHILD
[in]idthe SlaveId to unique identify the master/slave link, the id < MQ_SLAVE_USER is internal.
Returns
boolean true = valid or false = invalid

Definition at line 7698 of file LibMqMsgque_mq.h.

7699{
7700 return ctx ? id >= 0 && id < ctx->link.slave.used && ctx->link.slave.slaves[id] != NULL : false;
7701}
+ Here is the caller graph for this function:

◆ MqSlaveCheckP()

MK_BOOL MqSlaveCheckP ( MQ_CTXN const ctx,
MQ_SLAVE_ID const id )
extern

Non-inline replacement for MqSlaveCheck

◆ MqSlaveCreate_RT()

MQ_EXTERN enum MkErrorE MqSlaveCreate_RT ( MK_RT const mkrt,
MQ_CTX const ctx,
MQ_SLAVE_ID const id,
MQ_CTX const slave )

create a master/slave link between the master-parent-context and the slave-parent-context …

The slave-context have to be a sub-class of MqContextC and is owned by the master-context. Owned mean that no other external references should be used.
The slave-context will be deleted if the master-context is deleted and the slave-context will create a child-context if the master-context create a child context.

Example from server.cs with reflection support... only the class is required :

Client clt = new Client();
clt.LinkCreate(ConfigGetStartAs());
SlaveCreate (id, clt);

Example from server.cc without reflection support... the factory is required :

MqFactoryCT<Client>::Add("client");

and the factory is used to create the object :

Client *clt = MqFactoryCT<Client>::Get("client")->New();
clt->LinkCreate(ConfigGetStartAs());
SlaveCreate (id, clt);
Parameters
[in]mkrtthe MkRuntimeS instance to work on - the runtime argument, used by MK_RT_CALL (C-only)
[in]ctxthe master context object as PARENT without a CHILD
[in]idthe SlaveId to unique identify the master/slave link, the id < MQ_SLAVE_USER is internal.
[in]slavethe slave context object as CLIENT-PARENT without a CHILD
Exceptions
MkExceptionC→ The default-exception from the Programming-Language-Micro-Kernel (PLMK)
See also
MqSlaveGet

◆ MqSlaveDelete_RT()

MQ_EXTERN enum MkErrorE MqSlaveDelete_RT ( MK_RT const mkrt,
MQ_CTX const ctx,
MQ_SLAVE_ID const id )

Delete a slave object from a master/slave link identified by id. …

By default the slave-context object will be deleted if the master-context is deleted. Use this function to delete the parent-slave-context explicit and brake the master/slave link. If id is invalid nothing will happen. It is an error to delete a child-slave-context.

Parameters
[in]mkrtthe MkRuntimeS instance to work on - the runtime argument, used by MK_RT_CALL (C-only)
[in]ctxthe master context object as PARENT without a CHILD
[in]idthe SlaveId to unique identify the master/slave link, the id < MQ_SLAVE_USER is internal.
Exceptions
MkExceptionC→ The default-exception from the Programming-Language-Micro-Kernel (PLMK)
Attention
it is still possible to delete a child-slave-context using MqLinkDelete but this will break the internal master/slave order.

◆ MqSlaveGet_RT()

MQ_EXTERN enum MkErrorE MqSlaveGet_RT ( MK_RT const mkrt,
MQ_CTX const ctx,
MQ_SLAVE_ID const id,
MQ_CTX * ctx_out )

get the slave-context from a master-context

Parameters
[in]mkrtthe MkRuntimeS instance to work on - the runtime argument, used by MK_RT_CALL (C-only)
[in]ctxthe master-context as PARENT or CHILD
[in]idthe SlaveId to unique identify the master/slave link, the id < MQ_SLAVE_USER is internal.
[out]ctx_outthe slave-context or None on error
Exceptions
MkExceptionC→ The default-exception from the Programming-Language-Micro-Kernel (PLMK)
Attention
an error is raised if id is not valid or ctx is not a master-context.

◆ MqSlaveGetFilter_RT()

MQ_EXTERN enum MkErrorE MqSlaveGetFilter_RT ( MK_RT const mkrt,
MQ_CTX const ctx,
MQ_CTX * ctx_out )

get the filter-ctx or the master-ctx

The functions MqSlaveGetFilter, MqSlaveGetMaster and MqSlaveGetProxy have the same purpose. A filter-pipeline has two ctx, one on the left and one on the right. The left-ctx is linked with the master-ctx and the right-ctx is linked to the slave-ctx. This function return the ctx wanted or an error if NOT available. The search is done using the following order:

  1. return ctx if ctx is the wanted ctx
  2. return master-ctx or filter-ctx
  3. return a "context not available" error
Parameters
[in]mkrtthe MkRuntimeS instance to work on - the runtime argument, used by MK_RT_CALL (C-only)
[in]ctxthe MqContextS instance to work on
[out]ctx_outthe ctx or None on error
Exceptions
MkExceptionC→ The default-exception from the Programming-Language-Micro-Kernel (PLMK)

◆ MqSlaveGetMaster()

MQ_CTX MqSlaveGetMaster ( MQ_CTX const ctx)
inline

opposite function of MqSlaveGetFilter

Attention
if no master is available, a None is returned

Definition at line 7761 of file LibMqMsgque_mq.h.

7762{
7763 return ctx ? (MQ_IS_MASTER(ctx) ? ctx : ctx->config.master) : NULL;
7764}
#define MQ_IS_MASTER(ctx)
+ Here is the caller graph for this function:

◆ MqSlaveGetMasterP()

MQ_CTX MqSlaveGetMasterP ( MQ_CTX const ctx)
extern

Non-inline replacement for MqSlaveGetMaster

◆ MqSlaveGetProxy_RT()

MQ_EXTERN enum MkErrorE MqSlaveGetProxy_RT ( MK_RT const mkrt,
MQ_CTX const ctx,
MQ_SLAVE_ID const id,
MQ_CTX * ctx_out )

on slave return the master and on master return the slave identified by id.

Parameters
[in]mkrtthe MkRuntimeS instance to work on - the runtime argument, used by MK_RT_CALL (C-only)
[in]ctxthe master or slave-context as PARENT or CHILD
[in]idthe SlaveId to unique identify the master/slave link, the id < MQ_SLAVE_USER is internal.
[out]ctx_outthe other-context or None on error
Exceptions
MkExceptionC→ The default-exception from the Programming-Language-Micro-Kernel (PLMK)
Attention
an error is raised if id is not valid

◆ MqSlaveIs()

bool MqSlaveIs ( MQ_CTXN const ctx)
inline

is the context a slave-context ? …

Parameters
[in]ctxthe MqContextS instance to work on
Returns
a boolean value, True or False

Definition at line 7770 of file LibMqMsgque_mq.h.

7771{
7772 return ctx ? (ctx->config.master != NULL) : false;
7773}
+ Here is the caller graph for this function:

◆ MqSlaveIsP()

MK_BOOL MqSlaveIsP ( MQ_CTXN const ctx)
extern

Non-inline replacement for MqSlaveIs

◆ MqSlaveWorker_RT()

MQ_EXTERN enum MkErrorE MqSlaveWorker_RT ( MK_RT const mkrt,
MQ_CTX const ctx,
MQ_SLAVE_ID const id,
MK_STRN fct,
MK_BAC args )

create a master/slave link using the image of the ctx object self. …

The slave-context is started as an independent process or thread based on the StartAs argument.

The start of a "worker" can be done at:

  • context-creation in the Factory or the class-constructor
  • link-creation in the IServerSetup method
  • service-call in the client-service-request (starting worker one-the-fly)

Example from server.py create a worker in a service-callback reading arguments from the service

self.SlaveWorker(id, None, self.ReadALL().AppendLA("--name", "wk-cl-" + str(id), "@", "--name", "wk-sv-" + str(id)))
Parameters
[in]mkrtthe MkRuntimeS instance to work on - the runtime argument, used by MK_RT_CALL (C-only)
[in]ctxthe master context object as PARENT without a CHILD
[in]idthe SlaveId to unique identify the master/slave link, the id < MQ_SLAVE_USER is internal.
[in]fctthe MqFactoryS::originalIdent or None or '\0' or "WORKER".
if ident is None or '\0' or WORKER the factory of ctx will be used
if ident is MqFactoryS::originalIdent the factory defined will be used
[in]argscommand-line arguments passed to the worker-client or the worker-server. all arguments prior the first @ token are added to the worker-client and the other arguments to the worker-server.
example: --debug 5 --name hello @ --name myserver
Exceptions
MkExceptionC→ The default-exception from the Programming-Language-Micro-Kernel (PLMK)
Attention
- A slave-worker can only be created in a parent-context.