func runSender(qnum int) {

	ltag := tag + "-runsender"

	ll.Printf("%stag:%s connsess:%s start qnum:%d\n",
		exampid, ltag, sngecomm.Lcs,
		qnum)
	// Standard example connect sequence
	n, conn, e := sngecomm.CommonConnect(exampid, ltag, ll)
	if e != nil {
		ll.Fatalf("%stag:%s connsess:%s error:%s\n",
			exampid, ltag, sngecomm.Lcs,
			e.Error()) // Handle this ......
	}

	//
	sendMessages(conn, qnum, n)

	ll.Printf("%stag:%s connsess:%s sends_complete qnum:%d\n",
		exampid, ltag, conn.Session(),
		qnum)

	// Standard example disconnect sequence
	e = sngecomm.CommonDisconnect(n, conn, exampid, ltag, ll)
	if e != nil {
		ll.Fatalf("%stag:%s connsess:%s error:%s\n",
			exampid, ltag, conn.Session(),
			e.Error()) // Handle this ......
	}
	sngecomm.ShowStats(exampid, "send_"+fmt.Sprintf("%d", qnum), conn)
	wgs.Done()
}
func runReceiver(qnum int) {
	ltag := tag + "-runreceiver"

	ll.Printf("%stag:%s connsess:%s start qnum:%d\n",
		exampid, ltag, sngecomm.Lcs,
		qnum)

	// Standard example connect sequence
	n, conn, e := sngecomm.CommonConnect(exampid, ltag, ll)
	if e != nil {
		ll.Fatalf("%stag:%s connsess:%s error:%s\n",
			exampid, ltag, sngecomm.Lcs,
			e.Error()) // Handle this ......
	}

	//
	conn.SetSubChanCap(senv.SubChanCap()) // Experiment with this value, YMMV
	// Receives
	receiveMessages(conn, qnum, n)

	ll.Printf("%stag:%s connsess:%s receives_complete qnum:%d\n",
		exampid, ltag, conn.Session(),
		qnum)

	// Standard example disconnect sequence
	e = sngecomm.CommonDisconnect(n, conn, exampid, ltag, ll)
	if e != nil {
		ll.Fatalf("%stag:%s connsess:%s error:%s\n",
			exampid, ltag, conn.Session(),
			e.Error()) // Handle this ......
	}

	sngecomm.ShowStats(exampid, "recv_"+fmt.Sprintf("%d", qnum), conn)
	wgr.Done()
}
/*
startSender initializes the single send connection, and starts one sender go
for each destination.
*/
func startSender() {
	ltag := tag + "-startsender"

	n, conn := openSconn()
	ll.Printf("%stag:%s connsess:%s start\n",
		exampid, ltag, conn.Session())
	for i := 1; i <= sngecomm.Nqs(); i++ {
		wgs.Add(1)
		go runSender(conn, fmt.Sprintf("%d", i))
	}
	wgs.Wait()
	ll.Printf("%stag:%s connsess:%s end\n",
		exampid, ltag, conn.Session())
	sngecomm.ShowStats(exampid, ltag, conn)
	closeSconn(n, conn)
	//
	wga.Done()
}
Esempio n. 4
0
func startReceivers(qn int) {
	ltag := tag + "-startreceivers"

	ll.Printf("%stag:%s connsess:%s starts qn:%d\n",
		exampid, ltag, sngecomm.Lcs,
		qn)

	// Standard example connect sequence
	n, conn, e := sngecomm.CommonConnect(exampid, ltag, ll)
	if e != nil {
		ll.Fatalf("%stag:%s connsess:%s on_connect error:%v",
			exampid, ltag, sngecomm.Lcs,
			e.Error()) // Handle this ......
	}

	nmsgs := senv.Nmsgs() // get message count
	ll.Printf("%stag:%s connsess:%s message_count nmsgs:%d qn:%d\n",
		exampid, ltag, conn.Session(),
		nmsgs, qn)
	for i := 1; i <= qn; i++ { // all queues
		wgr.Add(1)
		go receiver(conn, i, nmsgs)
	}
	ll.Printf("%stag:%s connsess:%s starts_done\n",
		exampid, ltag, conn.Session())
	wgr.Wait()

	// Standard example disconnect sequence
	e = sngecomm.CommonDisconnect(n, conn, exampid, ltag, ll)
	if e != nil {
		ll.Fatalf("%stag:%s connsess:%s on_disconnect error:%v",
			exampid, ltag, conn.Session(),
			e.Error()) // Handle this ......
	}

	sngecomm.ShowStats(exampid, ltag, conn)
	wga.Done()
}
/*
startReceivers creates connections per environment variables, and starts each
connection.
*/
func startReceivers() {

	ltag := tag + "-startreceivers"

	// This was a performance experiment.  With number of connections.
	// My recollection is that it did not work out.
	// However ..... I will leave this code in place for now.

	// Figure out number of receiver connections wanted
	nrc := sngecomm.Nqs() // 1 receiver per each destination
	nqs := nrc            // Number of queues (destinations) starts the same

	if s := os.Getenv("STOMP_RECVCONNS"); s != "" {
		i, e := strconv.ParseInt(s, 10, 32)
		if nil != e {
			ll.Fatalf("%stag:%s connsess:%s RECVCONNS_conversion_error error:%v\n",
				exampid, ltag, sngecomm.Lcs,
				e.Error())
		} else {
			nrc = int(i)
		}
	}

	// Limit max receiver connection count to number of destinations
	if nrc > nqs {
		nrc = nqs
	}

	// Next calc. destinations per receiver
	dpr := nqs / nrc // Calculation first guess.
	if nqs%nrc != 0 {
		dpr += 1 // Bump destinations per receiver by 1.
	}
	// Destinations per receiver must be at least 1
	if dpr == 0 {
		dpr = 1
	}

	ll.Printf("%stag:%s connsess:%s start nrc:%d dpr:%d\n",
		exampid, ltag, sngecomm.Lcs,
		nrc, dpr)

	// So the idea seems to be allow more than one destination per receiver
	ncm := make([]net.Conn, 0)
	csm := make([]*stompngo.Connection, 0)
	for c := 1; c <= nrc; c++ { // :-)
		n, conn := openSconn()
		ncm = append(ncm, n)
		csm = append(csm, conn)
		wgr.Add(1)
		ll.Printf("%stag:%s connsess:%s connstart conn_number:%d nrc:%d dpr:%d\n",
			exampid, ltag, conn.Session(),
			c, nrc, dpr)
		go receiverConnection(conn, c, dpr)
	}
	wgr.Wait()
	ll.Printf("%stag:%s connsess:%s wait_done nrc:%d dpr:%d\n",
		exampid, ltag, sngecomm.Lcs,
		nrc, dpr)
	//
	for c := 1; c <= nrc; c++ {
		ll.Printf("%stag:%s connsess:%s connend conn_number:%d nrc:%d dpr:%d\n",
			exampid, ltag, csm[c-1].Session(),
			c, nrc, dpr)
		sngecomm.ShowStats(exampid, ltag, csm[c-1])
		closeSconn(ncm[c-1], csm[c-1])
	}
	//
	wga.Done()
}
Esempio n. 6
0
// A forever reader.
func main() {

	st := time.Now()

	sngecomm.ShowRunParms(exampid)

	// Standard example connect sequence
	var e error
	n, conn, e = sngecomm.CommonConnect(exampid, tag, ll)
	if e != nil {
		if conn != nil {
			ll.Printf("%stag:%s  connsess:%s Connect Response headers:%v body%s\n",
				exampid, tag, conn.Session(), conn.ConnectResponse.Headers,
				string(conn.ConnectResponse.Body))
		}
		ll.Fatalf("%stag:%s connsess:%s main_on_connect error:%v",
			exampid, tag, sngecomm.Lcs,
			e.Error()) // Handle this ......
	}

	//**
	qn := 1
	ltag := tag + "-receiver"

	id := stompngo.Uuid() // A unique subscription ID
	d := sngecomm.Dest()

	ll.Printf("%stag:%s connsess:%s queue_info id:%v d:%v qnum:%v\n",
		exampid, ltag, conn.Session(),
		id, d, qn)
	// Subscribe
	sc := sngecomm.HandleSubscribe(conn, d, id, sngecomm.AckMode())
	ll.Printf("%stag:%s connsess:%s subscribe_complete id:%v d:%v qnum:%v\n",
		exampid, ltag, conn.Session(),
		id, d, qn)
	//
	var md stompngo.MessageData
	// Receive loop
	mc := 1
	for {
		ll.Println("========================== ", "Expecting Message:", mc,
			"==========================")
		select {
		case md = <-sc:
		case md = <-conn.MessageData:
			// A RECEIPT or ERROR frame is unexpected here
			ll.Fatalf("%stag:%s connsess:%s bad_frame qnum:%v headers:%v body:%s",
				exampid, tag, conn.Session(),
				qn, md.Message.Headers, md.Message.Body) // Handle this ......
		}
		if md.Error != nil {
			ll.Fatalf("%stag:%s connsess:%s recv_error qnum:%v error:%v",
				exampid, tag, conn.Session(),
				qn, md.Error) // Handle this ......
		}

		ll.Printf("%stag:%s connsess:%s next_frame mc:%v command:%v headers:%v body:%v\n",
			exampid, tag, conn.Session(),
			mc, md.Message.Command, md.Message.Headers, string(md.Message.Body)) // Handle this ......

		mc++
	}

	//**

	// Standard example disconnect sequence
	e = sngecomm.CommonDisconnect(n, conn, exampid, tag, ll)
	if e != nil {
		ll.Fatalf("%stag:%s connsess:%s main_on_disconnect error:%v",
			exampid, tag, conn.Session(),
			e.Error()) // Handle this ......
	}

	sngecomm.ShowStats(exampid, tag, conn)

	ll.Printf("%stag:%s connsess:%s main_elapsed:%v\n",
		exampid, tag, conn.Session(),
		time.Now().Sub(st))

}
Esempio n. 7
0
// Show a number of writers and readers operating concurrently from unique
// destinations.
func main() {

	st := time.Now()

	sngecomm.ShowRunParms(exampid)

	ll.Printf("%stag:%s connsess:%s main_starts\n",
		exampid, tag, sngecomm.Lcs)

	ll.Printf("%stag:%s connsess:%s main_profiling pprof:%v\n",
		exampid, tag, sngecomm.Lcs,
		sngecomm.Pprof())

	ll.Printf("%stag:%s connsess:%s main_current_GOMAXPROCS gmp:%v\n",
		exampid, tag, sngecomm.Lcs,
		runtime.GOMAXPROCS(-1))

	if sngecomm.SetMAXPROCS() {
		nc := runtime.NumCPU()
		ll.Printf("%stag:%s connsess:%s main_current_num_cpus cncpu:%v\n",
			exampid, tag, sngecomm.Lcs,
			nc)
		gmp := runtime.GOMAXPROCS(nc)
		ll.Printf("%stag:%s connsess:%s main_previous_num_cpus pncpu:%v\n",
			exampid, tag, sngecomm.Lcs,
			gmp)
		ll.Printf("%stag:%s connsess:%s main_current_GOMAXPROCS gmp:%v\n",
			exampid, tag, sngecomm.Lcs,
			runtime.GOMAXPROCS(-1))
	}
	// Wait flags
	sw = sngecomm.SendWait()
	rw = sngecomm.RecvWait()
	sf = sngecomm.SendFactor()
	rf = sngecomm.RecvFactor()
	ll.Printf("%stag:%s connsess:%s main_wait_sleep_factors sw:%v rw:%v sf:%v rf:%v\n",
		exampid, tag, sngecomm.Lcs,
		sw, rw, sf, rf)
	// Number of queues
	nqs := sngecomm.Nqs()

	// Standard example connect sequence
	var e error
	n, conn, e = sngecomm.CommonConnect(exampid, tag, ll)
	if e != nil {
		if conn != nil {
			ll.Printf("%stag:%s  connsess:%s Connect Response headers:%v body%s\n",
				exampid, tag, conn.Session(), conn.ConnectResponse.Headers,
				string(conn.ConnectResponse.Body))
		}
		ll.Fatalf("%stag:%s connsess:%s main_on_connect error:%v",
			exampid, tag, sngecomm.Lcs,
			e.Error()) // Handle this ......
	}

	// Many receivers running under the same connection can cause
	// (wire read) performance issues.  This is *very* dependent on the broker
	// being used, specifically the broker's algorithm for putting messages on
	// the wire.
	// To alleviate those issues, this strategy insures that messages are
	// received from the wire as soon as possible.  Those messages are then
	// buffered internally for (possibly later) application processing. In
	// this example, buffering occurs in the stompngo package.
	conn.SetSubChanCap(senv.SubChanCap()) // Experiment with this value, YMMV

	// Run everything
	wga.Add(2)
	go startReceivers(nqs)
	go startSenders(nqs)
	wga.Wait()

	// Standard example disconnect sequence
	e = sngecomm.CommonDisconnect(n, conn, exampid, tag, ll)
	if e != nil {
		ll.Fatalf("%stag:%s connsess:%s main_on_disconnect error:%v",
			exampid, tag, conn.Session(),
			e.Error()) // Handle this ......
	}

	sngecomm.ShowStats(exampid, tag, conn)

	ll.Printf("%stag:%s connsess:%s main_elapsed:%v\n",
		exampid, tag, conn.Session(),
		time.Now().Sub(st))

}