奇怪的 t2.large instance

EC2 推出了新的 t2.large instance:「New T2.Large Instances」。

價錢剛好是 t2.medium 的兩倍,記憶體也是兩倍 (4GB 對 8GB),但 CPU 的部份只多了 50%,就如同 Colin Percival 講的,這看起來很奇怪:

不過 t2.* 是真的很好用,反正就當作多一個方案吧...

MySQL 在處理 GROUP BY 時選擇 index 的效率問題

Percona 的「Speed up GROUP BY queries with subselects in MySQL」這篇講了 MySQL 在處理 GROUP BY 的效率問題。

舉原文的例子,也就是這樣的 SQL query:(我把 command 都改成大寫,其他部份都改成小寫)

SELECT a.name, SUM(a.count) a_sum, AVG(a.position) a_avg, b.col1, c.col2, d.col3
FROM
a JOIN
b ON (a.bid = b.id) JOIN
c ON (a.cid = c.id) JOIN
d ON (a.did = d.id) GROUP BY a.name, b.id, c.id, d.id

其中 TABLE a 有 1.3M rows,而 b、c、d 都只有 5 rows。

由於會需要計算每組 (a.name, b.id, c.id, d.id)SUM(a.count)AVG(a.position),不可避免的是需要對 TABLE a 完整的掃一次。所以效能的改善會在於可以減少 temporily table 的大小。

上面這組 SQL query 會先 JOIN 完後再 GROUP BY,也就是會全部先展開後再 GROUP BY

由於 GROUP BY 所使用到的條件都可以在 TABLE a 裡面找到,所以這邊可以先 GROUP BY 後再 JOIN,降低 temporily table 的大小:

SELECT a.name, a_sum, a_avg, b.col1, c.col2, d.col3
FROM
(SELECT name, SUM(count) a_sum, AVG(position) a_avg, bid, cid, did
 FROM a
 GROUP BY name, bid, cid, did) a JOIN
 b ON (a.bid = b.id) JOIN
 c ON (a.cid = c.id) JOIN
 d ON (a.did = d.id)

原文測試出來的結果是從 2.3 秒降到 1.8 秒:

The first query took 2.3 sec avg and the optimized query took 1.8 sec average, half a second faster.

另外一個改善是再加上 covering index:

ALTER TABLE a ADD INDEX (name, bid, cid, did, count, position);

加上去之後,原來的 query 變成 1.9 秒,而改善後的變成 0.7 秒,速度快很多。不過這是 trade-off,多了這個 index 在寫入時的成本也會增加。

Adobe Typekit 支援 CJK 字型

Adobe Typekit 宣佈支援 CJK 字型:「Announcing East Asian web font support and new font browsing tools for Japanese customers」。中文的公告在「正式公開東亞網頁字體支援以及日文客戶適用的全新字體瀏覽工具」這邊。

這也包括了網頁版的部份。對於 CJK 單一字型檔案過大的問題,與大家的解法也都一樣,取出對應的字組出來給使用者作為 workaround (稱為 Dynamic Subsetting):

會稱為這是 workaround 是因為當網路速度愈來愈之後,就會又變成最單純的直接整包下載...

Anyway,Adobe 這個新功能是一個大邁進,不過他用的 HTTPS (EdgeCast) 還沒支援 SPDY 或是 HTTP/2 啊... :/

微軟讓 Windows 7 與 Windows 8.1 上的 IE11 支援 HSTS

本來只有 Windows 10 的 IE11 有支援 HSTS,而前幾天的更新則是讓 Windows 7 與 Windows 8.1 的 IE11 也支援了:「HTTP Strict Transport Security comes to Internet Explorer 11 on Windows 8.1 and Windows 7」。

With today’s monthly security updates (KB 3058515), we’re bringing the protections offered by HSTS to Internet Explorer 11 on Windows 8.1 and Windows 7. HSTS is also available in both Internet Explorer 11 and Microsoft Edge on Windows 10.

這次的更新讓所有主流瀏覽器都支援 HSTS 了,再加上前一篇「Wikimedia (包括維基百科) 推出 HSTS (強制使用 HTTPS)」提到的,愈來愈多人用啦...

然後據 zonble 說,iOS 9 有些東西會 HTTPS only (預設值),該回頭去催自己人支援了 :o

Wikimedia (包括維基百科) 推出 HSTS (強制使用 HTTPS)

Wikimeda 宣佈所有旗下的網站都會啟用 HTTPS 與 HSTS:「Securing access to Wikimedia sites with HTTPS」。

在這之前,使用者可以用 EFFHTTPS Everywhere 強制使用 HTTPS (在 FirefoxGoogle Chrome 都有上架),而這次則是全面強制使用了。

愈來愈多人使用 HTTPS 來保護隱私後 (而不僅僅是保護機密資料),接下來的問題就是要想辦法在 DNS 上保護了。也就是可以利用 DNS query pattern 知道你在看哪種 (或是哪一個) 頁面。

Git 上各種 Undo 的技巧

GitHub 的「How to undo (almost) anything with Git」這篇文章介紹了 Git 上各種 undo 的方式。

主要先分成「已經 push 出去」與「還沒 push 出去」兩種,然後針對 branch 再說一次。

這份沒有 cover 到所有的方式,但常用的都在裡面提到了,可以先 bookmark 下來,需要用的時候練個幾次就會背起來了。

Amazon EC2 推出新機種:m4.*

Amazon EC2 推出新的一般性機種 m4.* 了:「The New M4 Instance Type (Bonus: Price Reduction on M3 & C4)」。

亮眼在 m4.10xlarge 這組可以控制 C-state 與 P-state,可以利用這兩個對 latency 與整體 performance 調整。

拿 m4.large 與 m3.large 比較,m4 便宜一些,而且 m4 記憶體比 m3 大一點,但是 m3 有內掛 SSD,m4 需要 EBS。如果 I/O 比較重的應用還是用 m3 還是比較好。

另外一個發表的是 m3.* 在某些地區有些微的降價 (約 5%),就當作撿到的...?

Facebook 推出靜態分析工具:Facebook Infer

Facebook 推出了靜態分析工具 Facebook Infer,可以事先找出 AndroidiOS 上的 bug:Open-sourcing Facebook Infer: Identify bugs before you ship

從官方給的操作動畫中就可以看出來怎麼跑了。目前看起來支援三種程式語言,C、Objective-C、Java:

Facebook Infer is a static analysis tool - if you give Infer some Objective-C, Java, or C code, it produces a list of potential bugs.

在 Android 上 (Java) 會找出的類型:

Infer reports null pointer exceptions and resource leaks in Android and Java code.

iOS 上則只找 memory leak:

In addition to this, it reports memory leak problems in iOS and C code.

比較特別的是,這個工具是用 OCaml 寫:

Infer is a static analysis tool for Java, Objective-C and C, written in OCaml.

Amazon Redshift 的新硬體規格

Amazon Redshift 是以 SQL 介面操作的方式分析 data warehouse 的資料,可以利用多台機器平行計算加速。

這次 Amazon Redshift 提供了新的硬體規格出來 (ds2.* 系列):「Amazon Redshift – Now Faster and More Cost-Effective than Ever」。

ds2.* 與原來 ds1.* 的價錢都一樣,但是 vCPU 與記憶體都加倍,網路與 I/O 速度都升級了。如果沒有買 Reversed Instance (RI) 的人可以換過去,有買的人就再想辦法吧...

然後 Amazon Redshift 的 RI 模式也與 EC2 的 RI 架構相同了,有三種選擇。