ccmqmsgque 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 ccmqmsgque protocoll and build together a flat-like structure.

The GOAL for this setup is:

CODE server

/**
 *   @file         example/cc/perfserver.cc
 *   @brief        perfserver.cc - 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 */

#include  "debug_mq.h"
#include  "LibMqMsgque_cc.hh"

/* VAR-END */

using namespace ccmqmsgque;

class perfserver : public MqContextC, public IServerSetup {
  friend class MqFactoryCT<perfserver>;

  // define the factory constructor
  perfserver(MK_TYP const typ, MqContextC* tmpl=NULL) : MqContextC(typ, tmpl) {};

  private:
    void ECOU () { SendSTART(); SendU(ReadU()); SendRETURN(); }
    void ECOI () { SendSTART(); SendI(ReadI()); SendRETURN(); }

    void ECUL () {
      SendSTART();
      SendY(ReadY());
      SendS(ReadS());
      SendI(ReadI());
      SendD(ReadD());
      ProxyItem(this);
      SendRETURN();
    }

    // [BufferStream-Create-TLS]
    void BUST () {
      auto bus = MkBufferStreamC::CreateTLS(0);
      while (ReadItemExists()) {
        bus->WriteU(ReadU());
      }
      bus->PosToStart();
      SendSTART();
      while (bus->ReadItemExists()) {
        SendU(bus->ReadU());
      }
      SendRETURN();
    }
    // [BufferStream-Create-TLS]

    // [BufferList-Create-TLS]
    void BFLT () {
      auto bfl = MkBufferListC::CreateTLS(0);
      while (ReadItemExists()) {
        bfl->AppendU(ReadU());
      }
      SendSTART();
      for (MK_NUM i=0; i<bfl->Size(); ++i) {
        SendU(bfl->IndexGet(i));
      }
      SendRETURN();
    }
    // [BufferList-Create-TLS]

    void RDUL () {
      ReadY();
      ReadS();
      ReadI();
      ReadD();
      ReadU();
    }

    void RDUC () {
      ReadC();
      ReadC();
      ReadC();
      ReadC();
      ReadC();
    }

    void STDB () {
      SendSTART();
      StorageOpen(ReadC());
      SendRETURN();
    }

    void STDC () {
      SendSTART();
      StorageClose();
      SendRETURN();
    }

    void BINT () {
      ReadB();
    }

    void STRT () {
      ReadC();
    }

    // define a service as link between the token "HLWO" and the callback "MyFirstService"
    void ServerSetup() {
      ServiceCreate("ECOU", CallbackF(&perfserver::ECOU));
      ServiceCreate("ECOI", CallbackF(&perfserver::ECOI));
      ServiceCreate("ECUL", CallbackF(&perfserver::ECUL));
      ServiceCreate("RDUL", CallbackF(&perfserver::RDUL));
      ServiceCreate("RDUC", CallbackF(&perfserver::RDUC));
      ServiceCreate("STDB", CallbackF(&perfserver::STDB));
      ServiceCreate("STDC", CallbackF(&perfserver::STDC));
      ServiceCreate("BUST", CallbackF(&perfserver::BUST));
      ServiceCreate("BFLT", CallbackF(&perfserver::BFLT));
      ServiceCreate("BINT", CallbackF(&perfserver::BINT));
      ServiceCreate("STRT", CallbackF(&perfserver::STRT));
    }
};

int MK_CDECL main(int argc, MK_STRN argv[]) {
  MqMsgque::Setup();
  // setup commandline arguments for later use
  MkBufferListC largs = {argc, argv};
  // [factory-item]
  // create "perfserver" factory… and make it to the default.
  MqFactoryCT<perfserver>::Add("perfserver")->Default();
  // [factory-item]
  // inspect commandline-argument for the "factory" to choose… and create a object
  auto srv = MqFactoryCT<MqContextC>::GetCalled(largs)->New();
  // start listen for incoming call's
  try {
    srv->LinkCreate(largs);
    srv->ProcessEvent (MQ_WAIT_FOREVER);
  } catch (const std::exception& e) {
    srv->ErrorCatch(e);
  }
  srv->Exit();
}