theLink 10.0 NHI1 - theKernel - theLink - theConfig - theSq3Lite - theCompiler - theBrain - theGuard
c - tcl - cs - 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 csmqmsgque protocoll and build together a flat-like structure.

The GOAL for this setup is:

CODE server

/**
 *   @file         NHI1/example/cs/perfserver.cs
 *   @brief        perfserver.cs - 19 Aug 2024 - aotto1968
 *   @copyright    (C) NHI - #1 - Project - Group
 *                 This software has NO permission 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>
 */

using System;
using System.Linq;
using csmkkernel;
using csmqmsgque;

namespace example {

  sealed class perfserver : MqContextC, MqServerSetupIF {

    // factory constructor
    public perfserver(MqContextC tmpl=null) : base(tmpl) {
    }

    private void ECOU () { SendSTART(); SendBUF(ReadBUF()); SendRETURN(); }
    private void ECOI () { SendSTART(); SendI32(ReadI32()); SendRETURN(); }

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

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

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

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

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

    // [BufferStream-Create-TLS]
    private void BUST () {
      var 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]
    private void BFLT () {
      var bfl = MkBufferListC.CreateTLS( "perfserver-BFLT" );
      while (ReadItemExists()) {
        bfl.AppendBUF(ReadBUF());
      }
      SendSTART();
      var size = bfl.Size();
      for (int i=0; i<size; i++) {
        SendBUF(bfl.IndexGet(i));
      };
      SendRETURN();
    }
    // [BufferList-Create-TLS]

    private void BINT () {
      ReadBIN();
    }

    private void STRT () {
      ReadSTR();
    }

    private void NTHT () {
    }

    void MqServerSetupIF.ServerSetup() {
      ServiceCreate("ECOU", ECOU);
      ServiceCreate("ECOI", ECOI);
      ServiceCreate("ECUL", ECUL);
      ServiceCreate("RDUL", RDUL);
      ServiceCreate("RDUC", RDUC);
      ServiceCreate("STDB", STDB);
      ServiceCreate("STDC", STDC);
      ServiceCreate("BUST", BUST);
      ServiceCreate("BFLT", BFLT);
      ServiceCreate("BINT", BINT);
      ServiceCreate("STRT", STRT);
      ServiceCreate("NTHT", NTHT);
    }

    static void Main(string[] argv) {
      MqMsgque.Setup();

      // setup commandline arguments for later use
      var largv = new MkBufferListC(argv);
  
      // [factory-item]
      // create "perfserver" factory… and make it to the default.
      MqFactoryCT<perfserver>.Add().Default();
      // [factory-item]

      // inspect commandline-argument for the "factory" to choose… and create a object
      var srv = MqFactoryCT<MqContextC>.GetCalled(largv).New();

      try {
	srv.LinkCreate(largv);
	srv.ProcessEvent(MqWaitOnEventE.FOREVER);
      } catch (Exception ex) {
        srv.ErrorCatch (ex);
      }
      srv.Exit();
    }
  }
}