讓Ruby效能增加30%的改進方法分析

來源:互聯網
上載者:User

我們都知道在編譯Ruby的時候你需要使用configure的 --disable-pthread參數。沒錯,在configure --disable-pthread 可以讓你得到大約 30% 效能提高。但是,這是為什麼呢?

所有的這一些我們需要使用 strace 工具,這個工具可以打出所有的真實的作業系統的調用。

下面,是一段我們測試的常式:

def make_thread Thread.new {  a = []  10_000_000.times {   a << "a"   a.pop  } }endt = make_threadt1 = make_threadt.joint1.join

如果我們使用 strace 工具去測試 configure --enable-pthread 版本的Ruby引擎,那麼我們可以得 到下面這樣的結果:

22:46:16.706136 rt_sigprocmask(SIG_BLOCK, NULL, [], 8 ) = 0 <0.000004>22:46:16.706177 rt_sigprocmask(SIG_BLOCK, NULL, [], 8 ) = 0 <0.000004>22:46:16.706218 rt_sigprocmask(SIG_BLOCK, NULL, [], 8 ) = 0 <0.000004>22:46:16.706259 rt_sigprocmask(SIG_BLOCK, NULL, [], 8 ) = 0 <0.000005>22:46:16.706301 rt_sigprocmask(SIG_BLOCK, NULL, [], 8 ) = 0 <0.000004>22:46:16.706342 rt_sigprocmask(SIG_BLOCK, NULL, [], 8 ) = 0 <0.000004>22:46:16.706383 rt_sigprocmask(SIG_BLOCK, NULL, [], 8 ) = 0 <0.000004>

你會發現上面的sigprocmask 系統調用一頁一頁又一頁地沒完沒了的。如果你用 strace -c,你會發 現一共大約20,054,180 個sigprocmask系統調用。但是,如果你是在--disable-pthread 的Ruby版本下運 行,你會發現根本沒有那麼多的sigprocmask 系統調用(只有 3 次,簡直就是天壤之別)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.