Skip to content

Request rate limiting to protect PLC resources #628

@gijzelaerr

Description

@gijzelaerr

Summary

Add configurable request rate limiting to prevent overwhelming PLCs with too many requests, especially older/smaller models with limited processing capacity.

Background

Siemens S7-200 and S7-300 PLCs have limited communication resources. Sending requests too fast can cause the PLC to drop connections, queue requests, or even affect scan cycle times. A built-in rate limiter would protect against this, especially in polling loops.

What needs to be done

  • Implement a configurable rate limiter (max requests per second)
  • Support both fixed-rate and token-bucket algorithms
  • Apply rate limiting transparently to all client operations
  • Add per-connection and optionally per-PLC-model rate limits
  • Add configurable behavior when limit is hit: block (wait), raise exception, or drop
  • Make it opt-in (disabled by default)
  • Add tests
  • Add documentation

API Design Ideas

client = snap7.Client(
    max_requests_per_second=10,  # 0 for unlimited (default)
    rate_limit_behavior="block",  # "block", "raise", or "drop"
)

client.connect("192.168.1.10", 0, 1)

# Operations are automatically throttled
for i in range(1000):
    data = client.db_read(1, 0, 4)  # Will not exceed 10 req/s

Notes

  • Different PLC models have different limits:
    • S7-200: ~10 requests/second
    • S7-300: ~20-50 requests/second
    • S7-400: ~100+ requests/second
    • S7-1200/1500: ~100+ requests/second
  • Could provide sensible defaults per PLC model (auto-detected from CPU info)
  • Rate limiting should account for multi-variable operations (one multi-read = one request, not N)
  • Should work with both sync and future async clients

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions