C++ class templates for graph construction and search
This document explains how to test performance on very large graphs (10K-1M+ vertices) and understand scalability characteristics.
Large-scale performance testing addresses different concerns than micro-benchmarks:
Graph Size | Memory Needed | Use Case |
---|---|---|
10K vertices | ~50 MB | Development, CI testing |
100K vertices | ~500 MB | Realistic applications |
500K vertices | ~2.5 GB | Large applications |
1M+ vertices | ~5+ GB | Enterprise, research |
# Check available memory
free -h
# Recommended minimums:
# 4GB RAM: Up to 100K vertices
# 8GB RAM: Up to 500K vertices
# 16GB RAM: Up to 1M+ vertices
// ~4 edges per vertex (realistic road connectivity)
auto graph = LargeGraphGenerator::CreateRoadNetwork(316, 316); // 100K vertices
Characteristics:
// Variable degree distribution (some highly connected nodes)
auto graph = LargeGraphGenerator::CreateSocialNetwork(100000);
Characteristics:
// Dense connections within clusters, sparse between clusters
auto graph = LargeGraphGenerator::CreateClusteredGraph(1000, 100); // 100K vertices
Characteristics:
# Run comprehensive large-scale benchmarks
cd build
../scripts/run_large_scale_tests.sh
# Build large-scale benchmarks
make test_large_scale_benchmarks
# Run with timeout (recommended)
timeout 30m ./bin/test_large_scale_benchmarks
# Monitor memory usage during execution
watch -n 1 'free -h && ps aux | grep test_large_scale'
# Ensure sufficient memory
AVAILABLE_MB=$(awk '/MemAvailable/ {print int($2/1024)}' /proc/meminfo)
echo "Available memory: ${AVAILABLE_MB} MB"
# 30-minute timeout for safety
timeout 1800 ./bin/test_large_scale_benchmarks
# In another terminal
htop
# or
watch -n 1 'free -h && df -h'
100K Road Network (316x316):
Construction time: 0.18 seconds
Vertices: 99856
Edges: 398727
Memory used: 42.3 MB
Memory per vertex: 444 bytes
Construction rate: 549296 vertices/sec
Key Metrics:
Road Network Searches:
100x100 network (10000 vertices):
Dijkstra: 2.7 ms avg, 8/8 successful, avg path: 48 nodes
200x200 network (40000 vertices):
Dijkstra: 12.6 ms avg, 8/8 successful, avg path: 96 nodes
316x316 network (99856 vertices):
Dijkstra: 35.9 ms avg, 8/8 successful, avg path: 152 nodes
Analysis:
Memory Scaling Analysis:
50x50 (2500 vertices): 0.9 MB (378 bytes/vertex)
100x100 (10000 vertices): 4.7 MB (491 bytes/vertex)
200x200 (40000 vertices): 18.2 MB (477 bytes/vertex)
Insights:
Concurrent Large Graph Searches:
1 threads: 0.3s, 35 searches/sec, 10/10 successful
2 threads: 0.3s, 67 searches/sec, 20/20 successful
4 threads: 0.3s, 136 searches/sec, 40/40 successful
8 threads: 0.3s, 275 searches/sec, 80/80 successful
Analysis:
// Compact state representation
struct CompactState {
int32_t x, y; // Use smaller types
int64_t GetId() const { return static_cast<int64_t>(y) * 100000 + x; }
};
// Use float for edge weights when precision allows
using LargeGraph = Graph<CompactState, float, DefaultIndexer<CompactState>>;
# Gradually increase graph size until system limits
for size in 50000 100000 200000 500000; do
echo "Testing $size vertices..."
# Monitor memory usage and performance degradation
done
# Test system stability under sustained load
timeout 1h ./bin/test_large_scale_benchmarks
# Multiple benchmark processes
for i in {1..4}; do
./bin/test_large_scale_benchmarks &
done
wait
# Symptoms: Process killed, system freezing
# Solutions: Reduce graph size, increase swap, use smaller data types
swapon –show free -h
3. **Long Execution Times**
timeout 30m ./bin/test_large_scale_benchmarks
4. **Inconsistent Results**
echo 3 > /proc/sys/vm/drop_caches # Clear caches systemctl stop unnecessary-services
### Performance Analysis Tools
```bash
# Memory profiling
valgrind --tool=massif ./bin/test_large_scale_benchmarks
# CPU profiling
perf record ./bin/test_large_scale_benchmarks
perf report
# System monitoring
iostat -x 1
vmstat 1
# Example CI configuration
large_scale_tests:
runs-on: ubuntu-latest-8core
timeout-minutes: 60
steps:
- name: Check available memory
run: free -h
- name: Run large-scale tests
run: |
cd build
timeout 45m ../scripts/run_large_scale_tests.sh
- name: Archive results
uses: actions/upload-artifact@v2
with:
name: large-scale-results
path: performance_results/
# Compare with baseline
../scripts/compare_performance.py \
performance_results/baseline_large_scale.txt \
performance_results/latest_large_scale.txt
# Alert on significant regressions (>20% slower)
Operation | Expected | Large-Scale Observation |
---|---|---|
Graph Construction | O(V + E) | Linear scaling confirmed |
Dijkstra Search | O((V + E) log V) | ~O(V^1.2) on dense graphs |
BFS | O(V + E) | Linear with graph size |
DFS | O(V + E) | Linear, but high constant |
Graph Type | Vertices | Expected Memory | Observed |
---|---|---|---|
Road Network | 100K | ~40-60 MB | 42.3 MB ✓ |
Social Network | 100K | ~50-80 MB | Varies by degree |
Clustered | 100K | ~60-100 MB | High due to density |
This large-scale testing framework provides the foundation for understanding real-world performance characteristics and validating optimizations on production-sized graphs.