Ruby应用性能调优实践

7136495c6cf767acfa63d1a8b84f2bb9?s=47 Li Zhe
October 12, 2015

 Ruby应用性能调优实践

了解Ruby的性能调优关键,以及都有哪些工具可以利用

7136495c6cf767acfa63d1a8b84f2bb9?s=128

Li Zhe

October 12, 2015
Tweet

Transcript

  1. Rubyଫአ௔ᚆ᧣սਫ᪢ ๫߽ - OneAPM 2015.10.10

  2. ञ຾ฎՋԍҘ

  3. ञ: ݰԧ੪೉ ຾: ݰԧ੪ݺ

  4. ֦మݰᗤᶟҘ ඓԀ୏ஞހҘ ౯݄ԧ୊ᬟѺ

  5. ڹݶԪ { ڹݶԪ }

  6. ӳ۹Ոࣁଠ૞

  7. ಍ৼ֯Ո

  8. ۹Ղཛྷୗ୏ސ …

  9. ํᅩᔲୟ …

  10. ౯ժฎଗՋԍጱ? • OneAPM • ௔ᚆፊഴଘݣ • 2015ଙڡਠ౮C᫪ᣟᩒ • 350Ո •

    ᬪ200ՈฎᎸݎ • قࢵԆᥝITउ૱᮷ํړلݪ౲ېԪ॒
  11. ౯ฎ᧡Ҙ • ๫߽ • Java 2007 ~ 2010 • Ruby

    2011 ~ Now • ፓڹ੪ᘳOneAPM - RubyAgent, Cloud Insight • github.com/markgeek • douban.com/people/markgeek/
  12. ౯ժ๶ᘱᘱRails ౌ ᬯկԪ

  13. ౲ᘏฎRack ౌ ᬯկԪ

  14. ٌਫฎRuby ౌ ᬯկԪ

  15. ֦ᦊԅRubyౌހҘ ౌጱᤒሿฎՋԍҘ ፥ጱฎ᧍᥺๜᫝᭜౮ጱހҘ ᦶ፳አૡٍ༄ၥᬦހҘ

  16. 30%զӤጱౌฎ՗ຝ຅Ӥ᧣սጱ

  17. – ӧᎣ᭲ฎ᧡᧔ጱ “ᑕଧާ᮷ฎࡅෛܵ෯ጱਹվ̶”

  18. ӞӻRubyଫአ • 2000ଚݎ • क़᮱ߥଫ෸ᳵ300ms • ଫአߥଫ෸ᳵ < 150ms •

    4ݣԆ๢ / 8core,8G • nginx, goliath, grape, redis
  19. None
  20. None
  21. ፡፡RubyጱचᏐܲݥ

  22. RubyVMጱݎ઀ܲݥ • 1.9 Koichi Sasada : YARV • 1.9 Narihiro

    Nakamura ғLazySweep • 2.0 Narihiro Nakamura ғBitmap Marking GC • 2.1 Koichi Sasada ғGenerational Collector • 2.2 Koichi Sasada ғIncremental Generational Collector
  23. http://tmm1.net/ruby21-rgengc

  24. Rubyጱᬩᤈ᭛ଶӞፗࣁ൉܋

  25. ӞԶच๜༷ஷ • Benchmark • Profiling • Tracing • Debugging

  26. Benchmarkғ᪒ړ

  27. benchmark, benchmark-ips

  28. Profilingғᦕ୯ᬩᤈ෸מ௳

  29. None
  30. RubyProf,StackProf

  31. Tracingғᦕ୯ොဩ᧣አמ௳

  32. rbtrace,allocation_tracer

  33. Ӟӻੜጱbenchmark

  34. Ruby Performance

  35. 1.98 / 1.14 = 1.7368…

  36. None
  37. RubyProf • flat - Prints a flat profile as text

    (default). • dot - Prints a graph profile as a dot file • call_stack - prints a HTML visualization of the call tree • call_tree - format for KCacheGrind
  38. None
  39. None
  40. None
  41. None
  42. StackProf • CPUཛྷୗ • ੒᨝ړᯈཛྷୗ • middlewareཛྷୗ

  43. None
  44. None
  45. None
  46. rbtrace • rbtrace -p <PID> —firehose • rbtrace -p <PID>

    —slow=<N> • rbtrace -p <PID> --methods "Kernel#sleep" “Proc#call" • rbtrace -p <PID> --gc
  47. Ꮯਧኒ᷀ԏݸ • fast-ruby • fasterer

  48. Ӟӻਫᴬጱֺৼ

  49. None
  50. None
  51. ݚक़ጱӞԶૡٍ

  52. http://rbkit.codemancers.com/

  53. https://github.com/peek/peek-rblineprof

  54. https://github.com/MiniProfiler/rack-mini-profiler

  55. ইຎ֦੒ବ੶உఽي᪁ Dtrace / SystemTap

  56. ݳᭇጱૡٍ؉ݳᭇጱૡ֢

  57. Rubyਖ਼տᬩᤈጱๅள

  58. – Yukihiro 'Matz' Matsumoto “Super Dry Ruby”

  59. https://www.youtube.com/watch?v=bqWBB8-iEac&list=PLE7tQUdRKcyZdMYKatu_nics8Pkjxl3-F

  60. ই֜೮ᖅጱፊഴଫአ ጱ௔ᚆᳯ᷌

  61. Application Performance Monitor or Application Performance Management

  62. None
  63. None
  64. ӧՐՐฎᬯԶ

  65. None
  66. None
  67. ୏რᩒრ • https://github.com/JuanitoFatas/fast-ruby • https://github.com/DamirSvrtan/fasterer • https://github.com/schneems/derailed_benchmarks • https://github.com/change/method_profiler •

    https://github.com/schneems/heapy • https://github.com/peek/peek-rblineprof • https://github.com/tmm1/rblineprof
  68. ݇ᘍᩒා1 • https://engineering.heroku.com/blogs/2015-02-04-incremental-gc/ • http://tmm1.net/ruby21-rgengc/ • https://www.youtube.com/watch?v=nRehkd22j78&spfreload=10 • https://avsej.net/2012/systemtap-and-ruby-20/ •

    https://www.shopify.com/technology/16777156-tuning-rubys-global-method-cache • https://www.youtube.com/watch?v=pZ_BcEcFGj0 • http://www.atdot.net/~ko1/activities/2015_railsconf.pdf • http://samsaffron.com/archive/2013/11/22/demystifying-the-ruby-gc
  69. ݇ᘍᩒා2 • http://www.theirishpenguin.com/2009/10/29/understanding-how-ruby-stores- objects-in-memory-the-ruby-heap.html • http://samsaffron.com/archive/2013/11/22/demystifying-the-ruby-gc • http://thorstenball.com/blog/2014/03/12/watching-understanding-ruby-2.1- garbage-collector/

  70. https://github.com/mattbaker/ruby-heap-viz

  71. ᨀᨀ Q&A