MqContextC - create and manage a slave context … More...
Functions | |
native MqContextC | jvmqmsgque.MqContextC.SlaveGetMaster () |
Java: → C-API opposite function of MqSlaveGetFilter | |
native MqContextC | jvmqmsgque.MqContextC.SlaveGet (int id) |
Java: → C-API get the slave-context from a master-context … | |
native MqContextC | jvmqmsgque.MqContextC.SlaveGetFilter () |
Java: → C-API get the filter-ctx or the master-ctx … | |
native MqContextC | jvmqmsgque.MqContextC.SlaveGetProxy (int id) |
Java: → C-API on slave return the master and on master return the slave identified by id. | |
native boolean | jvmqmsgque.MqContextC.SlaveCheck (int id) |
Java: → C-API check if slave-id is valid | |
native void | jvmqmsgque.MqContextC.SlaveCreate (int id, MqContextC slave) |
Java: → C-API create a master/slave link between the master-parent-context and the slave-parent-context … | |
native void | jvmqmsgque.MqContextC.SlaveDelete (int id) |
Java: → C-API Delete a slave object from a master/slave link identified by id. … | |
native boolean | jvmqmsgque.MqContextC.SlaveIs () |
Java: → C-API is the context a slave-context ? … | |
native void | jvmqmsgque.MqContextC.SlaveWorker (int id, String fct, MkBufferListC args) |
Java: → C-API create a master/slave link using the image of the ctx object self. … | |
void | jvmqmsgque.MqContextC.SlaveWorker (int id, String fct, String... args) |
Java: → C-API create a master/slave link using the image of the ctx object self. … | |
void | jvmqmsgque.MqContextC.SlaveWorker (int id) |
Java: → C-API create a master/slave link using the image of the ctx object self. … | |
void | jvmqmsgque.MqContextC.SlaveWorker (int id, String fct) |
Java: → C-API create a master/slave link using the image of the ctx object self. … | |
JNIEXPORT jobject JNICALL | Java_jvmqmsgque_MqContextC_SlaveGetMaster (JNIEnv *env, jobject self) |
Java: → C-API opposite function of MqSlaveGetFilter | |
JNIEXPORT jobject JNICALL | Java_jvmqmsgque_MqContextC_SlaveGet (JNIEnv *env, jobject self, jint id) |
Java: → C-API get the slave-context from a master-context … | |
JNIEXPORT jobject JNICALL | Java_jvmqmsgque_MqContextC_SlaveGetFilter (JNIEnv *env, jobject self) |
Java: → C-API get the filter-ctx or the master-ctx … | |
JNIEXPORT jobject JNICALL | Java_jvmqmsgque_MqContextC_SlaveGetProxy (JNIEnv *env, jobject self, jint id) |
Java: → C-API on slave return the master and on master return the slave identified by id. | |
JNIEXPORT jboolean JNICALL | Java_jvmqmsgque_MqContextC_SlaveCheck (JNIEnv *env, jobject self, jint id) |
Java: → C-API check if slave-id is valid | |
JNIEXPORT void JNICALL | Java_jvmqmsgque_MqContextC_SlaveCreate (JNIEnv *env, jobject self, jint id, jobject slave) |
Java: → C-API create a master/slave link between the master-parent-context and the slave-parent-context … | |
JNIEXPORT void JNICALL | Java_jvmqmsgque_MqContextC_SlaveDelete (JNIEnv *env, jobject self, jint id) |
Java: → C-API Delete a slave object from a master/slave link identified by id. … | |
JNIEXPORT jboolean JNICALL | Java_jvmqmsgque_MqContextC_SlaveIs (JNIEnv *env, jobject self) |
Java: → C-API is the context a slave-context ? … | |
JNIEXPORT void JNICALL | Java_jvmqmsgque_MqContextC_SlaveWorker (JNIEnv *env, jobject self, jint id, jstring fct, jobject args) |
Java: → C-API create a master/slave link using the image of the ctx object self. … | |
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"
0
.Definition of the "worker-context"
0
./etc/services
0
slave-id | value | definition |
---|---|---|
MQ_SLAVE_MAX | 1024 | internal: the maximum slave-id … . |
MQ_SLAVE_USER | 10 | internal: start of user-defined-slave-id . |
MQ_SLAVE_LOOPBACK | 0 | internal: the loopback-slave-id, (call my own services) . |
MQ_SLAVE_FILTER | 1 | internal: the filter-slave-id, (on a master get the filter-slave) . |
MQ_SLAVE_MASTER | 1 | internal: the master-slave-id, (on a slave get the master) . |
MQ_SLAVE_OTHER | 1 | internal: on the master-ctx get the slave-ctx and on the slave-ctx get the master-ctx . |
range | definition |
---|---|
0 <= slave-id < MQ_SLAVE_MAX | range of valid slave-id's |
0 <= slave-id < MQ_SLAVE_USER | internale usage |
MQ_SLAVE_USER <= slave-id < MQ_SLAVE_MAX | external usage |
Definition of the "LOOPBACK" (0) slave
client | server | =========================================== | <--- client/server ---> | <-- loop --> | | <------ master/slave -----> | client -- | -- server -- | -- client -- # == == # server -- | -- client -- #
slave-id = 0
. MyLoopServer.java
→ create a new loop-server package example; import jvmqmsgque.*; import jvmkkernel.*; // package-item final class MyLoopServer extends MqContextC implements MqServerSetupIF { // set the "mydata" attribute to the master-context String mydata = "Hello World"; // Factory Constructor public MyLoopServer(MqContextC tmpl) { super(tmpl); } // service to serve all EXTERNAL requests for token "HLWO" class HLWO_srv implements MqServiceIF { public void Callback(MqContextC ctx) { // get the "loopback" context MqContextC loop = SlaveGet(MqSlaveE.LOOPBACK.get()); // call the LOOP service on the SAME server loop.Send("W","LOOP"); // answer HLWO with string-return from LOOP Send("R", "C", loop.ReadSTR()); } } // service to serve all INTERNAL requests for token "LOOP" class LOOP_srv implements MqServiceIF { public void Callback(MqContextC ctx) { // get the "master" context MyLoopServer master = ((MyLoopServer)SlaveGetMaster()); // answer LOOP with data from MASTER->mydata attribute Send("R", "C", master.mydata); } } // define a service as link between the token "HLWO" and the class "MyFirstService" public void ServerSetup() { // EXTERNAL: link the "HLWO" service with the "HLWO_srv" ServiceCreate("HLWO", new HLWO_srv()); // INTERNAL: link the "LOOP" service with "LOOP_srv" SlaveGet(MqSlaveE.LOOPBACK.get()).ServiceCreate("LOOP", new LOOP_srv()); } // ------------------------------------------------------------- // package-main public static void main(String[] argv) { // create the "MyLoopServer" factory… and the instance MqContextC srv = MqFactoryC.Add(MyLoopServer.class).New(); try { srv.LinkCreate(argv); srv.ProcessEvent(MqWaitOnEventE.FOREVER); } catch (Throwable e) { srv.ErrorCatch(e); } srv.Exit(); } }
Performance analyse
Nhi1Exec perfclient.c --parent --wrk ? @ perfserver.c
Nhi1Exec -r=uds perfserver.c --spawn|fork|thread
Nhi1Exec -r=uds perfclient.c --parent --wrk ?
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
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 | - |
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"
0
.Definition of the "worker-context"
0
./etc/services
0
slave-id | value | definition |
---|---|---|
MQ_SLAVE_MAX | 1024 | internal: the maximum slave-id … . |
MQ_SLAVE_USER | 10 | internal: start of user-defined-slave-id . |
MQ_SLAVE_LOOPBACK | 0 | internal: the loopback-slave-id, (call my own services) . |
MQ_SLAVE_FILTER | 1 | internal: the filter-slave-id, (on a master get the filter-slave) . |
MQ_SLAVE_MASTER | 1 | internal: the master-slave-id, (on a slave get the master) . |
MQ_SLAVE_OTHER | 1 | internal: on the master-ctx get the slave-ctx and on the slave-ctx get the master-ctx . |
range | definition |
---|---|
0 <= slave-id < MQ_SLAVE_MAX | range of valid slave-id's |
0 <= slave-id < MQ_SLAVE_USER | internale usage |
MQ_SLAVE_USER <= slave-id < MQ_SLAVE_MAX | external usage |
Definition of the "LOOPBACK" (0) slave
client | server | =========================================== | <--- client/server ---> | <-- loop --> | | <------ master/slave -----> | client -- | -- server -- | -- client -- # == == # server -- | -- client -- #
slave-id = 0
. MyLoopServer.java
→ create a new loop-server package example; import jvmqmsgque.*; import jvmkkernel.*; // package-item final class MyLoopServer extends MqContextC implements MqServerSetupIF { // set the "mydata" attribute to the master-context String mydata = "Hello World"; // Factory Constructor public MyLoopServer(MqContextC tmpl) { super(tmpl); } // service to serve all EXTERNAL requests for token "HLWO" class HLWO_srv implements MqServiceIF { public void Callback(MqContextC ctx) { // get the "loopback" context MqContextC loop = SlaveGet(MqSlaveE.LOOPBACK.get()); // call the LOOP service on the SAME server loop.Send("W","LOOP"); // answer HLWO with string-return from LOOP Send("R", "C", loop.ReadSTR()); } } // service to serve all INTERNAL requests for token "LOOP" class LOOP_srv implements MqServiceIF { public void Callback(MqContextC ctx) { // get the "master" context MyLoopServer master = ((MyLoopServer)SlaveGetMaster()); // answer LOOP with data from MASTER->mydata attribute Send("R", "C", master.mydata); } } // define a service as link between the token "HLWO" and the class "MyFirstService" public void ServerSetup() { // EXTERNAL: link the "HLWO" service with the "HLWO_srv" ServiceCreate("HLWO", new HLWO_srv()); // INTERNAL: link the "LOOP" service with "LOOP_srv" SlaveGet(MqSlaveE.LOOPBACK.get()).ServiceCreate("LOOP", new LOOP_srv()); } // ------------------------------------------------------------- // package-main public static void main(String[] argv) { // create the "MyLoopServer" factory… and the instance MqContextC srv = MqFactoryC.Add(MyLoopServer.class).New(); try { srv.LinkCreate(argv); srv.ProcessEvent(MqWaitOnEventE.FOREVER); } catch (Throwable e) { srv.ErrorCatch(e); } srv.Exit(); } }
Performance analyse
Nhi1Exec perfclient.c --parent --wrk ? @ perfserver.c
Nhi1Exec -r=uds perfserver.c --spawn|fork|thread
Nhi1Exec -r=uds perfclient.c --parent --wrk ?
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
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 | - |
JNIEXPORT jboolean JNICALL Java_jvmqmsgque_MqContextC_SlaveCheck | ( | JNIEnv * | env, |
jobject | self, | ||
jint | id ) |
Java:
→ C-API boolean ctx.SlaveCheck(int id)
check if slave-id is valid
Definition at line 2434 of file MqContextC_jv.c.
JNIEXPORT void JNICALL Java_jvmqmsgque_MqContextC_SlaveCreate | ( | JNIEnv * | env, |
jobject | self, | ||
jint | id, | ||
jobject | slave ) |
Java:
→ C-API ctx.SlaveCreate(int id, MqContextC slave)
create a master/slave link between the master-parent-context and the slave-parent-context …
Definition at line 2446 of file MqContextC_jv.c.
JNIEXPORT void JNICALL Java_jvmqmsgque_MqContextC_SlaveDelete | ( | JNIEnv * | env, |
jobject | self, | ||
jint | id ) |
Java:
→ C-API ctx.SlaveDelete(int id)
Delete a slave object from a master/slave link identified by id. …
Definition at line 2459 of file MqContextC_jv.c.
JNIEXPORT jobject JNICALL Java_jvmqmsgque_MqContextC_SlaveGet | ( | JNIEnv * | env, |
jobject | self, | ||
jint | id ) |
Java:
→ C-API MqContextC ctx.SlaveGet(int id)
get the slave-context from a master-context …
Definition at line 2390 of file MqContextC_jv.c.
JNIEXPORT jobject JNICALL Java_jvmqmsgque_MqContextC_SlaveGetFilter | ( | JNIEnv * | env, |
jobject | self ) |
Java:
→ C-API MqContextC ctx.SlaveGetFilter()
get the filter-ctx or the master-ctx …
Definition at line 2404 of file MqContextC_jv.c.
JNIEXPORT jobject JNICALL Java_jvmqmsgque_MqContextC_SlaveGetMaster | ( | JNIEnv * | env, |
jobject | self ) |
Java:
→ C-API MqContextC ctx.SlaveGetMaster()
opposite function of MqSlaveGetFilter
Definition at line 2376 of file MqContextC_jv.c.
JNIEXPORT jobject JNICALL Java_jvmqmsgque_MqContextC_SlaveGetProxy | ( | JNIEnv * | env, |
jobject | self, | ||
jint | id ) |
Java:
→ C-API MqContextC ctx.SlaveGetProxy(int id)
on slave return the master and on master return the slave identified by id.
Definition at line 2418 of file MqContextC_jv.c.
JNIEXPORT jboolean JNICALL Java_jvmqmsgque_MqContextC_SlaveIs | ( | JNIEnv * | env, |
jobject | self ) |
Java:
→ C-API boolean ctx.SlaveIs()
is the context a slave-context ? …
Definition at line 2470 of file MqContextC_jv.c.
JNIEXPORT void JNICALL Java_jvmqmsgque_MqContextC_SlaveWorker | ( | JNIEnv * | env, |
jobject | self, | ||
jint | id, | ||
jstring | fct, | ||
jobject | args ) |
Java:
→ C-API ctx.SlaveWorker(int id, ?String fct = "WORKER"?, ?MkBufferListC args = null?)
create a master/slave link using the image of the ctx object self. …
Definition at line 2482 of file MqContextC_jv.c.
native boolean jvmqmsgque.MqContextC.SlaveCheck | ( | int | id | ) |
Java:
→ C-API boolean ctx.SlaveCheck(int id)
check if slave-id is valid
native void jvmqmsgque.MqContextC.SlaveCreate | ( | int | id, |
MqContextC | slave ) |
Java:
→ C-API ctx.SlaveCreate(int id, MqContextC slave)
create a master/slave link between the master-parent-context and the slave-parent-context …
native void jvmqmsgque.MqContextC.SlaveDelete | ( | int | id | ) |
Java:
→ C-API ctx.SlaveDelete(int id)
Delete a slave object from a master/slave link identified by id. …
native MqContextC jvmqmsgque.MqContextC.SlaveGet | ( | int | id | ) |
Java:
→ C-API MqContextC ctx.SlaveGet(int id)
get the slave-context from a master-context …
native MqContextC jvmqmsgque.MqContextC.SlaveGetFilter | ( | ) |
Java:
→ C-API MqContextC ctx.SlaveGetFilter()
get the filter-ctx or the master-ctx …
native MqContextC jvmqmsgque.MqContextC.SlaveGetMaster | ( | ) |
Java:
→ C-API MqContextC ctx.SlaveGetMaster()
opposite function of MqSlaveGetFilter
native MqContextC jvmqmsgque.MqContextC.SlaveGetProxy | ( | int | id | ) |
Java:
→ C-API MqContextC ctx.SlaveGetProxy(int id)
on slave return the master and on master return the slave identified by id.
native boolean jvmqmsgque.MqContextC.SlaveIs | ( | ) |
Java:
→ C-API boolean ctx.SlaveIs()
is the context a slave-context ? …
void jvmqmsgque.MqContextC.SlaveWorker | ( | int | id | ) |
Java:
→ C-API ctx.SlaveWorker(int id, ?String fct = "WORKER"?, ?MkBufferListC args = null?)
create a master/slave link using the image of the ctx object self. …
Definition at line 1066 of file MqContextC.java.
void jvmqmsgque.MqContextC.SlaveWorker | ( | int | id, |
String | fct ) |
Java:
→ C-API ctx.SlaveWorker(int id, ?String fct = "WORKER"?, ?MkBufferListC args = null?)
create a master/slave link using the image of the ctx object self. …
Definition at line 1071 of file MqContextC.java.
native void jvmqmsgque.MqContextC.SlaveWorker | ( | int | id, |
String | fct, | ||
MkBufferListC | args ) |
Java:
→ C-API ctx.SlaveWorker(int id, ?String fct = "WORKER"?, ?MkBufferListC args = null?)
create a master/slave link using the image of the ctx object self. …
void jvmqmsgque.MqContextC.SlaveWorker | ( | int | id, |
String | fct, | ||
String... | args ) |
Java:
→ C-API ctx.SlaveWorker(int id, ?String fct = "WORKER"?, ?MkBufferListC args = null?)
create a master/slave link using the image of the ctx object self. …
Definition at line 1061 of file MqContextC.java.