Skip to Content
AgentPerformance

Performance

Performance comparison between snmpkit (Rust core) and pyagentx3 (pure Python).

Benchmarks

snmpkit (Rust)
pyagentx3 (Python)

OID Parse

snmpkit
318k/s
pyagentx3
216k/s

1.5x faster

Value Create

snmpkit
332k/s
pyagentx3
52k/s

6.4x faster

PDU Encode

snmpkit
196k/s
pyagentx3
17k/s

11.5x faster

Header Decode

snmpkit
968k/s
pyagentx3
1.0M/s

1.1x slower

10,000 iterations per benchmark. Higher is better.

Analysis

PDU Encode: 11.5x faster

The most critical operation for agent response times. snmpkit encodes PDUs in Rust with zero-copy byte handling, while pyagentx3 uses Python’s struct.pack with multiple allocations.

Value Create: 6.4x faster

Creating SNMP values (Integer, OctetString, Counter64, etc.) is significantly faster in Rust. This benefits agents with large table responses where thousands of values are created per request.

OID Parse: 1.5x faster

Parsing OID strings like “1.3.6.1.4.1.12345” into internal representation. snmpkit uses a Rust parser with pre-allocated buffers.

Header Decode: ~1x (equal)

Header decode is roughly equal between implementations. This 20-byte operation is so fast (~1M ops/sec) that the PyO3 FFI overhead of crossing the Python↔Rust boundary negates the Rust speedup. This is expected and acceptable since:

  1. Header decode happens once per PDU (not a bottleneck)
  2. The operations that matter (encode, value creation) are much faster
  3. Real-world performance is dominated by network I/O

Test Environment

ComponentSpecification
CPUAMD Ryzen 7 5800X (8C/16T, 3.8GHz base)
Memory64GB DDR4 3600MHz CL18
OSUbuntu 22.04 LTS (WSL2)
Python3.14 (free-threaded)
Rust1.83.0

All benchmarks measure raw encoding/decoding performance without network I/O overhead. Each operation runs 10,000 iterations.

Real-World Impact

Response Latency

For a typical SNMP GET request with 10 OIDs:

Operationpyagentx3snmpkit
Decode header1 μs1 μs
Create 10 values192 μs30 μs
Encode response588 μs51 μs
Total781 μs82 μs

snmpkit responds ~9.5x faster before network latency.

Throughput

At 1000 OIDs per response:

  • pyagentx3: ~500 responses/sec (bottlenecked by encoding)
  • snmpkit: ~5,000 responses/sec (bottlenecked by network)

Memory

snmpkit uses less memory per OID:

  • pyagentx3: OIDs stored as Python strings with full object overhead
  • snmpkit: OIDs stored as compact Rust tuples, exposed to Python on-demand

Optimization Tips

Enable Parallel Encoding

For agents serving 1000+ OIDs:

agent = Agent(parallel_encoding=True)

This uses Rust’s rayon for multi-threaded PDU encoding.

Tune Update Frequency

Don’t update faster than needed:

# Fast updates only where necessary agent.register("1.3.6.1.4.1.12345.1", RealtimeMetrics(), freq=1) # Slow updates for stable data agent.register("1.3.6.1.4.1.12345.2", ConfigData(), freq=60)

Use Appropriate Types

Counter64 is larger to encode than Integer32. Use the smallest type that fits your data:

# Good: use Counter32 for values < 4 billion self.set_COUNTER32("1.0", packet_count) # Only use Counter64 when needed self.set_COUNTER64("2.0", bytes_transferred)

Reproducing Benchmarks

Run the benchmarks yourself:

cd benchmarks python run_benchmarks.py

Results are saved to benchmarks/results.json.

Last updated on