文章摘要
文章比较了2025年底AWS Lambda在arm64和x86_64架构上的性能表现,测试了Node.js、Python和Rust在CPU、内存和I/O工作负载下的性能。特别提到Rust在ARM64上启用汇编优化的SHA-256哈希后,性能提升了4-5倍,处理时间从约152ms缩短到约35ms。
文章总结
2025年末AWS Lambda Arm64与x86_64多运行时性能对比分析
核心发现
- 性能冠军:Rust在arm64架构上综合表现最优,在CPU密集型任务中比Node.js快8倍,比Python快2倍
- 架构优势:arm64整体性能持平或优于x86_64,同时享有20%价格折扣和更小环境足迹
- 运行时表现:
- Python 3.11意外成为最快Python版本(比3.14快9-15%)
- Node.js 22比20版本快8-11%
- Rust冷启动仅16ms,比解释型语言快5-8倍
测试方法论
测试场景:
- 轻量级:DynamoDB批量读写(含网络I/O)
- CPU密集型:50万次SHA-256哈希计算
- 内存密集型:100MB数组排序
测试配置:
- 覆盖Node.js 20/22、Python 3.11-3.14、Rust等7个运行时
- 内存配置从128MB到10GB不等
- 每种配置进行625次调用(125次冷启动+500次热启动)
关键数据
CPU测试(2048MB内存): | 运行时 | arm64耗时 | x86耗时 | |--------------|-----------|---------| | Rust | 35ms | 152ms | | Python 3.11 | 263ms | 341ms | | Node.js 22 | 1260ms | 1384ms |
成本效益:
- arm64平均节省25-40%成本
- 内存密集型任务最高节省42%
优化发现
通过启用SHA-2库的asm特性,Rust在arm64上的SHA-256性能提升4-5倍,使ARM优势从最初的10%反超为显著领先。
实践建议
- 无特殊需求时应优先选择arm64架构
- 不同场景推荐:
- 极致性能:Rust+arm64
- Python项目:Python 3.11+arm64
- I/O密集型:任意运行时,优先考虑成本
完整测试代码已开源在aws-lambda-performance-benchmarks仓库,包含12月更新的Rust优化结果。测试表明,充分挖掘硬件特性可带来显著性能提升,建议生产环境中进行针对性基准测试。
(注:原文中约50%的配置细节和重复结论已精简,保留所有核心数据和关键发现)
评论总结
以下是评论内容的总结:
1. 关于ARM与x86性能比较
- 支持ARM的观点:ARM64在性能上普遍优于x86,且能显著降低成本。
- "One of the easiest hack to reduce your AWS bills is to migrate from x86 to arm64 CPU... cost can be upto 50% lower" (abhashanand1501)
- "ARM64 is just strictly faster when running the same nodejs workload and version" (KeplerBoy)
- 质疑ARM的观点:ARM性能优势可能受限于特定场景或AWS的硬件配置。
- "the arm64 implementation was stuck at something like Graviton2" (coredog64)
- "Hash functions are not representative of the performance of... Business logic" (pizlonator)
2. 关于编程语言性能
- Node.js性能争议:
- 批评:Node.js表现不佳,冷启动慢。
- "Node.js did really badly... ~200ms requests even in the light case" (torginus)
- "Node 22 had ~50ms slower coldstarts than Node 20" (perpil)
- 辩护:ARM64上Node.js比x86更快。
- "ARM64 is just strictly faster when running the same nodejs workload" (KeplerBoy)
- 批评:Node.js表现不佳,冷启动慢。
- Python与Rust性能:
- Rust应比Python快得多,但测试方法可能有问题。
- "How is Rust only one order of magnitude faster than Python?" (pizlonator)
- "the 'light' test will do calls to 'dynamodb'... you benchmark average dynamodb latencies" (greatgib)
- Rust应比Python快得多,但测试方法可能有问题。
3. 测试方法与局限性
- 测试方法问题:
- SHA256哈希测试不能全面反映CPU性能。
- "Hash functions are not representative of the performance of... Compression or decompression" (pizlonator)
- "the cpu and memory test code looks like to be especially specific" (greatgib)
- 冷启动测试未涵盖完整流程。
- "The Init Duration in the logs doesn't include things like decrypting environment variables" (perpil)
- SHA256哈希测试不能全面反映CPU性能。
- 其他测试建议:
- 建议加入更多语言(如C++)和场景测试。
- "Would be interesting to see a benchmark with the rust binary with successively more 'bloat'" (mnutt)
- "Would be interesting to add a cold start + 'import boto3' benchmark for Python" (ju-st)
- 建议加入更多语言(如C++)和场景测试。
4. 其他观点
- 硬件与生态问题:
- 缺少ARM Linux笔记本的讨论。
- "why there isn't almost any laptop with Linux and ARM?" (evilmonkey19)
- 缺少ARM Linux笔记本的讨论。
- 幽默评论:
- 对Intel的调侃。
- "Intel execs after reading this: FAST, more stock buybacks and executive bonuses" (artemonster)
- 对Intel的调侃。
总结:评论主要围绕ARM与x86性能对比、编程语言效率及测试方法的局限性展开,观点多样且部分存在争议。