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

The GOAL for this setup is:

CODE server

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

package main

import (
  .   "gomsgque/mkkernel"
  .   "gomsgque/mqmsgque"
      "os"
      "runtime/pprof"
      "log"
)

type PerfServer struct {
  MqContextC
  // add server specific data 
}

func PerfServer_New(tmpl MqContextCI) MqFactoryI {
  srv := new(PerfServer)
  srv.Init(tmpl,srv)
  return srv
}

func (this *PerfServer) ServerSetup() {
  this.ServiceCreate("ECOU", (*ECOU)(this))
  this.ServiceCreate("ECOI", (*ECOI)(this))
  this.ServiceCreate("ECUL", (*ECUL)(this))
  this.ServiceCreate("RDUL", (*RDUL)(this))
  this.ServiceCreate("RDUC", (*RDUC)(this))
  this.ServiceCreate("STDB", (*STDB)(this))
  this.ServiceCreate("STDC", (*STDC)(this))
  this.ServiceCreate("BUST", (*BUST)(this))
  this.ServiceCreate("BFLT", (*BFLT)(this))
  this.ServiceCreate("BINT", (*BINT)(this))
  this.ServiceCreate("STRT", (*STRT)(this))
}

type BINT PerfServer
  func (this *BINT) Call() {
    this.ReadB()
  }

type STRT PerfServer
  func (this *STRT) Call() {
    this.ReadC()
  }

type ECOU PerfServer
  func (this *ECOU) Call() {
    this.SendSTART()
    this.SendU(this.ReadU())
    this.SendRETURN()
  }

type ECOI PerfServer
  func (this *ECOI) Call() {
    this.SendSTART()
    this.SendI(this.ReadI())
    this.SendRETURN()
  }

type ECUL PerfServer
  func (this *ECUL) Call() {
    this.SendSTART()
    this.SendY(this.ReadY())
    this.SendS(this.ReadS())
    this.SendI(this.ReadI())
    this.SendD(this.ReadD())
    this.ProxyItem(this)
    this.SendRETURN()
  }

type RDUL PerfServer
  func (this *RDUL) Call() {
    this.ReadY()
    this.ReadS()
    this.ReadI()
    this.ReadD()
    this.ReadU()
  }

type RDUC PerfServer
  func (this *RDUC) Call() {
    this.ReadC()
    this.ReadC()
    this.ReadC()
    this.ReadC()
    this.ReadC()
  }

type STDB PerfServer
  func (this *STDB) Call() {
    this.SendSTART()
    this.StorageOpen(this.ReadC())
    this.SendRETURN()
  }

type STDC PerfServer
  func (this *STDC) Call() {
    this.SendSTART()
    this.StorageClose()
    this.SendRETURN()
  }

// [BufferStream-Create-TLS]
type BUST PerfServer
  func (this *BUST) Call() {
    bus := MkBufferStreamCreateTLS(0)
    for this.ReadItemExists() {
      bus.WriteU(this.ReadU())
    }
    bus.PosToStart()
    this.SendSTART()
    for bus.ReadItemExists() {
      this.SendU(bus.ReadU())
    }
    this.SendRETURN()
  }
// [BufferStream-Create-TLS]

// [BufferList-Create-TLS]
type BFLT PerfServer
  func (this *BFLT) Call() {
    bfl := MkBufferListCreateTLS(0)
    for this.ReadItemExists() {
      bfl.AppendU(this.ReadU())
    }
    this.SendSTART()
    size := bfl.Size()
    for i := int32(0); i < size; i++ {
      this.SendU(bfl.IndexGet(i))
    }
    this.SendRETURN()
  }
// [BufferList-Create-TLS]

func main() {
  profiling := false

  if false {
      // go tool pprof -web out.prof
      f, err := os.Create("out.prof")
      if err != nil { log.Fatal(err) }
      pprof.StartCPUProfile(f)
      profiling = true
  }

  // setup commandline arguments for later use
  largv := MkBufferListCreateVC(os.Args)

  // [factory-item]
  // create "perfserver" factory… and make it to the default.
  MqFactoryAdd(PerfServer_New, "perfserver").Default()
  // [factory-item]

  // inspect commandline-argument for the "factory" to choose… and create a object
  srv := MqFactoryGetCalledL(largv).New()

  defer func() {
    if x := recover(); x != nil {
      srv.ErrorCatch_1(x)
    }
    if profiling { pprof.StopCPUProfile() }
    srv.Exit_0()
  }()
  srv.LinkCreateVC(os.Args)
  srv.ProcessEvent(MQ_WAIT_FOREVER,MK_TIMEOUT_DEFAULT)
}