logo
Public
0
0
WeChat Login
✨ docs: 添加 MQTT X Claude Code Skills 文档

MQTTX Performance Skill

Comprehensive performance optimization skill for MQTTX applications.

Overview

This skill provides tools, templates, and guides for optimizing MQTTX application performance across various scenarios including high-throughput IoT gateways, low-latency control systems, resource-constrained edge devices, and mobile applications.

Skill Structure

mqttx-performance/ ├── SKILL.md # Main skill documentation ├── assets/ │ └── performance-tuning.go.tmpl # Complete performance configuration examples ├── scripts/ │ └── benchmark.sh # Automated benchmark testing script └── references/ └── performance-guide.md # Detailed optimization guide

Files Description

SKILL.md (439 lines)

The main skill entry point containing:

  • When to use this skill
  • Quick optimization strategies
  • Performance monitoring examples
  • Troubleshooting common issues
  • Links to detailed resources

assets/performance-tuning.go.tmpl (557 lines)

Complete Go code templates for:

  • High-throughput configuration
  • Low-latency configuration
  • Resource-constrained configuration
  • Unstable network configuration
  • Multi-session load balancing
  • Batch message processing
  • Worker pool implementation
  • Performance monitoring system
  • Complete working examples

scripts/benchmark.sh (353 lines)

Automated benchmark script providing:

  • Basic performance benchmarks
  • Storage performance tests
  • CPU profiling
  • Memory profiling
  • Execution tracing
  • Automated summary generation
  • Configurable test parameters

Usage:

cd /workspace/docs/skills/mqttx-performance/scripts chmod +x benchmark.sh # Run all benchmarks ./benchmark.sh # Run specific benchmarks ./benchmark.sh --basic --cpu # Customize duration BENCHMARK_TIME=60s ./benchmark.sh --basic # See all options ./benchmark.sh --help

references/performance-guide.md (726 lines)

Comprehensive optimization guide covering:

  • Performance overview and benchmarks
  • Configuration optimization strategies
  • Memory management techniques
  • Concurrency optimization patterns
  • Network optimization
  • Storage optimization
  • Scenario-specific tuning (IoT, control systems, edge, mobile)
  • Performance monitoring and KPIs
  • Troubleshooting guide
  • Performance tuning checklist

Quick Start

1. View the Skill

cat /workspace/docs/skills/mqttx-performance/SKILL.md

2. Use Configuration Templates

# Copy template to your project cp /workspace/docs/skills/mqttx-performance/assets/performance-tuning.go.tmpl \ /your/project/performance-config.go # Edit and adapt to your needs vim /your/project/performance-config.go

3. Run Benchmarks

cd /workspace/docs/skills/mqttx-performance/scripts ./benchmark.sh

4. Review Detailed Guide

cat /workspace/docs/skills/mqttx-performance/references/performance-guide.md

Key Performance Scenarios

High-Throughput (100K+ msg/sec)

  • 64KB buffers
  • Large message channels (10K+)
  • QoS 0 for sensors
  • Multiple concurrent sessions
  • See: assets/performance-tuning.go.tmplcreateHighThroughputSession()

Low-Latency (<10ms)

  • 8KB buffers
  • Small message channels (100-1000)
  • Direct message processing
  • Local broker connection
  • See: assets/performance-tuning.go.tmplcreateLowLatencySession()

Resource-Constrained (<10MB)

  • 1KB minimal buffers
  • Very small channels (10-50)
  • Clean sessions (no persistence)
  • Strict message limits
  • See: assets/performance-tuning.go.tmplcreateConstrainedSession()

Unstable Network (Mobile/Cellular)

  • Multiple broker addresses
  • Persistent sessions
  • Aggressive reconnect strategy
  • Message persistence
  • See: assets/performance-tuning.go.tmplcreateResilientSession()

Performance Monitoring

The skill includes a complete performance monitoring system:

// Start monitoring monitor := NewPerformanceMonitor(manager, 10*time.Second) monitor.Start() defer monitor.Stop() // Get metrics history history := monitor.GetHistory() // Report session metrics reportSessionMetrics(manager, "session-name")

See assets/performance-tuning.go.tmpl for complete implementation.

Benchmarking

Run comprehensive benchmarks:

# Full benchmark suite ./scripts/benchmark.sh # Quick benchmarks only ./scripts/benchmark.sh --basic # With profiling ./scripts/benchmark.sh --cpu --mem # Custom duration BENCHMARK_TIME=120s ./scripts/benchmark.sh

Results are saved in ./benchmark-results/ directory.

Optimization Workflow

  1. Baseline: Run benchmarks to establish baseline performance
  2. Monitor: Set up performance monitoring in your application
  3. Identify: Use metrics to identify bottlenecks
  4. Optimize: Apply scenario-specific optimizations
  5. Measure: Run benchmarks again to verify improvements
  6. Iterate: Repeat until performance targets are met

Related Documentation

  • /workspace/docs/性能调优指南.md - Chinese performance tuning guide
  • /workspace/docs/PERFORMANCE_GUIDE.md - English performance guide
  • /workspace/benchmark_test.go - Benchmark test implementations
  • /workspace/types.go - PerformanceOptions type definitions

Performance Targets

On standard hardware (4-core CPU, 8GB RAM):

MetricTargetConfiguration
Throughput100K+ msg/secHigh-throughput config
Latency<10msLow-latency config
Memory per session<10MBDefault config
Connection capacity1000+ sessionsMulti-session config
Error rate<0.1%Proper error handling
Reconnect time<5sAuto-reconnect enabled

Troubleshooting Quick Reference

IssueSolution
Message backlogIncrease MessageChanSize, add workers
High latencyReduce buffer sizes, use QoS 0
Memory leaksStop unused routes, clean up sessions
Connection failuresIncrease timeouts, use multiple brokers
High CPUUse batch processing, optimize handlers
GC pressureReduce allocations, increase limits

See references/performance-guide.md for detailed troubleshooting steps.

Contributing

To improve this skill:

  1. Add new configuration templates to assets/
  2. Enhance benchmark scripts in scripts/
  3. Update guides in references/
  4. Add real-world examples to SKILL.md

License

Part of the MQTTX project. See project LICENSE for details.

Support

For performance issues or questions:

  1. Review this skill's documentation
  2. Run benchmarks to identify bottlenecks
  3. Check the troubleshooting guide
  4. Consult the main MQTTX documentation