8

Mac 上 sprintf 的 scalability 問題

 2 years ago
source link: https://blog.gslin.org/archives/2022/02/27/10570/mac-%e4%b8%8a-sprintf-%e7%9a%84-scalability-%e5%95%8f%e9%a1%8c/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Mac 上 sprintf 的 scalability 問題

Hacker News 上看到個有趣的 scalability 問題,在 Mac 上的 sprintf() 因為有 lock 造成的 scalability 問題:「Curious lack of sprintf scaling (aras-p.info)」。

作者注意到 Mac 在多 CPU 下 sprintf() 會有 scalability 的問題,要注意到這邊的 Y 軸是對數比例:

用了 std::stringstream << 反而更慢 (作者還酸了一句「Zero cost abstractions」):

然後用了 Instruments 跑 profiling 找問題,可以看到看起來跟 locale 有關:

一般的情況下應該不會是問題,但如果是需要大量 sprintf() 組字串的人就會比較要注意了。

在「What else can we do?」這段有提到一些解法,包括了 stb_sprintf 當作替代品,以及 {fmt} 作為 iostreams 的替代品,然後另外是利用 to_chars 來解決,如果只是要把數字轉成字串。

算是蠻有趣的 bug hunting 過程,對於開發者來說,一般性的重點還是在 profiling,找到對的問題然後再往下提出解法...

Related

GTA 的啟動讀取效能問題

這件事情也已經過了一個禮拜,來整理一下發生什麼事情... 起因是 GTA Online 的遊戲開啟速度很慢,而有人一路 reverse engineering 找出問題並且解決:「How I cut GTA Online loading times by 70%」,對應的 Hacker News 討論有提到其他有趣的事情也可以看看:「How I cut GTA Online loading times by 70% (nee.lv)」。 作者的電腦不算太差,但光開啟 GTA Online 就需要六分鐘,網路上甚至有辦投票蒐集大家的等待時間,發現也有很多人反應類似的問題: 接下來就開始 reverse engineering 了,先觀察各種狀態後發現是卡在 CPU,而不是網路或 Disk I/O,然後就拿出 Luke Stackwalker 這個工具 profiling,不過因為沒有 debug symbol 幫忙 group,所以只能人工判斷後,可以看到兩個問題: 第一個問題發現效能是卡在 strlen(),而 call…

March 6, 2021

In "Computer"

Linux 上 MySQL Scalability 的問題

先前提到在 Linux 跑 MySQL 的問題,在 Update on the linux scaling situation. 提到了兩個 link: MySQL scalability on Linux with sysbench SMP performance degradation with sysbench 在第一個 link 裡,在一台 4 CPU 的 PPC 64 有發現類似的現象: 中間 debug 的過程就不講了,最後發現是 glibc 裡 malloc() 的問題,用 LD_PRELOAD 把 Google 提供的 tcmalloc 替換掉後就恢復了: 那個法鵝大站的站長,如果你覺得 MySQL 太慢的話掛個 LD_PRELOAD…

March 18, 2007

In "Computer"

MySQL 總算要拔掉 mysql_query_cache 了

半官方的 MySQL blog 上宣佈了拔掉 mysql_query_cache 的計畫:「MySQL 8.0: Retiring Support for the Query Cache」。 作者開頭引用了 ProxySQL 的人對 MySQL Query Cache 的說明: Although MySQL Query Cache was meant to improve performance, it has serious scalability issues and it can easily become a severe bottleneck. 主要問題在於 MySQL Query Cache 在多 CPU 環境下很難 scale,很容易造成一堆…

May 31, 2017

In "Computer"

a611ee8db44c8d03a20edf0bf5a71d80?s=49&d=identicon&r=gAuthor Gea-Suan LinPosted on February 27, 2022February 27, 2022Categories Computer, Library, Murmuring, Programming, SoftwareTags apple, bug, cpu, locale, mac, macos, os, osx, performance, profiling, scalability, speed, sprintf

Leave a Reply

Your email address will not be published. Required fields are marked *

Comment *

Name *

Email *

Website

Notify me of follow-up comments by email.

Notify me of new posts by email.

To respond on your own website, enter the URL of your response which should contain a link to this post's permalink URL. Your response will then appear (possibly after moderation) on this page. Want to update or remove your response? Update or delete your post and re-enter your post's URL again. (Learn More)

Post navigation


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK