libmqmsgque 9.0
Loading...
Searching...
No Matches
Example: perfserver

Documentation of the perfserver tool used for example.test.

INTRODUCTION

The perfserver tool is used server-part of the performance-test

To perform the test the perfclient send various service request to the perfserver. The perfclient is written in C and finally create a report.

All context created, are connected using the libmqmsgque protocoll and build together a flat-like structure.

The GOAL for this setup is:

CODE server

/**
 *   @file         example/c/perfserver.c
 *   @brief        perfserver.c - 03 May 2023 - aotto1968
 *   @copyright    (C) NHI - #1 - Project - Group
 *                 This software has NO permissions to copy,
 *                 please contact AUTHOR for additional information
 *   @version      1c3a8f89f6bbd5c146252125f8a426400f6e1300
 *   @date         Wed May 3 12:28:13 2023 +0200
 *   @author       aotto1968 <aotto1968@t-online.de>
 */

/* VAR-START */

#define NHI1_FILE_NAME "perfserver.c"

/* VAR-END */

#include "common.h"

static enum MkErrorE
Ot_ECOU ( MQ_CALLBACK_SERVICE_CALL_ARGS ) {
  MqSendSTART_E (mqctx);
  MqSendU_E (mqctx, MqReadU_e(mqctx));
error:
  return MqSendRETURN (mqctx);
}

static enum MkErrorE
Ot_ECOI ( MQ_CALLBACK_SERVICE_CALL_ARGS ) {
  MqSendSTART_E (mqctx);
  MqSendI_E (mqctx, MqReadI_e(mqctx));
error:
  return MqSendRETURN (mqctx);
}

static enum MkErrorE
Ot_ECUL ( MQ_CALLBACK_SERVICE_CALL_ARGS )
{
  MqSendSTART_E (mqctx);

  MqSendY_E (mqctx, MqReadY_e (mqctx));
  MqSendS_E (mqctx, MqReadS_e (mqctx));
  MqSendI_E (mqctx, MqReadI_e (mqctx));
  MqSendD_E (mqctx, MqReadD_e (mqctx));
  MqSendU_E (mqctx, MqReadU_e (mqctx));

error:
  return MqSendRETURN (mqctx);
}

// [BufferStream-Create-TLS]
static enum MkErrorE
Ot_BUST ( MQ_CALLBACK_SERVICE_CALL_ARGS )
{
  MK_BUS bus = MkBufferStreamCreateTLS(0);

  while (MqReadItemExists(mqctx)) {
    MkBufferStreamWriteU(bus,MqReadU_e(mqctx));
  }

  MkBufferStreamPosToStart(bus);

  MqSendSTART_E (mqctx);
  while (MkBufferStreamReadItemExists(bus)) {
    MqSendU_E (mqctx, MkBufferStreamReadU_e (bus));
  }

error:
  return MqSendRETURN (mqctx);
}
// [BufferStream-Create-TLS]

// [BufferList-Create-TLS]
static enum MkErrorE
Ot_BFLT ( MQ_CALLBACK_SERVICE_CALL_ARGS )
{
  MK_BFL bfl = MkBufferListCreateTLS(0);

  while (MqReadItemExists(mqctx)) {
    MkBufferListAppendU(bfl,MqReadU_e(mqctx));
  }

  MqSendSTART_E (mqctx);
  for (int i=0; i<bfl->cursize; i++) {
    MqSendU_E (mqctx, MkBufferListIndexGet_e (bfl,i));
  }

error:
  return MqSendRETURN (mqctx);
}
// [BufferList-Create-TLS]

static enum MkErrorE
Ot_RDUL ( MQ_CALLBACK_SERVICE_CALL_ARGS ) {
  MqReadY_e (mqctx);
  MqReadS_e (mqctx);
  MqReadI_e (mqctx);
  MqReadD_e (mqctx);
  MqReadU_e (mqctx);

error:
  return MK_OK;
}

static enum MkErrorE
Ot_RDUC ( MQ_CALLBACK_SERVICE_CALL_ARGS ) {
  MqReadC_e (mqctx);
  MqReadC_e (mqctx);
  MqReadC_e (mqctx);
  MqReadC_e (mqctx);
  MqReadC_e (mqctx);

error:
  return MK_OK;
}

static enum MkErrorE Ot_STDB ( MQ_CALLBACK_SERVICE_CALL_ARGS ) {
  MqSendSTART_E (mqctx);
  MqStorageOpen_E (mqctx, MqReadC_e (mqctx));
error:
  return MqSendRETURN (mqctx);
}
static enum MkErrorE Ot_STDC ( MQ_CALLBACK_SERVICE_CALL_ARGS )
{
  MqSendSTART_E (mqctx);
  MqStorageClose_E (mqctx);
error:
  return MqSendRETURN (mqctx);
}

static enum MkErrorE
Ot_BINT ( MQ_CALLBACK_SERVICE_CALL_ARGS ) {
  MkBinaryR bin = {0};
  MqReadB_E (mqctx, &bin);
error:
  return MK_OK;
}

static enum MkErrorE
Ot_STRT ( MQ_CALLBACK_SERVICE_CALL_ARGS ) {
  MK_STRN str = NULL;
  MqReadC_E (mqctx, &str);
error:
  return MK_OK;
}


// define a service as link between the token "HLWO" and the callback "MyFirstService"
static enum MkErrorE ServerSetup ( MQ_CALLBACK_SERVICE_CALL_ARGS ) {
  MqServiceCreate_E(mqctx,"ECOU", Ot_ECOU, NULL, NULL, NULL);
  MqServiceCreate_E(mqctx,"ECOI", Ot_ECOI, NULL, NULL, NULL);
  MqServiceCreate_E(mqctx,"ECUL", Ot_ECUL, NULL, NULL, NULL);
  MqServiceCreate_E(mqctx,"RDUL", Ot_RDUL, NULL, NULL, NULL);
  MqServiceCreate_E(mqctx,"RDUC", Ot_RDUC, NULL, NULL, NULL);
  MqServiceCreate_E(mqctx,"STDB", Ot_STDB, NULL, NULL, NULL);
  MqServiceCreate_E(mqctx,"STDC", Ot_STDC, NULL, NULL, NULL);
  MqServiceCreate_E(mqctx,"BUST", Ot_BUST, NULL, NULL, NULL);
  MqServiceCreate_E(mqctx,"BFLT", Ot_BFLT, NULL, NULL, NULL);
  MqServiceCreate_E(mqctx,"BINT", Ot_BINT, NULL, NULL, NULL);
  MqServiceCreate_E(mqctx,"STRT", Ot_STRT, NULL, NULL, NULL);
error:
  return MqSendRETURN(mqctx);
}

enum MkErrorE
PerfServerFactory ( MQ_CALLBACK_FACTORY_CTOR_ARGS )
{ 
  MqContextSetup(NULL,tmpl,contextP);
  MqConfigSetServerSetup (*contextP, ServerSetup, NULL, NULL, NULL);
  return MK_OK;
}

int main (int argc, MK_STRN argv[]) 
{
  MqRtSetup_NULL;

  // setup commandline arguments for later use
  MK_BFL largv = MkBufferListCreateVC(argc, argv);
  struct MqContextS ctxS = {0}; 
  MQ_CTX ctx = &ctxS;

  // [factory-item]
  // create "PerfServer" factory… and make it to the default.
  MqFactoryDefault( MqFactoryAdd_2(PerfServerFactory, "perfserver"));
  // [factory-item]

  // inspect commandline-argument for the "factory" to choose… and create a object
  MkErrorCheck(MqFactoryNew (MqFactoryGetCalledL(largv), NULL, &ctx));

  // start listen for incoming call's
  MqLinkCreate_E (ctx, largv);
  MqCheckForLeftOverArguments_E (ctx, largv);
  MqProcessEvent_E (ctx,MQ_WAIT_FOREVER,MK_TIMEOUT_DEFAULT);
error:
  MkBufferListDelete(largv);
  MqExit_1(ctx);
}