Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
百度贴吧HHVM应用实践
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Reeze Xia
August 24, 2014
Technology
1.3k
6
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
百度贴吧HHVM应用实践
Reeze Xia
August 24, 2014
More Decks by Reeze Xia
See All by Reeze Xia
HHVM: A High Performance PHP Engine
reeze
3
140
百度贴吧服务端性能优化实践
reeze
5
1.8k
百度贴吧LAMP架构
reeze
1
1.4k
Other Decks in Technology
See All in Technology
AAIFに入ってみた ~内から見えるコミュニティ動向~
sato4
0
190
2026TECHFRESH畢業分享會 - Lightning Talk - 資料也要 CI/CD? 用 Airbyte 自動化資料同步
line_developers_tw
PRO
0
950
ACE-Step-1.5で見る 音楽生成AIのしくみと“破綻だけ直す”Retake機能の開発【zennfes spring 2026 登壇資料】
personabb
1
320
Bucharest Tech Week 2026 - Reinventing testing practices in the AI era
edeandrea
PRO
1
150
機械学習を「社会実装」するということ 2026年夏版 / Social Implementation of Machine Learning June 2026 Version
moepy_stats
5
2k
2026TECHFRESH畢業分享會 - AI 時代的人生存檔點
line_developers_tw
PRO
0
960
Disciplined Vibes: Scaling AI-Assisted Engineering
sheharyar
0
140
【NRUG vol.18】なぜ多くのオブザーバビリティ導入は失敗するのか
nrug_member
0
120
FinOps × AIエージェントで実現する コストインシデントの自動調査
oasis1994liveforever
0
130
protovalidate-es を導入してみた
bengo4com
0
180
Bedrock AgentCore RuntimeでAuth0 Changelog調査AIをアップグレードした話
t5u8a5a
1
120
【Cyber-sec+】経営層を"動かす"ための考え方
hssh2_bin
0
170
Featured
See All Featured
The Spectacular Lies of Maps
axbom
PRO
1
800
The Curse of the Amulet
leimatthew05
1
13k
A better future with KSS
kneath
240
18k
Ecommerce SEO: The Keys for Success Now & Beyond - #SERPConf2024
aleyda
1
2k
Keith and Marios Guide to Fast Websites
keithpitt
413
23k
Build The Right Thing And Hit Your Dates
maggiecrowley
39
3.2k
Digital Projects Gone Horribly Wrong (And the UX Pros Who Still Save the Day) - Dean Schuster
uxyall
1
1.7k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
32
2.9k
Leveraging Curiosity to Care for An Aging Population
cassininazir
1
270
Lightning talk: Run Django tests with GitHub Actions
sabderemane
0
200
A brief & incomplete history of UX Design for the World Wide Web: 1989–2019
jct
2
390
Building an army of robots
kneath
306
46k
Transcript
百度贴吧HHVM应用实践 夏绪宏
[email protected]
About me • 夏绪宏 (reeze) • 百度贴吧:LAMP基础技术及性能优化负责人 • Blog: reeze.cn
• Github: github.com/reeze • Email:
[email protected]
• Weibo: @reeze
• 有多少人知道HHVM? • 有多少人在用HHVM? • 方便的话发微博 “ @reeze 公司名称,HHVM版本”
Agenda 1. 为什么要用HHVM? 2. 贴吧PHP到HHVM迁移的收益 3. 迁移到HHVM的经验分享
百度贴吧概述 • 全球最大的中文社区 • 百亿流量 • 500+模块 • P级数据
百度贴吧概述 • 业务迭代快:开发效率要求 • 业务增长快:资源效率要求 • 每天100+次业务上线变更 • 服务器成本持续增加 :(
• 帖子列表页 • 150+模板组件 • 性能丌够好,业务复杂 • 精简业务?No Way! •
性能优化
层次化性能优化 • Nginx cache,长连接等 • 业务逻辑优化 • 性能优化 • 怎么做?
• Cache优化、网络性能调优
PHP运行环境性能优化 • fpm参数调优、扩展性能优化、opcache升级等 • PHP升级到最新版 •性能提升 •新功能 • 迁移到HHVM
HHVM简介 • Facebook开源项目 http://github.com/facebook/hhvm • PHP实现:HHVM (HipHop PHP Virtual Machine)
• 解决PHP运行效率问题 • 开发速度和效率兼得
进程模型对比
多线程模型vs多进程模型 • 优点 • 进程内通信效率高、连接池、共享状态容易 • 节省内存 • 可控性强 •
缺点(运维): • 内存泄露问题 • 单进程Crash整体挂掉
PHP版本性能对比 bench.php 耗时(s) mico_bench.php耗时(s) bench_third.php耗时(s) PHP 5.2 6.692 41.890 9.226
PHP 5.5 3.609 14.972 5.893 PHPNg 2.361 12.292 - HHVM 2.2 0.579 5.832 2.869
线下环境业务性能对比 纯业务耗时 idle Vs 5.2提升比 PHP 5.2 127ms 50% -
PHP 5.5 107ms 45% 15.7% HHVM 2.2 72ms 65% 43.3%
15 HHVM is fast • 类型推导 • JIT • 多级优化
其他因素 • 兼容性:98% (和主流开源程序) • 业界和公司有成功案例 • 活跃的社区
• Let’s give it a shot! (帖子列表模块)
迁移效果 • CPU使用率下降:11.9% • 性能提升:59%
尝试迁移HHVM • 响应时间下降:126ms • 平均提升:27% • 最终效果超预期
How much does it cost?
迁移HHVM成本 • 修改代码 34 行 非业务代码修改(php5.2 ->5.4升级) • 6个扩展升级 (hhvm扩展编写成本远小于php)
• 4周完成上线 • 一次性投入:后续模块1周内完成迁移
核心服务迁移到HHVM • 核心服务迁移到HHVM • 平均35%+性能提升,节约1/3的机器 • 计算密集性服务收益非常明显,最大的到67.5%的性能提升 • 还将继续迁移更多的服务到HHVM
23 迁移到HHVM的一些经验
24 迁移到HHVM的一些经验 •优先使用最新版(HHVM3.1): • 兼容性更好 •使用fastcgi模式: • 内置Webserver丌标准,后续也丌维护 •迁移扩展时留意线程安全的问题 •
Fpm的多进程和HHVM的多线程
25 迁移到HHVM的一些经验 •充分利用HHVM的AdminServer功能 • 内部数据和控制HTTP API接口(可用于自劢化监控和管理) • 服务控制:/stop 停服务 …
• 内存分析:/jemalloc-stats … • 性能分析:/jemalloc-prof-dump… • 服务状态数据:/status.json、/check-health、/dump-apc … • …
26 迁移到HHVM的一些经验 •配置ResourceLimit.MaxRSS最大内存限制 • 避免可能的内存泄露持续增长的问题 •使用supervisor启劢HHVM • 避免扩展或者HHVM本身crash对服务的影响 •前两者结合起来实现fpm应对内存泄露以及crash问题的能力,简单粗暴
27 迁移到HHVM的一些经验 •JIT内存持续增长问题 • 丌停的更新代码内存可能 会持续增长 •/vm-tcreset 接口清理 •还有supervisor 守护
28 迁移到HHVM的一些经验(编码) •少用eval() create_user_function() $$var等劢态特性 • PHP中一样,丌过HHVM中更丌推荐 •性能敏感代码尽量将逻辑放到函数中(JIT的特点) • 全局代码无法享受JIT的优点
•set_error_handler($callback, $level) 传递第二个参数,避免性能消耗 •性能丌敏感代码使用PHP代码编写 (hhvm支持内嵌php大妈),提高开发效率
Conclusion&Future • HHVM 对于普通应用有可观的性能提升,尤其适合计算密集型 应用,值得尝试 • 未来: • HHVM独有的特性考虑:Hack语言 •
针对HHVM的性能优化
Any Questions?