Skip to content

Rate limiting for UDP and TCP packets #105

@zeusoo001

Description

@zeusoo001

Background

Libp2p does not rate-limit the processing of UDP and TCP packets, which may cause resource loss. There are physical limitations on the processing power(such as bandwidth, CPU, and memory) of nodes, and the competition for resources by different applications may cause the following problems:

  • Risk of resource overload: Burst traffic or high concurrent requests may cause the node processing capacity to be saturated, affecting normal service response.
  • Degradation of service quality (QoS): Critical traffic (such as transaction/block broadcast) may be delayed or lost because non-critical traffic occupies resources.
  • Differences in protocol characteristics: UDP's connectionless and low-overhead characteristics make it easy to generate high-throughput data streams, but it lacks a built-in flow control mechanism. Although TCP has congestion control, it may still exceed the node's load threshold in extreme scenarios.

Rationale

Rate limiting for UDP and TCP packets can balance resource allocation, avoid resource loss caused by non-critical traffic occupying resources, improve program robustness, and ensure service reliability.

Expected goals of rate limiting:

  • Resource utilization optimization: maximize throughput within the critical point of node load.
  • Service resilience improvement: reduce the risk of system crash through traffic shaping.
  • User experience consistency: avoid global service degradation due to local overload.

The normal rate of each message can be used as a benchmark to limit the message rate without affecting normal functions. The rate of each message is listed below:

Rate limiting for UDP message
  • PingMessage: When a new neighbor is found, a PingMessage will be sent with a timeout of 15s and go for 3 attempts.

  • FindNeighbours: When the neighbor discovery protocol is running, FindNeighbours will be sent to different nodes. The neighbor discovery protool runs every 7.2s.

Rate limiting for TCP message
  • KeepAliveMessage-ping: When the channel does not send a message for 20s, a ping message will be sent to keep the channel alive.
  • HelloMessage: After the TCP connection is established, HelloMessage will be sent for a handshake. It will only appear once in the entire connection cycle.
  • StatusMessage: Node detection message, scheduled every 5 seconds.
  • P2pDisconnectMessage: After receiving this message, the connection will be disconnected. It will only appear once in the entire connection cycle.

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