Ruby China 背后的故事

4035ddfe11dbb2afc4e683b1bc6ac68f?s=47 Jason Lee
October 10, 2015

Ruby China 背后的故事

4035ddfe11dbb2afc4e683b1bc6ac68f?s=128

Jason Lee

October 10, 2015
Tweet

Transcript

  1. Ruby China ᙧݸጱඳԪ ๫܏ᶲ 2015 ruby-china.org

  2. ӻՈՕᕨ - Ruby China ᐒ܄ᓕቘާ̵Ԇᥝ୏ݎᘏ̵ڠতՈ - ፓڹ੪ᘳԭඪ՞ਪ - ٟԧঅग़ଙ Rails

    ଫአٟ҅ᬦᦜग़ Gem - ڠᒈԧ ruby.taobao.org @huacnlee
  3. “ Let's Party! — @Rei 2011-10-28

  4. ፓڹఘ٭Օᕨ

  5. ๦শ̵ଚӬࠔӞጱ Ruby Ӿ෈ᐒ܄

  6. ᮱ᗟᯈᗝ • UCloud VPS Ԇ๢Ҕ • 1 ݣ 4 Core

    CPU VPS; • 4GB ٖਂҔ • MongoDB̵Cache ࣁݶӞݣ๢࢏ӤҔ • UpYun ಓᓕӤփ෈կ҅Assets҅զ݊൉׀ Assets CDN ๐ۓҔ • 5M ଃ਼ᇿՁኪמ + ᘶ᭗ᗑᕶҔ
  7. ᩻ᬦ 20K տާ̵27K ᓤૼৼզ݊ 270K ࢧૼ 0 2500 5000 7500

    10000 12500 15000 17500 20000 22500 25000 27500 30000 2011 2012 2013 2014 Now տާᰁ 0 5000 10000 15000 20000 25000 30000 2011 2012 2013 2014 Now ᦾ᷌ 0 50000 100000 150000 200000 250000 300000 2011 2012 2013 2014 Now ࢧ॔
  8. 3953 Ոᛗ੝ݎᬦӞེᩂ Topic.pluck(:user_id).uniq.count Reply.pluck(:user_id).uniq.count 7802 Ոᛗ੝ࢧᬦӞེᩂ 0 50 100 150

    200 250 300 350 400 0 500 1000 1500 2000 2500 3000 3500 4000 4500 5000 5500 6000 6500 7000 rei huacnlee lgn21st luikore kgen bhuztez blacktulip chairy11 ibachue hooooopo ࢧૼᰁ ݎૼᰁ
  9. ଘ࣐ྯॠ 13K ӻᇿᒈᦢਮ҅զ݊ 30K ེᶭᶎᦢᳯᰁ Google ړຉᕹᦇᦢᳯᰁ 0 4,000 8,000

    12,000 16,000 20,000 24,000 28,000 32,000 36,000 40,000 8์25෭ 8์30෭ 9์4෭ 9์9෭ 9์14෭ 9์19෭ 9์24෭ ᦢਮ ၨᥦᰁ
  10. UpYun ਂؙྯ์᧗࿢ᕹᦇ ၞᰁ(GB) 0 30 60 90 120 150 180

    210 240 ᧗࿢ᰁ(ེ) 0 800000 1600000 2400000 3200000 4000000 4800000 5600000 6400000 7200000 8000000 2013-05 2013-11 2014-05 2014-11 2015-05 2015-09 ᑮᳵܛአ: 1.11 GB
  11. ᕅ 900 ਹلݪݎ૲ᬦ Ruby ፘىᘳ֖מ௳ Topic.where(node_id: Node.jobs_id).pluck(:user_id).uniq.count

  12. And…

  13. ୮֦ Google ൤ᔱ

  14. None
  15. None
  16. None
  17. ݎ઀ᬦᑕ

  18. Homeland - ੜ܄ᦞࣚᶱፓ https://github.com/huacnlee/homeland/tree/single-app-rails-3.0

  19. Shanghai on Rails

  20. chinaonrails.com

  21. – 2012-05-10 “ٌਫইຎ chinaonrails ԏڹঅঅදᇇӞӥ҅ ౯֌ᦇ੪ӧտํՔॠጱ Ruby China ԧ” https://ruby-china.org/topics/3223#reply4

  22. None
  23. - ୏তԭ 2010-8҅ᒫӞӻᇇ๜ฎ Ruby 1.9.2̵Rails 3.0.0.rc2; - ๋ڡฎ MySQL ପ;

    - ᬮဌํአ Markdown҅ݝฎᓌܔጱ simple_format ໒ୗ۸Ҕ - ဌํ᭗ᎣۑᚆҔ - ݝฎᓌܔጱړᔄ̵ᦾ̵᷌ࢧ̵॔ᦕԪ๜پӻۑᚆҔ - ᶋଉᓌܔጱݸݣኴᶎҔ - ᛔګᓌܔጱአಁᔮᕹҔ
  24. None
  25. None
  26. None
  27. source 'http://rubygems.org'
 
 gem 'rails', ‘3.0.0.rc2'
 gem 'mysql2'
 gem ‘paperclip'

    gem 'authlogic'
 gem 'will_paginate', '3.0.pre' 
 gem 'memcache-client'

  28. def index
 @topics = Topic.last_actived.includes(:user,:node).limit(10)
 @sections = Section.all.includes(:nodes)
 end
 


    def show
 @topic = Topic.find(params[:id])
 if current_user
 Node.set_user_last_visited(current_user.id, @topic.node_id)
 @topic.user_readed(current_user.id)
 end
 @node = @topic.node
 @replies = @topic.replies.all
 end
 
 def reply
 @topic = Topic.find(params[:id])
 @reply = @topic.replies.build(params[:reply]) 
 @reply.user_id = current_user.id
 if @reply.save
 flash[:notice] = "ࢧ॔౮ۑ"
 else
 flash[:notice] = @reply.errors.full_messages.join("<br />")
 end
 redirect_to topic_path(params[:id],:anchor => 'reply')
 end
  29. Ruby Tuesday @ Hangzhou ᭬ᥠ @lgn21st

  30. Ӟޮݸ…

  31. None
  32. ᇔᜋෛጱๅग़ጱ݇Өᘏ @hooopo @chloerei Twitter̵V2EX̵GitHub զٌ݊՜ Ruby ᐒ܄ၚ᪋ړৼ @liuzihua

  33. Design by @QCee https://ruby-china.org/topics/8

  34. GitCafe

  35. source 'http://rubygems.org'
 
 gem "rails", "3.1.1"
 gem "mongoid", "2.2.4"
 gem

    'carrierwave', '0.5.6'
 gem 'mini_magick','3.3'
 gem 'mongoid_auto_increment_id', "0.2.2"
 gem "devise", "1.4.5"
 gem 'will_paginate', '3.0.pre2'
 gem 'omniauth', '0.3.0'
 gem "oa-openid", '0.3.0'
 gem 'dalli', '1.1.1' … gem "rails-i18n","0.1.8"
 gem 'redis-namespace','~> 1.0.2'
 gem "redis-objects", "0.5.2"
 gem "rdiscount","1.6.8"
 gem "settingslogic", "~> 2.0.6"
 gem "cells", "3.6.7"
 gem "resque", "~> 1.19.0", :require => "resque/server"
 gem "aws-ses", "~> 0.4.3"
 gem 'mail_view', :git => 'git://github.com/37signals/mail_view.git'
 gem "daemon-spawn", "~> 0.4.2"
 #
 gem "sprite-factory", "1.4.1"
 group :development do
 gem 'capistrano', '2.9.0'
 gem 'chunky_png', “1.2.5" gem 'factory_girl_rails'
 end
  36. def index
 @topics = Topic.last_actived.limit(10)
 @sections = Section.all
 render :stream

    => true
 end
 
 def show
 @topic = Topic.find(params[:id])
 @topic.hits.incr(1)
 @node = @topic.node
 @replies = @topic.replies.asc(:_id).all.cache
 if current_user
 @topic.user_readed(current_user.id)
 current_user.notifications.where(:reply_id.in => @replies.map(&:id), :read => false).update_all(:read => true)
 end
 render :stream => true
 end
  37. • ruby-china.org ऒݷҔ • Linode ᮱ᗟҔ • ෛጱ UIҔ •

    ᦾ᷌ྋ෈ MarkdownҔ • ीے Wiki ۑᚆ̵ඪ೮դᎱṛՄҔ • Devise ๊դአಁᔮᕹ; • Mongoid, Assets Pipeline, Carrierwave, redis-objects, cellsҔ • ीے Notification ۑᚆҔ • Ծڊ mongoid_auto_increment_idҔ
  38. RubyConf China 2011 ੒क़ل૲ Ruby China

  39. ୏তႀفय़ᰁጱአಁ ྋୗᬰفᬩ០

  40. ӞԶݎ઀ොݻ • വۖᕟᕢ RubyConf China ၚۖҔ • Ӥၹ̵๺૞̵۹Ղӣࣈ᷇ᔺጱ Ruby Tuesday

    ᕚӥၚۖҔ • Ruby ᆽঅᘏ T ௫Ҕ • ෆቘෛಋفᳪᩒා WikiҔ • ڠᒈ GitHub Ruby China ୏რੜᕟҔ • ᘉᦲ Ruby ᐒ܄ᅾᳪದ๞ᩒාҔ • ᤉኞ RailsCast China̵TeaHour;
  41. None
  42. None
  43. ଚധԏڹਂࣁጱݱᐿ Ruby Ӿ෈ᗑᒊ rubybbs.com rubycn.org thoughtrails.com chinaonrails.com shanghaionrails ruby-lang.org.cn

  44. by XiaoBo Liu

  45. GitHub Ӥᶎڠᒈ Ruby China ᕟ @ashchan @lgn21st @chloerei @huacnlee

  46. huacnlee/ruby-china ruby-china/ruby-china ՗ӻՈݒ౮ࢫᴚ

  47. GitHub Ӥ୏তڊሿஉग़ጱᨯሠᘏ

  48. 2400 ེ Commit, 105 ᨯሠᘏ ᩻ᬦ 5 ེ Commit ጱํ

    21 Ո 0 175 350 525 700 875 1050 1225 1400 huacnlee xdite chloerei ashchan forresty doitian qichunren xiaods fredwu bachue 10 11 19 23 37 40 83 88 185 1,394 Commits
  49. > rake stats +----------------------+-------+-------+---------+---------+-----+-------+ | Name | Lines | LOC

    | Classes | Methods | M/C | LOC/M | +----------------------+-------+-------+---------+---------+-----+-------+ | Controllers | 1793 | 1471 | 37 | 208 | 5 | 5 | | Helpers | 489 | 414 | 0 | 54 | 0 | 5 | | Models | 1841 | 1424 | 27 | 146 | 5 | 7 | | Mailers | 16 | 15 | 2 | 1 | 0 | 13 | | Javascripts | 7633 | 5866 | 1 | 694 | 694 | 6 | | Libraries | 708 | 500 | 8 | 46 | 5 | 8 | | Api specs | 1024 | 886 | 0 | 1 | 0 | 884 | | Controller specs | 720 | 613 | 0 | 0 | 0 | 0 | | Feature specs | 37 | 33 | 0 | 0 | 0 | 0 | | Helper specs | 461 | 378 | 0 | 0 | 0 | 0 | | Lib specs | 620 | 470 | 3 | 0 | 0 | 0 | | Model specs | 1405 | 1185 | 3 | 0 | 0 | 0 | | Request specs | 51 | 40 | 0 | 0 | 0 | 0 | | Routing specs | 21 | 17 | 0 | 0 | 0 | 0 | | View specs | 35 | 27 | 0 | 0 | 0 | 0 | +----------------------+-------+-------+---------+---------+-----+-------+ | Total | 16854 | 13339 | 81 | 1150 | 14 | 9 | +----------------------+-------+-------+---------+---------+-----+-------+ Code LOC: 9690 Test LOC: 3649 Code to Test Ratio: 1:0.4
  50. GitHub Issues 2015 Open Issue 30 Closed Issue 230 Closed

    PR 54 Merged PR 127 Open PR 3 Open PR Merged PR Closed PR Closed Issue Open Issue
  51. ኧᗑ݋Ծኞ • य़ᰁጱ Ruby դᎱ᯿຅Ҕ • ୚فၥᦶҔ • @ ӥ೉൉ᐏҔ

    • Markdown ᶼᥦҔ • ग़᧍᥺ඪ೮Ҕ • APIҔ • ᕷय़ग़හฎ Bug ץྋզ݊ੜදᬰҔ
  52. ᮎԶᤩ೏ᕷധጱۑᚆ • ᐺמ • ஙמړՁ • Internet Explorer ඪ೮ •

    ىဳՈҁ๋ڡጱ෸ײ҂ • ଆۗڦՈᖫᬋૼৼ • Vote Up / Down
  53. உग़ PR ဌݳଚฎਠ࠺ଶጱᳯ᷌ UI̵Ի԰̵෈ໜᕡᜓ̵ၥᦶ̵॔๥ଶ̵սضᕆ…

  54. ᑕଧާ౜ᦡᦇஉ᯿ᥝ Ruby China ጱ౮ۑ҅޾“ᦡᦇ”ํӞਧىᔮ

  55. உग़ۑᚆ ٌਫฎሿࣁဌᑮਫሿ

  56. ౲ᘏฎ

  57. ౡ̵೒୊ዩ… ྲই KeyNotes ೒کԧ 9 ์ବ

  58. ୮ᆐ

  59. ํԶۑᚆ֦ӧӞਧᥝਫ ሿ౲ḘӤਫሿ ֺইғىဳ̵᭗Ꭳ̵ق෈൤ᔱ

  60. ےቔ੪ฎᮎԍ๶ጱ

  61. ౯ᅾᆽᬯӻᶱፓ

  62. ෸ଉտᎸᑪྯӻᕡᜓ॒ጱਫሿ

  63. ݱᐿ Ruby ᐒ܄ጱದ๞ࣁӤᶎ੤ ᦶԧӞ᭭ JRuby Faya Rubinius ݱᐿ Benchmark ړຉૡٍ

    Rails ෛڊጱۑᚆ
  64. ้ᕪ൥ࣕᬦහഝପ ਣ๢ᬦঅग़ེҁ᮷ฎ޾ݎ૲ํى҂ ॓ղஉ᯿ᥝ

  65. ᑞਧጱ෸ײᬮฎᇙڦᑞਧጱ

  66. Unicorn ᬰᑕٖਂᑞਧࣁ 212m ᑞਧ᪒ԧ 11 ॠ

  67. ᶲ׎᧔Ӟӥ ٖਂအᶂӞਧฎय़ग़හ෸ײฎ ଫአጱᳯ᷌

  68. य़᮱ړ෸ײฎࣁ੤ᦶ፡ Ruby̵ Rails ฎވᬮᚆ᪒஑ๅள ܨֵᶱፓሿࣁ૪ᕪ᪃ड़ளԧ

  69. ፓຽฎ 100ms զٖጱߥଫ෸ᳵ ሿࣁፓຽ૪Ӥ܋ک 50ms զٖԧ

  70. ୮ᆐԞࢩྌත឴உग़

  71. Ruby China ᶱፓݱӻᴤྦྷىᲫᶭᶎߥଫ෸ᳵ੒ྲ Response Time (ms) 50 100 150 200

    250 300 350 400 450 500 550 600 650 700 750 800 / /topics /topics/:id /topics/node:id /:login Homeland (Rails 3.0) 2011-11 (Rails 3.1) 2013-05 (Rails 3.2) 2013-12 (Rails 4.0) 2014-05 (Rails 4.1) Now (Rails 4.2)
  72. • ᓌ۸᭦ᬋ֦҅፥ጱᵱᥝᮎԍ॔๥ጱۑᚆҘ • ӧᥝ஺ኼԧڹᒒጱපሲҔ • य़᮱ړ෸ᳵ᮷ᜰࣁ View Ӥᶎ҅Fragment CacheҔ •

    ᭿ع॔๥᭦ᬋ҅՗ۑᚆ޾ຝ຅Ӥᶎכ೮᪃ड़ጱᓌܔҔ • ຤ԶԪఘݢզԻᕳ JavaScript ๶॒ቘҔ • ग़፡ Rails API ෈໩҅ݎሿྋᏟጱֵአොୗ҅ྲই render collection: itemsҔ • MRI Ruby ࣁ IO ጱ᮱ړٌਫݢզአ Thread ਫሿଚᤈጱҔ • Gem ጱෛᇇ๜ݢզտํ௔ᚆ޾ٖਂጱץ॔҅ىဳ Changelog, PR; • ഩൎྋᏟጱ᮱ᗟොୗ҅GC ᧣ս; • ဳ఺֦አጱ Gem ٖਂ୏ᲀҔ
  73. ړຉ֦ጱଫአ

  74. https://tunemygc.com/ TuneMyGC ᧣ս GC

  75. - evanphx/benchmark-ips - ӧᥝ௛ฎ“౯ᥧ஑”֦҅ଫᧆᖫٟ Benchmark ၥᦶ੒ྲҔ - MiniProfiler/rack-mini-profiler - ᕳଫአ಑ᅩ҅ړຉᘙ෸Ҕ

    - rails/rails-perftest - ᕳଫአᖫٟ௔ᚆၥᦶአֺҔ - SamSaffron/memory_profiler - ړຉᑕଧݱӻ᧣አ຾ٖਂ୏ᲀ҅ allocated ੒᨝ེහ҅ݎሿᩇٖਂጱ GemҔ - ruby-prof/ruby-prof - चԭդᎱྦྷጱړຉҔ
  76. ଚݎ IO ᧗࿢ def index
 @threads = []
 @threads <<

    Thread.new do
 @suggest_topics = Topic.suggest.limit(3)
 end
 
 @threads << Thread.new do
 @topics = Topic.last_actived
 if current_user
 @topics = @topics.without_nodes(current_user.blocked_node_ids)
 @topics = @topics.without_users(current_user.blocked_user_ids)
 else
 @topics = @topics.without_hide_nodes
 end
 @topics = @topics.paginate(page: params[:page], per_page: 22)
 end
 @threads.each(&:join)
 end
  77. ํපڥአ updated_at ਫሿᖨਂ <% cache([reply]) do %>
 <div class="reply">
 ...


    </div>
 <% end %> irb> reply.cache_key
 "replies/256261-20150825031859640000000"
  78. Rails 3.0.0 … 4.2.x ۱ೡݱᔄ Gems̵Bootstrap Ruby China - ೮ᖅ᭄ᵋ

    Rails ᇇ๜܋ᕆ Ruby 1.9.3 … 2.2.3
  79. Homeland

  80. 2011-11 - v1

  81. 2013 - v1.1

  82. 2014-5 - V1.3

  83. Now

  84. • ੱݢᚆ᭽஗ Rails ๋֯ਫ᪢๶ਫሿ֦ጱݱӻۑᚆҁLess SQL҅ Router URL҅Helper҅ຽٵ CURD҅ERB)Ҕ • ࠺አ

    ActiveModel ጱ ScopeҁTopic.last_actived.without_hide_nodes҂ • ࠺አ Helper ᓌ۸ Viewҁuser_name_tag, user_avatar_tag҂ • ෸ڰىဳ Rails ۖா᭄҅ᇇ๜҅ᛗ੝Ӿ֖හҁ4.x.0҂ᇇ๜Ҕ • ىဳᶱፓ໐ஞۑᚆጱᔄପࣁ GitHub Ӥጱๅෛۖா҅ํᚆێݢզ݇ Өਠ࠺Ҕ • ੱݢᚆጱٺ੝ᛔ૩ጱդᎱᰁ҅ᚆአପጱࣈොአପᥴ٬ᳯ᷌҅ྲইӤ փ̵ړᶭ҅๦ᴴ̵ᴚڜᬯԶ Ruby ᐒ܄૪ᕪᶋଉ౮ᆧጱᶱፓᔄࣳҔ
  85. ੪ᬯԶԧ

  86. ౯ժՖࣁ੔ತ Ruby China ᓕቘާളቔՈ

  87. • ᅾᆽ Ruby̵Rails; • ڹݸᒒ඘ᳩҔ • ౜Ի԰ᦡᦇ҅Ꭳ᭲ই֜؉অጱԾߝҔ • ॒ঀଷጱ؉Ԫᷚ໒҅ဳ఺ᕡᜓҁݷ᦯य़ੜٟ҅Ӿ᝕෈ ᑮ໒҂Ҕ

  88. ইຎ֦ᒧݳ Ԟ૶๕̵ౄ఺ԅ Ruby Ӿ෈ᐒ܄ጱݎ઀ᨯሠێᰁ ᧗ᘶᔮ౯

  89. END

  90. - @huacnlee - huacnlee@gmail.com QA