// Open device
handle, err = pcap.OpenLive(device, snapshot_len, promiscuous, timeout)
if err == nil {
Info.Println("Open interface ", device, "successfully")
}
defer handle.Close()
//fmt.Println("In the deafult reading case ", time.Now())
// Use the handle as a packet source to process all packets
packetSource := gopacket.NewPacketSource(handle, handle.LinkType())
Info.Println("pcketsourc is ", packetSource, time.Now())
for packet := range packetSource.Packets() {
Debug.Println("-------------------------------------------------------------------")
count++
Warning.Println("packet count ", count)
// write to a pcap for testing
/*err = w.WritePacket(packet.Metadata().CaptureInfo, packet.Data())
if err != nil {
fmt.Println(err)
}*/
continue
Good point.
as a comparison: tcpdump -w /dev/null can handle up to 750Mbps, where sending machine's speed limit reached. I think it should be able to handle line rate.
Are those two packages lighter/faster than gopacket?
handle, err := pcap.OpenLive(device, snapshot_len, promiscuous, timeout)
// ...for {data, ci, err := handle.ZeroCopyReadPacketData()// ...
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Can you offload the actual packet processing to a different goroutine?
Thanks Kevin and Egon!
With a few experiments, I found that the logging, even to a file, is quite time consuming, so turning off logging helps, resulting in 500Mbps-ish no drop rate; however, still not even close to Gbps.
Then I turned on both lazy and nocopy option in the decoding option, the lazy options seems to help. I got something close to 700Mbps, where the sender's limit is reached.
Given that said, the program does not nothing but receiving the packet at this moment. Any actual processing of the packet in the same thread significantly hurt the rate. Besides spinning multiple thread to handle the actual work, anything else in the gopacket land that can be done?
On first appearance, the article you linked to uses some patterns that are different from the same documentation in gopacket: https://godoc.org/github.com/google/gopacket#hdr-Fast_Decoding_With_DecodingLayerParser . Namely, the official docs suggest reusing the parser and results allocations while the third party docs demonstrate reallocating these components on each packet. It's worth double checking that you aren't performing unnecessary allocations due to bad example code.
Also, I recommend reading through https://blog.golang.org/profiling-go-programs if you haven't already. It gives some good examples of drilling down into smaller components to find more granular code bottlenecks.