Skip to content

Performance or Memory Issues with Gopacket #1106

@huhuegg

Description

@huhuegg

Environment and Phenomenon Description:
I am using Gopacket for data analysis of TCP sessions. The data is received from a traffic mirror port on a switch, and other servers perform pre-processing and forward only a portion of the TCP traffic to the server where Gopacket is installed. The TCP portion of the data packets is at a rate of 250,000 to 550,000 packets per second, with a data rate of 0.7-2Gbps. The memory usage of the program continues to increase, leading to increased GC pressure and severely affecting the efficiency of the program.

The following optimizations have been made to the program:

  1. Use DPDK to improve packet capture efficiency and ensure that incoming data packets are not lost.
  2. Assign multiple Gopacket instances based on the hash of the data packet to avoid performance issues with channels.
  3. Set a timer to call FlushCloseOlderThan(time.Now().Add(time.Minute * -1)) every minute.
  4. Use sync.Pool to manage Gopacket.Packet.
  5. Use DecodeFromBytes to parse only Ethernet, IPv4, and TCP data, and manage them using sync.Pool.
  6. Use cgo to manage request and response data caches for TCP sessions to avoid GC.

Problem Analysis:
After monitoring the program continuously for 12 hours using Pyroscope, some problems were discovered by comparing the inuse_object samples. Many Stream objects were not released and remained in use throughout the period:

  1. The New method of Gopacket's StreamFactory creates a large number of reassembly.Stream objects that remain in use, and after 12 hours, the number of these objects in inuse_object reaches 56 million.
  2. reassembly.getConnect also has a large number of objects, and after 12 hours, the number of these objects in inuse_object reaches 57.9 million.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions