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
JRuby @ OpenFeint
Search
flyerhzm
November 19, 2012
Technology
23
3.1k
JRuby @ OpenFeint
一次JRuby迁移成功的案例
flyerhzm
November 19, 2012
Tweet
Share
More Decks by flyerhzm
See All by flyerhzm
玩转 AST
flyerhzm
0
160
Find and Replace Code based on AST
flyerhzm
0
230
Rails Performance Tips
flyerhzm
0
1.2k
Refactor ruby code based on AST
flyerhzm
4
3.5k
基于AST的代码优化
flyerhzm
10
780
Write ruby code to change ruby code
flyerhzm
5
3.5k
Building Asynchronous APIs
flyerhzm
25
8.9k
构建异步API服务
flyerhzm
19
7.2k
Other Decks in Technology
See All in Technology
ずっと昔に Star をつけたはずの思い出せない GitHub リポジトリを見つけたい!
rokuosan
0
150
AWS re:Invent 2024で発表された コードを書く開発者向け機能について
maruto
0
190
Oracle Cloud Infrastructure:2024年12月度サービス・アップデート
oracle4engineer
PRO
0
190
KubeCon NA 2024 Recap / Running WebAssembly (Wasm) Workloads Side-by-Side with Container Workloads
z63d
1
250
社外コミュニティで学び社内に活かす共に学ぶプロジェクトの実践/backlogworld2024
nishiuma
0
260
DevOps視点でAWS re:invent2024の新サービス・アプデを振り返ってみた
oshanqq
0
180
10個のフィルタをAXI4-Streamでつなげてみた
marsee101
0
170
Wantedly での Datadog 活用事例
bgpat
1
490
20241214_WACATE2024冬_テスト設計技法をチョット俯瞰してみよう
kzsuzuki
3
510
LINEヤフーのフロントエンド組織・体制の紹介【24年12月】
lycorp_recruit_jp
0
530
成果を出しながら成長する、アウトプット駆動のキャッチアップ術 / Output-driven catch-up techniques to grow while producing results
aiandrox
0
340
DevFest 2024 Incheon / Songdo - Compose UI 조합 심화
wisemuji
0
110
Featured
See All Featured
Build your cross-platform service in a week with App Engine
jlugia
229
18k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
29
2k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
44
6.9k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
132
33k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
251
21k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
330
21k
Side Projects
sachag
452
42k
GraphQLとの向き合い方2022年版
quramy
44
13k
It's Worth the Effort
3n
183
28k
How To Stay Up To Date on Web Technology
chriscoyier
789
250k
Keith and Marios Guide to Fast Websites
keithpitt
410
22k
The Straight Up "How To Draw Better" Workshop
denniskardys
232
140k
Transcript
JRuby @ OpenFeint 黄志敏 http://huangzhimin.com/2012/11/14/jruby-at-openfeint-jruby-migration-success-story/
JRuby 给 OpenFeint 带来 了40%的性能提升
关于OpenFeint • 最大的移动社交游戏平台 • 每分钟几十万的API调用 • 去年被GREE收购 • REE 1.8.7
+ Rails 2.3.14
关于我 • 黄志敏 Richard Huang (a.k.a flyerhzm) • 之前是OpenFeint资深工程师 现在是GREE咨询顾问
• 活跃于Ruby/JRuby的开源社区 • 个人主页 http://huangzhimin.com twitter, weibo, github: flyerhzm
为什么要尝试JRuby?
提高OpenFeint 服务器端的性能
Railsconf 2012
大多数人在抱怨Ruby的GC
Not a Vendor Pitch: Real World Rails Apps at Massive
Scale:: A Panel Discussion with New Relic, Groupon, Zendesk, Fanzter, and Uken http://railsconf2012.com/sessions/66
2场介绍JRuby的话题
Up and to the right – how Spiceworks is scaling
200 million requests per month http://railsconf2012.com/sessions/62
Complex Made Simple: Sleep Better with TorqueBox http://railsconf2012.com/sessions/16
快速性能测试
REE 1.8.7 2010.01 + passenger 331 ms JRuby 1.6.7.2 +
torquebox 51.5 ms 禁用mysql sharding,background job和其它无法工作的部分 部署在qa服务器上,memcached, redis, rabbitmq和app server在同一台机器 ree没有优化gc
JRuby迁移策略
fetch_friend_status OpenFeint基础设施 Load Balancers Web / App Servers Mysql Memcached
Redis Rabbitmq ......
fetch_friend_status OpenFeint基础设施 Load Balancers Web / App Servers Mysql Memcached
Redis Rabbitmq ......
fetch_friend_status OpenFeint基础设施 App服务器按功能拆分到不同的池 Load Balancers负载把请求分发到不同的池
JRuby迁移策略 一个池一个池地进行迁移
JRuby迁移策略 (优点) 人力投入少 更早地享受JRuby带来的高速 更早地发现问题 更快地积累线上运维的经验
JRuby迁移策略 (缺点) 必须保证代码可同时在REE和JRuby下运行 增加了部署的复杂度
替换不兼容的gem
yajl-ruby (x) hiredis (x) mysql => activerecord-jdbcmysql-adapter
typhoeus => net-http-persistent
memcached => jruby-memcached
启用 threadsafe http://jrubytips.com/posts/3-enable-threadsafe-for-rails
所有测试通过
JRuby往往需要更多的内存 JRUBY_OPTS=-J-Xmx2g jruby --client -S bundle exec rake test
在开发和测试环境使用CRuby 在生产环境使用JRuby http://jrubytips.com/posts/2-mri-for-development-and-test-while-jruby-for- production
选择JRuby服务器
Trinidad 基于 Tomcat Torquebox 基于 JBoss AS Mizuno 基于 Jetty
Puma 新的ruby server
Trinidad 基于 Tomcat Torquebox 基于 JBoss AS Mizuno 基于 Jetty
Puma 新的ruby server (rack 版本问题)
Trinidad 基于 Tomcat Torquebox 基于 JBoss AS (运行最快,团队维护) Mizuno 基于
Jetty Puma 新的ruby server (rack 版本问题)
torquebox-lite
监控JVM
REE监控 NewRelic Scout
JRuby监控 NewRelic Scout + JMX Monitoring Plugin Zabbix (没上)
JRuby监控 http://jrubytips.com/posts/6-monitor-jvm 命令行工具 jstat, jstack, jmap 图形化工具 jconsole, visualvm
JVM 相关的问题
内存泄漏
内存无法回收
内存无法回收 频繁执行Full GC 性能急剧下降
线程安全问题
ActiveRecord 2.3.14 线程池 不安全! https://gist.github.com/3882854
ActiveRecord 2.3线程池 不安全! 线程死锁 吞吐量逐渐下降
优化JVM Xms Xmx CodeCache http://jrubytips.com/posts/4-set-proper-value-for- codecache ......
性能测试
read action write action REE 1.8.7 2010.01 + passenger 448
ms 44 ms Ruby 1.9.3 p194 + passenger 374 ms 42 ms JRuby 1.7.0.RC2 + torquebox-lite 187 ms 38 ms 在备机上进行测试 连接产品环境的mysql, memcached, redis, rabbitmq等等 REE使用Twitter提供的GC优化
部署策略
热部署 touch /opt/torquebox/current/jboss/standalone/deployments/openfeint_pla tform-knob.yml.dodeploy 30s 左右的宕机时间 non heap memory 每次都会增加
Rolling restart sudo /etc/init.d/jboss-as-standalone restart 1. 从LB中移除服务器A 2. 在服务器A上重启JBOSS 3.
把服务器A加回到LB中 4. 对每台服务器重复以上操作 零宕机 http://jrubytips.com/posts/5-zero-downtime-deployment
上线之后效果如何?
性能提升 ~ 40%
None
invokedynamic?
bug 18:29:03,515 ERROR [org.torquebox.core.runtime] (Thread-71) Error during execution: ENV['RAILS_ROOT']=RACK_ROOT ENV['RAILS_ENV']=RACK_ENV
require %q(org/torquebox/web/rails/boot) : org.jruby.exceptions.RaiseException: (LoadError) load error: haml/buffer -- java.lang.NoClassDefFoundError: org/jruby/runtime/ThreadContext at org.jruby.RubyKernel.require(org/jruby/RubyKernel.java:1010) [jruby.jar:] at ActiveSupport::Dependencies::Loadable.require (/home/deploy/rails_apps/openfeint_platform/shared/bundle/jruby/1. 8/gems/activesupport-2.3.14/lib/active_support/dependencies.rb:182)
期待invokedynamic带来 更多的性能优化
感谢 JRuby team 感谢 Torquebox team
谢谢 提问