theLink 10.0 NHI1 - theKernel - theLink - theConfig - theSq3Lite - theCompiler - theBrain - theGuard
c - tcl - py - rb - jv - cc
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         NHI1/example/cc/perfserver.cc
 *   @brief        perfserver.cc - 19 Aug 2024 - aotto1968
 *   @copyright    (C) NHI - #1 - Project - Group
 *                 This software has NO permissions to copy,
 *                 please contact AUTHOR for additional information
 *   @version      a5cb9f916df9a2d44f91871d69b296ab9a9d1e68
 *   @date         Mon Aug 19 14:57:57 2024 +0200
 *   @author       aotto1968 <aotto1968@t-online.de>
 */

/* LABEL-START */

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

/* LABEL-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(); SendBUF(ReadBUF()); SendRETURN(); }
    void ECOI () { SendSTART(); SendI32(ReadI32()); SendRETURN(); }

    void ECUL () {
      SendSTART();
      SendI8(ReadI8());
      SendI16(ReadI16());
      SendI32(ReadI32());
      SendDBL(ReadDBL());
      ProxyItem(this);
      SendRETURN();
    }

    // [BufferStream-Create-TLS]
    void BUST () {
      auto bus = MkBufferStreamC::CreateTLS( "perfserver-BUST" );
      while (ReadItemExists()) {
        bus->WriteBUF(ReadBUF());
      }
      bus->PosToStart();
      SendSTART();
      while (bus->ReadItemExists()) {
        SendBUF(bus->ReadBUF());
      }
      SendRETURN();
    }
    // [BufferStream-Create-TLS]

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

    void RDUL () {
      ReadI8();
      ReadI16();
      ReadI32();
      ReadDBL();
      ReadBUF();
    }

    void RDUC () {
      ReadSTR();
      ReadSTR();
      ReadSTR();
      ReadSTR();
      ReadSTR();
    }

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

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

    void BINT () {
      ReadBIN();
    }

    void STRT () {
      ReadSTR();
    }

    void NTHT () {
    }

    void ServerSetup() {
      ServiceCreate("ECOU", MqServiceICB(&perfserver::ECOU));
      ServiceCreate("ECOI", MqServiceICB(&perfserver::ECOI));
      ServiceCreate("ECUL", MqServiceICB(&perfserver::ECUL));
      ServiceCreate("RDUL", MqServiceICB(&perfserver::RDUL));
      ServiceCreate("RDUC", MqServiceICB(&perfserver::RDUC));
      ServiceCreate("STDB", MqServiceICB(&perfserver::STDB));
      ServiceCreate("STDC", MqServiceICB(&perfserver::STDC));
      ServiceCreate("BUST", MqServiceICB(&perfserver::BUST));
      ServiceCreate("BFLT", MqServiceICB(&perfserver::BFLT));
      ServiceCreate("BINT", MqServiceICB(&perfserver::BINT));
      ServiceCreate("STRT", MqServiceICB(&perfserver::STRT));
      ServiceCreate("NTHT", MqServiceICB(&perfserver::NTHT));
    }
};

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();
}