一些懷古的點陣字型

前幾天在 Hacker News 上看到的懷古字型:「The Ultimate Oldschool PC Font Pack」,在「FONT INDEX」這頁裡面有很多字型的圖片可以看。

比較有趣的是在「README」這頁提到的版權問題,點陣字體在美國是無法被版權化的:

Q. Is this even legal? The original fonts are not yours. Do you have the right to distribute these versions?

A. Short answer: as far as I was able to research, there is nothing illegal or infringing about this collection. The raw bitmap typefaces are not copyrightable, unlike fonts in specific formats such as .fon and TrueType (which qualify as software); at least this is the case in the US, where this site is based. For a longer and far more boring answer, see the legal stuff section below.

這點可以在維基百科上的「Intellectual property protection of typefaces」這篇看到對應的說明:

Typefaces cannot be protected by copyright in the United States (Code of Federal Regulations, Ch 37, Sec. 202.1(e); Eltra Corp. vs. Ringer). The idea that typefaces (rather than fonts, which are computer software) cannot be copyrighted in the United States is black letter law. 37 C.F.R. § 202.1(e). Under U.S. law, typefaces and their letter forms or glyphs are considered utilitarian objects whose public utility outweighs any private interest in protecting their creative elements. However, there is a distinction between a font and a typeface. The machine code used to display a stylized typeface (called a font) is protectable as copyright. In 1992, the US Copyright Office determined that digital outline fonts had elements that could be protected as software. Since that time, the Office has accepted registration of copyright for digital vector fonts, such as PostScript Type 1, TrueType, and OpenType format files.

有不少字型有提供 8x16 的大小,看起來之後還是可以找機會用看看?應該有機會搭 16px 的中文字...

Mass Effect 的 3D 場景黑塊問題一路追到 Intel/AMD 的 SSE2 指令集...

Mass Effect 是個 2007 在 Xbox 上推出的遊戲,並且在 2008 推出 Windows 版,這個遊戲在 2011 年 AMD 推出的 CPU 上 (Bulldozer),某些場景會產生人物黑塊的 bug,社群有些猜測但一直都沒被證實,作者一路追出不少問題,並且給了一個還算乾淨的 workaround:「Fixing Mass Effect black blobs on modern AMD CPUs」,另外在 Hacker News 上有很精彩的討論:「Fixing Mass Effect black blobs on modern AMD CPUs (cookieplmonster.github.io)」。

這篇主要是看趣味的,裡面的狀況有點複雜。

社群有一些 workaround 可以避開這個問題,作者後來是從關閉 PSGP (Processor Specific Graphics Pipeline) 的方法找問題,然後發現在計算時會產生出 NaN 的問題,所以導致貼出來的圖就變成黑塊了...

一路追下去,發現遊戲本身好像沒什麼大問題,但跟 Direct3D 裡面的 D3DXMatrixInverse 有關,會依照 CPU 的支援度決定怎麼跑:

  • Disabling PSGP makes both Intel and AMD take a regular x86 code path.
  • Intel CPUs always take an intelsse2 code path.
  • AMD CPUs supporting 3DNow! take a amd_mmx_3dnow or amd3dnow_amdmmx code path, while CPUs without 3DNow take an intelsse2 code path.

會有這些邏輯是因為 AMD 在 2010 後決定放生 3DNow!,所以會需要這樣判斷。

接著寫了一隻小程式測試,用 memcmp() 判斷是不是一樣,結果發現 AMD 的 SSE2 跑出來的程式不被遊戲接受:(不一樣是正常的,因為這些指令本來就沒有要求完全正確,是可以接受誤差的)

接著就是翻資料,可以知道 XMMatrixInverse 算是接班人:

I figured that since we were to replace that matrix function anyway, I could try replacing it with XMMatrixInverse being a “modern” replacement for D3DXMatrixInverse. XMMatrixInverse also uses SSE2 instructions so it should be equally optimal to the D3DX function, but I was nearly sure it would break the same way.

所以就弄個一個 DLL,把本來呼叫 D3DXMatrixInverse 的部份用 XMMatrixInverse 改寫換掉:「SilentPatchME/source/D3DXMatrix.cpp」,這個方式算是乾淨的 workaround 掉,保持 API 相容性,以及該有的加速能力 (由 XMMatrixInverse 提供)。

Hacker News 上有討論到 Intel 與 AMD 這些指令在 SSE2 上的誤差值,都是在規格要求的範圍內:

Const-me 14 hours ago [–]

Here’s Intel versus AMD relative error of RCPPS instruction: http://const.me/tmp/vrcpps-errors-chart.png AMD is Ryzen 5 3600, Intel is Core i3 6157U.
Over the complete range of floats, AMD is more precise on average, 0.000078 versus 0.000095 relative error. However, Intel has 0.000300 maximum relative error, AMD 0.000315.

Both are well within the spec. The documentation says “maximum relative error for this approximation is less than 1.5*2^-12”, in human language that would be 3.6621E-4.

Source code that compares them by creating 16GB binary files with the complete range of floats: https://gist.github.com/Const-me/a6d36f70a3a77de00c61cf4f6c17c7ac

至於為什麼會生出 NaN 的原因,沒找出來還是有點可惜,不過這個解法還行,就是「新版的 library 既然沒問題,就大家也不要太計較舊版的問題」的概念...

MariaDB 的 S3 Engine 效能測試

PerconaMariaDB 在 10.5 (目前的最新穩定版) 裡出的 S3 Engine 給出了簡單的測試報告:「MariaDB S3 Engine: Implementation and Benchmarking」。

這個 engine 顧名思義就是把資料丟到 Amazon S3 上,目前是 alpha 版本,預設是不會載入的,需要開 alpha flag 才能用:

The S3 engine is READ_ONLY so you can’t perform any write operations ( INSERT/UPDATE/DELETE ), but you can change the table structure.

另外這是從 Aria 改出來的 read-only engine,而 Aria 是從 MyISAM 改出來的:

The S3 storage engine is based on the Aria code and the main feature is that you can directly move your table from a local device to S3 using ALTER.

測出來發現在 read-only 的情境下,COUNT(*) 超快,看起來就是跟 MyISAM 體系有關,直接撈 MyISAM 內的資料,所以本地要 18 秒,但放到 S3 反而秒殺 XDDD

整體看起來還不錯?算是一種 Data warehouse 的方案,主要是要用到 row-based format 儲存的優點,遇到一些冷資料可以這樣玩。

從「Using the S3 Storage Engine」這邊的設定方式看到 s3_host_name,看起來有機會接其他家的 S3 API,或是本地的 Storage。

話說 Aria 這個引擎當初最主要的重點就在 crash-safe,在有了 crash-safe 之後,DRBD 這種 block-level replication 機制就可以硬幹上去,後來主力就在擴充其他型態了,像是 GIS 與 virtual column 的功能,不過這些功能本家在 InnoDB 上好像也都陸陸續續跟上來了,單純的 Aria engine 好像還好...

EU-US Privacy Shield 被歐盟法院拒絕

在「EU rejects US data sharing agreement over privacy concerns」這邊看到的新聞,引用自「EU rejects US data sharing agreement over privacy concerns」這邊的新聞報導。

歐盟最高法院的新聞稿則是在「The Court of Justice invalidates Decision 2016/1250 on the adequacy of the protection provided by the EU-US Data Protection Shield」這邊可以看到,雖然 EU-US Privacy Shield 被推翻,但本來在 2010 年的框架仍然有效:

However, it considers that Commission Decision 2010/87 on standard contractual clauses for the transfer of personal data to processors established in third countries is valid.

維基百科上的條目寫的比較簡單,主要是協議裡美國的保護機制不到歐盟的標準:

A final CJEU decision was published on 16 July 2020. The EU-US Privacy Shield for data sharing was struck down by the European Court of Justice on the grounds it did not provide adequate protections to EU citizens on government snooping.

記得這個戰了好久,最後在最高法院定案了...

PHP 在 Amazon EC2 的 m5 (Intel) 與 m6g (ARM) 的效能差異

先前在「Amazon EC2 的 M6g 系列正式推出了」這邊提到了 AWSAmazon EC2 上推出了以 ARM 為架構的 m6g 系列機器,剛剛看到有人拿 PHP 上的應用丟出測試的差異了:「Improving performance of PHP for Arm64 and impact on Amazon EC2 M6g instances」。

最先要注意的應該是這張:

在 PHP 7.3 的時候 Intel 平台的 m5 跑比較快,但到了 PHP 7.4 就變成 ARM 的 m6g 跑比較快了,不過這兩個版本的差異都不算太大,而到了還在開發的 PHP 8 則是出現了比較大的差距。

作者有提到主要的原因是在 PHP 7.4 之前 ARM 上不會啟用 Zend optimizer,而這個功能對效能的影響差很多,在 PHP 7.4 打開後就反轉了:

Zend optimizer is a component of the PHP runtime system that improves performance by up to 30% on a range of Zend micro-benchmarks. Before PHP 7.4 the Zend optimizer was not enabled for Arm.

而 PHP 8 的差距拉大,則是因為 PHP 有更多針對 ARM 平台的改善,像是這邊提到的 NEON 指令集:

PHP-8 plans to release in 2021 with more improvements for Arm64: an improved toupper/tolower function brings performance up by 16.5x. https://github.com/php/php-src/pull/4439

除此之外,AWS 也對 PCRE2 提供了使用 NEON 指令集的加速的 patch:

AWS has contributed changes to PCRE2 release 10.34. PCRE2 version 10.34 is used in PHP-8 to match regular expressions. PCRE2 accounted for about 8% of execution time in WordPress benchmark. The change contributed by AWS to PCRE2 vectorizes first character match and matching pairs of characters with NEON instructions: performance improves by up to 8x on M6g.

這樣可以看到 ARM 平常應該會愈來愈成熟,而更重要的是 m6g 系列機器比 m5 便宜不少:以作者測試的 {m5,m6g}.4xlarge 來看,分別是 USD$0.768/hr 與 USD$0.616/hr,大約是 20% 的差距,加上效能上的差距,C/P 值看起來是真的有到官方宣稱的 40%,這點在其他 Plurk 也測出了類似的結果

未來除非是 binary-only 的東西,不然應該會朝著往 ARM 上面測過,再決定要怎麼選 instance type...

AWS 南韓區開第四個 AZ

AWS 南韓區開第四個 AZ 了,比想像中的快不少:「Now Open – Fourth Availability Zone in the AWS Asia Pacific (Seoul) Region」。

而且不像東京,新客戶只能看到三個 AZ:「Regions and Availability Zones」。

*New customers can access three Availability Zones in Asia Pacific (Tokyo).

雖然台灣過去的 routing 都還是沒改善...

AWS 推出直播服務 Amazon Interactive Video Service (Twitch-as-a-Service)

把直播系統包在一起的服務 Amazon Interactive Video Service:「Amazon Interactive Video Service – Add Live Video to Your Apps and Websites」。

這邊先抱怨一下,這個服務的網址是 https://aws.amazon.com/ivs/,但 Elastic Load Balancer (ELB) 卻是 https://aws.amazon.com/elasticloadbalancing/,這是差別待遇啊...

回到原來的主題,這個服務做了幾件事情。收到 RTMPS stream 後,他會轉成許多格式:

If you send the maximum 8.5Mbps, 1080p60 stream, Amazon IVS will create 8.5Mbps 1080p60, 3Mbps 720p60, 2Mbps 720p30, 1.2Mbps 480p30, 800Kbps 360p30, and 400Kbps 160p30 renditions in an ABR stream.

從這份列表可以看出他目前最高只支援 1080p60,而 1440p (2K) 或是 2160p (4K) 看起來都還不支援。

另外因為是包裝 AWS Elemental Media Services,所以有蠻多東西都一起可以拿進來用,像是廣告機制與 DRM,然後看起來可以選擇 CDN:

With AWS Elemental Media Services, you have a high level of control over all workflow components: transcoding and packaging configurations; levels of resilience; personalized ad insertion; and features like content protection for digital rights management (DRM). You also get to choose which video players and CDNs are used.

區域上只開了三區 (us-east-1us-west-2eu-west-1),但我在看 AWS 上的標價時整個搞混:

一開始看的時候在找單位但發現沒標,後來研究了一下看起來應該是 per hour?這樣標看起來很像是前面一萬個小時只要 USD$0.32 啊?

另外一個比較有趣的事情是,看起來不像是用 CloudFront 做,因為收費區域的區分跟 CloudFront 不太一樣,實際開下去後發現似乎是用 Twitch 的架構?

我試著開了一個,給了 a9a09e285166.us-east-1.playback.live-video.net 這樣的 endpoint,實際測試發現的確是某種 CDN,指到台灣的機房:

;; ANSWER SECTION:
a9a09e285166.us-east-1.playback.live-video.net. 56 IN A 23.160.0.254
a9a09e285166.us-east-1.playback.live-video.net. 56 IN A 192.108.239.254

實際 traceroute 後發現不是 CloudFront,但反解後發現 dig 拋出了 Justin.tv 的資訊:

;; AUTHORITY SECTION:
0.160.23.in-addr.arpa.  300     IN      SOA     ib-ens.sjc02.justin.tv. admin.justin.tv. 44 10800 3600 604800 300

;; AUTHORITY SECTION:
239.108.192.in-addr.arpa. 300   IN      SOA     ib-ens.sjc02.justin.tv. admin.justin.tv. 49 10800 3600 604800 300

然後 traceroute 可以發現跟 video-edge-6ab612.tpe03.abs.hls.ttvnw.net (在 Twitch 上隨便找個實況抓的 hostname) 進到同一個機房 (在 router 還沒有擋下來的範圍),看起來就是拿 Twitch 的頻寬做事 XDDD

Twitch-as-a-service XDDD

這包會不會是 Twitch 掛 AWS 牌推出的服務啊 XDDD

libtorrent 要支援 WebTorrent 協定了

一開始是看到「Libtorrent Adds WebTorrent Support, Expanding the Reach of Browser Torrenting」這篇,但看的時候發現裡面把 libtorrentlibTorrent 搞混 (這兩套不一樣,libTorrent 是 rTorrent 作者開發的),就暫時沒管這篇文章了...

剛剛看到「libtorrent adds support for the WebTorrent protocol」這篇,然後回頭去看本來 TorrentFreak 上的文章,發現已經拿掉本來提到的 rTorrent 了。(可以參考 Internet Archive 上的存檔資料 20200709223911)

WebTorrent 的支援對於 BitTorrent 社群算是很大的進展,主要是因為瀏覽器內就算用上 WebRTC 也沒有辦法模擬出 BitTorrent 的協定,所以只能調整協定,也就是這邊提到的 WebTorrent。

但訂了新的協定,最大的問題還是現有的 BitTorrent 程式都不支援 WebTorrent,所以沒辦法享用現有的 ecosystem,變成獨立的系統,對於推廣上面很不利...

而 libtorrent 算是第一個夠大的 library (對應到 client 的數量) 宣佈支援 WebTorrent,這樣用瀏覽器的人就會有更多機會透過 WebTorrent 協定對通了,接下來等更加發佈新版後應該就可以在 WebTorrent 上看到更多節點了...

Blackboard Learn

有時候 Hacker News 上會有一些有趣的問答,像是這篇了有哪些你每天會用到,但卻幹翻的軟體 (下面的討論比較廣義,包括是服務):「Ask HN: What's the worst piece of software you use everyday?」。

先說一下,因為 Hacker News 有分頁的機制,記得看到底以後點 more 看下一頁。

其實沒什麼意外的,知名的軟體都會被幹,包括 AWSDockerSlack 之類的 (然後還看到 Git 也有人幹)。

不過比較意外的是目前在第一頁第一項 (代表分數很高) 的項目,看起來寫的人有滿滿的恨意:

Sorry, but everything listed here is rank amateur stuff when compared to Blackboard Learn (https://en.wikipedia.org/wiki/Blackboard_Learn).

下面的回覆也是一片幹,完全沒什麼人想辯解...

翻了一下維基百科的「Blackboard Learn」條目,看了裡面的「介紹」,似乎不太意外...

像是用了一年就換掉的:

In addition, a number of educational institutions, teachers, and students have expressed concerns about the reliability of Blackboard. McMaster University in Hamilton, Ontario, Canada, has replaced their Blackboard system after multiple problems during one year of use.

因為問題與成本關係換成 open source 的 Moodle

Citing numerous glitches and high costs, many universities are turning to the cheaper, open source alternative Moodle, including Montana State University, Vassar College, California State University, Long Beach, and many other schools.

炸掉的:

Rensselaer Polytechnic Institute's implementation of the system notably suffered sporadic outages in the Grade Book section during the finals of the Fall 2014 semester.

然後這次 COVID-19 也有災情:

In Spring 2020, during coronavirus pandemic, Fairfax County Public Schools, one of the largest school system in the United States with 189 thousand students abandoned Blackboard Learn 24/7 after weeks of unsuccessful attempts to use it. The issues included, poor security allowing live instructions to be hacked and disrupted and inability for the system to cope with the volume even on the days when only elementary schools were using the system.

記得交大以前也有用過 Blackboard 的產品 (不確定用的產品跟 Learn 有沒有關係),網址是 bb.nctu.edu.tw (搜一下還可以看到一些痕跡),但現在也查不到了,後來也沒聽到消息了...

Linus 狂幹 Intel 的 AVX-512

這幾天蠻熱鬧的消息,Linus 幹翻 Intel 丟出來的 AVX-512:「Alder Lake and AVX-512」。

在維基百科的「Advanced Vector Extensions」這邊有提到,因為 AVX-512 執行時會消耗產生更多的熱量,所以得壓低 Turbo Boost 執行:

Since AVX instructions are wider and generate more heat, Intel processors have provisions to reduce the Turbo Boost frequency limit when such instructions are being executed. The throttling is divided into three levels:

  • L0 (100%): The normal turbo boost limit.
  • L1 (~85%): The "AVX boost" limit. Soft-triggered by 256-bit "heavy" (floating-point unit: FP math and integer multiplication) instructions. Hard-triggered by "light" (all other) 512-bit instructions.
  • L2 (~60%): The "AVX-512 boost" limit. Soft-triggered by 512-bit heavy instructions.

本來 AVX 與 AVX-2 只會在某些重量級的指令時會壓 15%,現在在 AVX-512 則是變成常態,而且有些會降到 40%,對於同時在跑的應用會受到很大的影響,所以 Linus 也直接放話要用他的權限擋這件事情 (我把動詞讀錯了):

I want my power limits to be reached with regular integer code, not with some AVX512 power virus that takes away top frequency (because people ended up using it for memcpy!) and takes away cores (because those useless garbage units take up space).

在後面的討論串「Alder Lake and AVX-512」這邊 Linus 有提到更細,像是他對於 MMX/SSE/AVX/AVX2 的想法,以及為什麼他這麼厭惡 AVX-512。

AMD 的繼續看戲 XDDD