日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 人文社科 > 生活经验 >内容正文

生活经验

OpenResty上各种测试用例实操(1)

發布時間:2023/11/27 生活经验 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 OpenResty上各种测试用例实操(1) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

下面記錄了我閱讀《OpenResty最佳實踐》過程中對一些例子的實踐操作示例,記錄以作備忘。

一.Location的組合使用

演示一個location只作為內部調用接口,被另一個location調用

reload配置文件后,在終端輸入

更復雜一些的情況:

有多個子請求來并行或串行調用,它們的執行時間的比較,下面是改造后的nginx.conf

worker_processes 1;
error_log logs/error.log;
events {worker_connections 1024;
}http {server{listen 6699;location = /sum {internal;content_by_lua_block{ngx.sleep(0.1)local args = ngx.req.get_uri_args()ngx.say(tonumber(args.a) + tonumber(args.b))}}location = /subduction {internal;content_by_lua_block{ngx.sleep(0.1)local args = ngx.req.get_uri_args()ngx.say(tonumber(args.a) - tonumber(args.b))}}location = /app/test_parallels {content_by_lua_block{local start_time = ngx.now()local res1, res2 = ngx.location.capture_multi({{"/sum", {args={a=3, b=8}}},{"/subduction", {args={a=3, b=8}}}})ngx.say("status:", res1.status, " response:", res1.body)ngx.say("status:", res2.status, " response:", res2.body)ngx.say("time used:", ngx.now() - start_time)}}location = /app/test_queue {content_by_lua_block{local start_time = ngx.now()local res1 = ngx.location.capture_multi({{"/sum", {args={a=3, b=8}}}})local res2 = ngx.location.capture_multi({{"/subduction", {args={a=3, b=8}}}})ngx.say("status:", res1.status, " response:", res1.body)ngx.say("status:", res2.status, " response:", res2.body)ngx.say("time used:", ngx.now() - start_time)}}location / {default_type text/html;content_by_lua_block {ngx.say("Hello World!")}}}
}

檢查nginx.conf語法正確后,熱加載nginx


在命令行輸入如下命令進行對比測試,發現當兩個子請求沒有依賴關系時,并行比串行效率高一倍

另一個場景是,外部重定向,可以跨域名的。例如從 A 網站跳轉到 B 網站是絕對允許的。在 CDN 場景的大量下載應用中,一般分為調度、存儲兩個重要環節。調度就是通過根據請求方 IP 、下載文件等信息尋找最近、最快節點,應答跳轉給請求方完成下載。

下面是配置文件內容


語法檢查無誤后,重新加載生效

在命令行輸入如下兩個命令測試

參考文獻

[1].https://moonbingbing.gitbooks.io/openresty-best-practices/content/openresty/work_with_location.html

總結

以上是生活随笔為你收集整理的OpenResty上各种测试用例实操(1)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。