gonetmap icon indicating copy to clipboard operation
gonetmap copied to clipboard

What's the proper way to multithread gonetmap?

Open ntcong opened this issue 6 years ago • 2 comments

I tried several ways to multithread gonetmap but it doesn't work

for ringIndex := uint32(0); ringIndex < iface.Nif.RxRings+1; ringIndex++ {
	ring := iface.GetRing(ringIndex, gonetmap.RX)
	go pollingWorker(iface, ring, 1000) // polling specific ring with processRing(ring)
}
for i := uint32(0); i < 8; i++ {
	ring := iface.GetRing(ringIndex, gonetmap.RX)
	go pollingWorker(iface, 1000)  // a loop create ring and use processRing(ring)
}

It's always fail with

ens192 RX0: fail 'cur < head || cur > kring->nr_hwtail' h 47 c 43 t 47 rh 47 rc 43 rt 47
hc 43 ht 47

Seems like different goroutines change cur/head.

ntcong avatar Jul 31 '19 10:07 ntcong

Hi, @ntcong ! Thank you for your interest in my project and I apologize for the long answer.

You should not use any synchronization primitives, which means sharing nothing between goroutines. And for what purpose did you need multithreading?

pragus avatar Oct 16 '19 13:10 pragus

Hi. I'm trying to process a large number of packet, mostly when the server under heavy traffic like DDOS. With only 1 core there's a lot of packet dropping. This is what I did before I switched to nff-go. In case someone wants to do multiprocessing with gonetmap

		for ringIndex := uint32(0); ringIndex < uint32(*numRingWorker); ringIndex++ {
			netmap := gonetmap.New()
			req0 := gonetmap.Request{Version: 14, RingId: uint16(ringIndex), Flags: gonetmap.ReqOneNic, Arg1: 0}
			req0.SetName(*ifname)
			iface, _ := netmap.RegIf(&req0)
			ring := iface.GetRing(ringIndex, gonetmap.RX)
			go pollingWorkerRing(iface, ring, 1000)
		}

ntcong avatar Oct 18 '19 17:10 ntcong