[爆卦]blocking實驗是什麼?優點缺點精華區懶人包

雖然這篇blocking實驗鄉民發文沒有被收入到精華區:在blocking實驗這個話題中,我們另外找到其它相關的精選爆讚文章

在 blocking實驗產品中有4篇Facebook貼文,粉絲數超過2,850的網紅矽谷牛的耕田筆記,也在其Facebook貼文中提到, 本篇文章是個經驗談,作者想要聊聊是如何將一個 4vCPU 的VM給調整到可以達到每秒處理 1.2M(120萬)個 JSON Reuqest,本篇文章非常的長,所以會分多天來介紹。 整篇文章探討的是各種 turning 的步驟,來聊聊如何從最初每秒 224k(22萬四千) 給調整到每秒 1.2M 的...

  • blocking實驗 在 矽谷牛的耕田筆記 Facebook 的最讚貼文

    2021-06-14 08:07:47
    有 198 人按讚

    本篇文章是個經驗談,作者想要聊聊是如何將一個 4vCPU 的VM給調整到可以達到每秒處理 1.2M(120萬)個 JSON Reuqest,本篇文章非常的長,所以會分多天來介紹。

    整篇文章探討的是各種 turning 的步驟,來聊聊如何從最初每秒 224k(22萬四千) 給調整到每秒 1.2M 的處理能力。

    整個過程分成九大步驟,後面同時標示每個過程後的每秒請求能力
    1. Application Optimizations (347k)
    2. Speculative Execution Migtigations (446k)
    3. Syscall Auditing/Blocking (495k)
    4. Disabling iptables/netfilter (603k)
    5. Perfect Locality (834k)
    6. Interrypt Optimizations (1.06M)
    7. The Case of the Nosy Neighbor (1.12M)
    8. The Battle Against the Spin Lock (1.15M)
    9. This Gost to Twelv (1.20M)

    作者強調,上述的過程不一定適合你的應用程式,但是透過這些步驟能夠讓你更佳瞭解應用程式的運作行為,同時也有機會發現一些潛在的瓶頸問題。

    環境介紹
    1. 團隊使用 Techempower 來進行 JSON Serialization 的測試
    2. 使用 libreactor(event-driven框架) 來搭建一個簡單的 API Server
    3. HTTP 的解析使用 picohttpparser,同時使用 libclo 來處理 JSON 的編碼
    4. 硬體環境
    - Server: 4 vCPU, c5n.xlarge AWS VM
    - Client: 16 vCPU, c5n.4xlarge AWS VM (clinet太弱會變成瓶頸)
    - Network: Server/Client 屬於同一個可用區域(AZ)
    5. 軟體環境
    - 作業系統: Amazon Linux2 (Kernel 4.14)
    - Server: 使用 libreactor (使用不同版本,分別是 Round18 以及 Round20)
    - Client: 修改 wrk 這個知名的工具並重新命名為 twrk,詳細差異自己看文章內部,主要都跟顯示有關
    6. 實驗方式
    - 每個測試跑三次,取中間值
    - 256 連線,16 threads,同時每個 thread 都會 pin 到一個固定的 CPU
    - 每個實驗都有兩秒的暖機時間來建立連線


    Ground Zero
    第一個要探討的就是什麼最佳化都還沒有使用前,到底當前應用程式可能的瓶頸在哪裏
    首先團隊將該應用程式與其他常見的應用程式或是開發框架比較,譬如 Netty, Nginx, Actix, aspcore 等, libreactor 的效能不錯,有中上水準。

    接者作者使用火焰圖(Flame Graphs)來 Profile 該伺服器,作者很好心地將文章中所有的火焰圖都調整了一下,讓所有的 user-space 相關的 function call 都轉成藍色,而剩下跟 kernel 相關都維持紅色。
    1. 大部分的時間都在 Kernel 處理
    2. 主要是花費在收封包與送封包
    3. 應用程式本身主要是分兩大部分,解析 HTTP 的封包以及處理請求與回應。
    從上述兩點來看,作者認為目前的應用程式寫得算不錯,因為瓶頸很明顯是卡在 Kernel 端

    接下來就正式進入到各種 Turning 的章節探討

    Application Optimizations

    長話短說:
    - 作者基於 libreactor Round18 的框架進行修改,並且所有的修改都已經被合併到 Round20 的版本中,而這些修改主要是實作方面的強化以及整個框架的最佳化。

    1. 作者首先透過 htop 觀察運行過程,發現 Server 只有使用 2vCPU 而已(系統有 4vCPU),因此這是作者進行的第一個修改,讓 Server 使用了 4vCPU,這個簡單調整就讓效能提升 25%

    註: 作者特別強調,不要覺得從 2vCPU 變成 4vCPU 效能就可以變成兩倍,主要是1) 沒有使用的 vCPU 還有很多其他的工作要處理,因此不是完全都送給你應用程式處理。2)基於 hypter-thread vCPU 的架構,環境只有兩個真正的 CPU 而是透過邏輯的方式產生四個抽象的 CPU,所以全用一定會變快,但是基於很多資源還是要競爭與共用,數字不是單純翻倍

    2. 作者自己的應用程式本身使用 gcc 建置時有使用 "-o3" 的方式來最佳化處理,然而框架本身卻沒有使用 "-o3" 的方式來弄,因此作者也針對這個部分來處理,讓建制框架時能夠使用 -o3
    3. 從實作方面來看,作者觀察到 libreactor 1.0 版本使用的是 read/write 這兩個常見的方式來處理封包的送收,作者將其修改成 recv/send 整個效能就提升了將近 10%。

    註: write(針對 FD,更全面廣泛的用法) 與 send(針對 Socket,更針對的用法) 使用上差異不大,但是 write 於底層 Kernel 最終還是會呼叫到 send 來處理,所以基本上可以理解就是在沒有特別參數需求時,可以直接跳過幾個 kernel function 來達到加速的效果。

    write kernel 內的走向: sys_write -> vfs_write -> __vfs_write -> sock_write_iter -> sock_sendmsg

    send kernel 內的走向: sendto -> sock_sendmsg

    4. 作者觀察到火焰圖中有一些 pthread 相關的資料,進而發現 libreactor 會創造一個 thread pool 來處理非同步的 DNS 名稱解析問題。對於一個 HTTP Client 來說,如果今天要發送請求到多個不同的 domain,而每個 domain 都會需要進行一個 blocking 的解析過程,透過這種方式可以減少 DNS 解析造成的 blocking 問題。然而對於 HTTP Server 來說,這個使用情境帶來的效益似乎就稍微低了些,畢竟 Server 只有 Bind Socket 之前可能會需要去解析一次 DNS 而已。
    大部分的情境下, thread pool 都是應用程式初期會去創造而接者就不太會管她,但是對於錙銖必較的效能除錯人來說,任何能夠調整的部分都可能是個值得探討的地方。
    作者透過修改 Server 端(準確來說是 libreactor 框架內的程式碼)關於 Thread Pool 的一些用法,成長的讓整個效能提升了 2~3%

    結論來說,透過上述四個概念來提升的程式碼效能。
    1. vCPU 盡量使用: 25%-27%
    2. 使用 gcc -O3 來建置框架的程式碼: 5%-10%
    3. 使用 march=native 等參數來建置最後的 server 應用程式: 5%-10%
    4. 使用 send/recv 而非 write/read: 5%-10%
    5. 修改 pthread 的用法: 2%-3%

    註: 作者強調每個最佳化的結果並非是單純累積的概念,反而還會有互補的效果。
    可能前述的操作實際上也會讓後續的操作達到更好的效果,
    譬如如果先跑 vCPU 的調整,效能大概提升 25%,但是如果先執行別的最佳化過程,最後再來調整 vCPU,就可以達到 40% 的效果,主要是 CPU 可以共有效率的去執行程式。

    最後,這個部分讓整個處理封包能力從 224k 提升了 55% 到 347k (req/s)。
    從火焰圖來看,整個 user-space 的範圍縮小許多,同時 send/recv 的處理也有使得整體的高度下降一點點(大概四格..)

    為了避免文章過長,本篇文章就探討第一個最佳化的過程,剩下的就敬請期待後續!

    https://talawah.io/blog/extreme-http-performance-tuning-one-point-two-million/

  • blocking實驗 在 Facebook 的最讚貼文

    2021-06-06 20:59:06
    有 811 人按讚

    [關於反芻動物全身麻醉的風險,反芻動物中,全身麻醉的弊大於利。] 有興趣的朋友可以多了解一下喔! (中文翻譯的部分為Google翻譯的,能夠閱讀英文的朋友建議看原文會比較清楚喔)
    還有很多很多相關的學術發表,就不貼那麼多出來啦!

    Cooper結紮的日期是4月26日,他現在很健康很調皮。

    (德叔真的超級超級愛看這些學術發表的文章,但是我還是相信醫生的專業。)

    https://www.researchgate.net/publication/334673867_The_Use_of_Epidural_Anaesthesia_over_General_Anaesthesia_in_Ruminants
    全身麻醉是現代醫學的重要組成部分。它是一種藥物誘導的可逆病症,包括特定的行為和生理特徵,包括無意識、健忘症、鎮痛和運動不能——伴隨自主神經、心血管、呼吸和體溫調節系統的穩定性。
    [反芻動物全身麻醉具有內在風險,如瘤胃內容物反流、唾液分泌過多和肺部誤吸的可能性;因此並不總是推薦使用本地或區域技術。硬膜外麻醉是一種中樞神經阻滯技術,經常用於獸醫實踐中,用於治療家畜會陰、骶骨、腰椎和尾椎部位的不同產科和外科手術干擾。關於在反芻動物和其他物種的各種外科和實驗室程序中使用硬膜外麻醉的科學研究已經有幾項。總之,全身麻醉的弊大於利,特別是在反芻動物中。因此,硬膜外麻醉是首選。

    General anaesthesia is an essential component of modern medicine. It is a drug induced reversible condition that includes specific behavioral and physiological traits unconsciousness, amnesia, analgesia, and akinesia- with concomitant stability of the autonomic, cardiovascular, respiratory, and thermoregulatory systems.
    [General anesthesia in ruminants has inherent risks such as regurgitation of ruminal contents, excessive salivation and the possibility of pulmonary aspiration; therefore it is not always recommended and local or regional techniques may be used instead. Epidural anaesthesia is a central neuraxial block technique which is used regularly in veterinary practice for treatment of different obstetrical and surgical interferences in the perineal, sacral, lumbar, and caudal parts of the thoracic region of domestic animals. There have been several scientific researches on the use of epidural anesthesia in ruminants and other species for various surgical and laboratory procedures. In conclusion, the disadvantages of general anaesthesia outweigh the advantages especially in ruminant specie. Therefore, epidural anaesthesia is the most preferred.

    https://onlinelibrary.wiley.com/doi/abs/10.1002/9781118886700.ch1
    瘤胃鼓脹、腹脹、反流和吸入性肺炎是與家畜全身麻醉相關的常見問題,應通過適當的預防措施和必要的麻醉前考慮來預見和解決。家畜在麻醉期間可能會出現胃內容物反流和誤吸,尤其是未禁食的動物。反芻動物在麻醉期間通常會大量分泌唾液。惡性高熱的觸發因素包括壓力(例如興奮、運輸或麻醉前處理)、鹵化吸入麻醉劑(例如氟烷、異氟烷、七氟烷和地氟烷)和去極化神經肌肉阻滯藥物(例如琥珀膽鹼)。同樣,氟烷似乎是豬惡性高熱的最有效和最常見的觸發因素。麻醉前禁食可能不能完全防止反流,但會減少瘤胃內容物中的固體物質數量。獸醫應將這些知識與適當的麻醉前準備和適當的圍手術期管理相結合,以確保這些動物的麻醉成功。
    Ruminal tympany, bloat, regurgitation, and aspiration pneumonia are common problems associated with general anesthesia in farm animal species that should be anticipated and addressed with proper precautions and the necessary preanesthetic considerations. Regurgitation and aspiration of stomach content can occur in farm animal species during anesthesia, especially in nonfasted animals. Ruminants normally salivate profusely during anesthesia. The triggering agents of malignant hyperthermia include stress (e.g., excitement, transportation, or preanesthetic handling), halogenated inhalation anesthetics (e.g., halothane, isoflurane, sevoflurane, and desflurane), and depolarizing neuro-muscular blocking drugs (e.g., succinylcholine). Similarly, halothane appears to be the most potent and most frequently reported trigger of malignant hyperthermia in pigs. Preanesthetic fasting may not completely prevent regurgitation, but it will decrease the amount of solid matter in the rumen content. Veterinarians should incorporate the knowledge with proper preanesthetic preparations and appropriate perioperative management to ensure successful outcome of anesthesia in these animals.

  • blocking實驗 在 Zuker 租客 Facebook 的最佳解答

    2020-06-20 12:00:35
    有 8 人按讚

    🔔ZUKER最新空房釋出!近善導寺、中山捷運站!
    🔎看更多公共空間:https://zuker.cc/ZhongshanLab/F200620

    👇點更多看詳細資訊  
    ───────
     
    ❣中山實驗室❣
     
    🔸房型:套房 / C房 / $14,000 月 *6/27 可入住
    🔸地點:善導寺捷運站步行6分鐘
    🔸樓層:5F/5F

      
    🔸關於
      溫暖的空間,適合溫暖的你。早晨明亮的採光、掃去昨日的陰鬱。窗戶全為氣密窗,隔出吵雜的街道,還你安靜的空間。頂樓僅一層之遙,整個開放式屋頂,任你處置。烤肉、看101,看著來往車潮、思考自己的人生。這裡水電瓦斯網路是每月1000元/人全含喔!

    A cozy place looking for cozy guests. If you like the morning sun shining in to start your day, this is the place for you. All the windows are airtight, blocking the noise from the bust streets. Since it's on the top floor, you are one floor away from the rooftop, where you can enjoy the open space and do whatever you want (barbecue, smoke, you can even see Taipei 101 on there!). We ask for NT$1000/per person for utilities all included.
      
    🔸周邊環境
      位於善導寺捷運站6分鐘,中山捷運站10分鐘。右往北車、左往華山藝文中心,全在20分鐘內路程。前方小公園適合小憩,旁邊公車站任你隨意搭乘。對面即有U-bike、暢遊整個城市!中山區域的繁華、林森北路的熱鬧,等你來體驗。

    6 minutes to Shandao Temple station, 10 minutes to Zhongshan station. To your right is Taipei main station, left is Huashan park, all within 20 minutes walk.
    There is a U-bike station right across the streets, you could simply hop on and bike around to see what Taipei has to offer. Be sure to check around the Zhongshan area and the night market!
     

    🗣約看房、包租代管服務歡迎私訊

你可能也想看看

搜尋相關網站