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

The GOAL for this setup is:

CODE server

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

using System;
using System.Linq;
using csmsgque.mkkernel;
using csmsgque.mqmsgque;

namespace example {

  sealed class perfserver : MqContextC, IServerSetup {

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

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

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

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

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

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

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

    // [BufferStream-Create-TLS]
    private void BUST () {
      var 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]
    private void BFLT () {
      var bfl = MkBufferListC.CreateTLS(0);
      while (ReadItemExists()) {
        bfl.AppendU(ReadU());
      }
      SendSTART();
      foreach (int i in Enumerable.Range(0, bfl.Size())) {
        SendU(bfl.IndexGet(i));
      };
      SendRETURN();
    }
    // [BufferList-Create-TLS]

    private void BINT () {
      ReadB();
    }

    private void STRT () {
      ReadC();
    }

    // define a service as link between the token "HLWO" and the callback "MyFirstService"
    void IServerSetup.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);
    }

    static void Main(string[] argv) {
      // 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();
    }
  }
}