<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                # sleep 這是一個比較常見的功能,你會怎么做呢?Google一下,你會找到[Lua的官方指南](http://lua-users.org/wiki/SleepFunction), 里面介紹了10種sleep不同的方法(操作系統不一樣,方法還有區別),選擇一個用,然后你就杯具了:( 你會發現nginx高并發的特性不見了! 在OpenResty里面選擇使用庫的時候,有一個基本的原則:***盡量使用ngx Lua的庫函數,盡量不用Lua的庫函數,因為Lua的庫都是同步阻塞的。*** ~~~ # you do not need the following line if you are using # the ngx_openresty bundle: lua_package_path "/path/to/lua-resty-redis/lib/?.lua;;"; server { location /non_block { content_by_lua_block { ngx.sleep(0.1) } } } ~~~ 本章節內容好少,只是想通過一個真實的例子,來提醒大家,做OpenResty開發,[ngx-lua的文檔](http://wiki.nginx.org/HttpLuaModule)是你的首選,Lua語言的庫都是同步阻塞的,用的時候要三思。 再來一個例子來說明阻塞API的調用對nginx并發性能的影響 ~~~ location /sleep_1 { default_type 'text/plain'; content_by_lua_block { ngx.sleep(0.01) ngx.say("ok") } } location /sleep_2 { default_type 'text/plain'; content_by_lua_block { function sleep(n) os.execute("sleep " .. n) end sleep(0.01) ngx.say("ok") } } ~~~ ab測試一下 ~~~ ? nginx git:(master) ab -c 10 -n 20 http://127.0.0.1/sleep_1 ... Requests per second: 860.33 [#/sec] (mean) ... ? nginx git:(master) ab -c 10 -n 20 http://127.0.0.1/sleep_2 ... Requests per second: 56.87 [#/sec] (mean) ... ~~~ 可以看到,如果不使用ngx_lua提供的sleep函數,nginx并發處理性能會下降15倍左右。 # 為什么會這樣? 原因是sleep_1接口使用了ngx_lua提供的非阻塞API,而sleep_2使用了系統自帶的阻塞API。前者只會引起(進程內)協程的切換,但進程還是處于運行狀態(其他協程還在運行),而后者卻會觸發進程切換,當前進程會變成睡眠狀態, 結果CPU就進入空閑狀態。很明顯,非阻塞的API的性能會更高。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看