0

I have a simple program that will generate random string and numbers and put it in specific format:

output: A=SKEK673KJK B=67235 C=PDCNE39JSWL

I have 4 func including main:

func genRandInt() string {
  //return string(randInt)
}

func genRandStr() string {
  //return (randStr)
}

func genFakeData() string {
  fmt.Println("A=" + genRanStr() + genRandInt().....etc)
}

func main() {
  genFackeData()
}

so far the program working fine, and I am executing it via bash loop in order to run it many time in order to generate huge traffic on the server, but I couldn't reach the generated data as I was expected, what I need to run genFackeData() in many worker (e.g 50 worker) how I can achieve that in GO ?

(by the way this is very simple version of my program, to not make complicated I have written the simple sample of what I need)

Moss
  • 378
  • 7
  • 18
  • 1
    Check this out https://gobyexample.com/worker-pools – Seaskyways Dec 26 '18 at 06:42
  • I have already checked this example, but still is not clear for me, would you apply my case to this example ? – Moss Dec 26 '18 at 06:54
  • 1
    See [Is this an idiomatic worker thread pool in Go?](https://stackoverflow.com/questions/38170852/is-this-an-idiomatic-worker-thread-pool-in-go/38172204#38172204) – icza Dec 26 '18 at 08:02

1 Answers1

0

If i am understood your wish right then try to play here https://play.golang.org/p/q_r8PATh6_U

package main

import (
    "fmt"
    "sync"
)

func genFakeData(wg *sync.WaitGroup, i int) {
  fmt.Println("A =",i + 1)
  wg.Done()
}

func main() {
   var wg sync.WaitGroup
   for i:=0 ; i<50 ; i++ {
    wg.Add(1)
    go genFakeData(&wg, i)
   }
   wg.Wait()
}
Maxim
  • 2,233
  • 6
  • 16
  • I have tried the gobyexample.com example, but still not reach more than ~14MBit/s , here is my program: https://play.golang.org/p/mmT9gzz08Y0 – Moss Dec 26 '18 at 11:20
  • ow, you need use something for load testing such as jMeter or Yandex Tank – Maxim Dec 26 '18 at 11:36
  • yes, you are right, I want to test the performance for both the generator and receiver , and this code is about generator, I wanna generate huge traffic toward the receiver , I have used different ways, still not reached more than 14MBit/s on the receiver side, I wanna reach 700MBit/s – Moss Dec 26 '18 at 11:41
  • Relevant detail should be in the body of an answer, not at an external link: https://stackoverflow.com/help/how-to-answer – Adrian Dec 26 '18 at 13:59