Percona Server 5.5.30-30.2 (based on MySQL 5.5.30) 的改善

Percona 在前幾天推出基於 MySQL 5.5.30 的 Percona Server 5.5.30-30.2:「Percona Server for MySQL 5.5.30-30.2 now available」。

5.5.30-30.2 這個版本引入了 jemalloc

Percona Server for MySQL will now be shipped with the libjemalloc library. Benchmark showing the impact of memory allocators on MySQL performance can be found in this blogpost. (Ignacio Nin)

在去年 (2012 年) 七月 Percona 就有分析過 glibc 與 jemalloc 對效能的差異:「Impact of memory allocators on MySQL performance」,可以看到在 concurrent active connection 數量愈高,jemalloc 的優勢愈明顯。

預設總算把 jemalloc 包進去了,等好久了...

另外一個是「trx descriptors: MySQL performance improvements in Percona Server 5.5.30-30.2」,針對 transaction lock 問題的改善。

這邊比較時都用 jemalloc,是因為 Percona Server 5.5.30-30.2 是用 jemalloc,比較時必須盡可能維持一樣的條件。

圖表可以看到 Percona 把 5.6 的改善方式再改善,然後 backport 回 5.5,使得沒有被飆為 read only transaction 的 query 也能受益。

PostgreSQL 安全性更新...

PostgreSQL 在官網最明顯的位置上放出更新公告:

說明在「PostgreSQL 9.2.4, 9.1.9, 9.0.13 and 8.4.17 released」這頁,更新的版本分別是 9.2.4 (9.2)、9.1.9 (9.1)、9.0.13 (9.0) 與 8.4.17 (8.4)。除了公告外,在 Security Information 的資料也可以交叉看。

這次最嚴重的問題是 CVE-2013-1899,等級分類在最嚴重的 A 級,官方對這個問題的描述是:

A connection request containing a database name that begins with "-" may be crafted to damage or destroy files within a server's data directory

hmmm...

PostgreSQL 對 NoSQL 的看法...

二月的時候 PostgreSQL 的人在 FOSDEM PGDay 2013 上發表了對 NoSQL 的看法 (PDF 投影片):「PostgreSQL as a Schemaless Database.」。

先說明,這投影片相當酸 XD

不過這份投影片說明了大多數人的問題:

  • 其實大多用 NoSQL 的人不知道在用什麼...
  • 就算你知道你在用什麼,你用得很爽的功能其實在「傳統的」「SQL 架構」下效能通常都會更好...

另外我建議可以看看維基百科上的 Entity-attribute-value model,大多數你想用 NoSQL 的情況在這個 case 下就可以解決,而且效能相當好。

PostgreSQL 對 security update 的極端作法...

Hacker News 文摘上看到,PostgreSQL 決定對這次的 security update 採取最極端的作法:「Extra security measures for next week's releases」。

包括全面管制 Git repository 公開資訊:官方的 Git repository 將會在正式釋出修正前限制只有 committer 可以存取,並且暫停 GitHub 以及其他 git mirror 權限。

另外 mailing list 也受到管制,包括了 src commit log 以及 document commit log。

信件開頭就提到這次安全性漏洞足以說服 PostgreSQL 的人採取最極端的作法,避免在有修正方案前造成漏洞洩漏出來被使用:

The core committee has decided that one of the security issues due to be fixed next week is sufficiently bad that we need to take extra measures to prevent it from becoming public before packages containing the fix are available. (This is a scenario we've discussed before, but never had to actually implement.)

不過這反而讓人更關注,甚至上了 Hacker News 熱門榜...

Percona 的 MySQL 5.6...

剛剛看到 Percona 放出第三個基於 MySQL 5.6 的版本了,仍然是 alpha 等級 (還在測試階段):「Announcing Percona Server for MySQL 5.6.10-60.2」。

這也是 MySQL 5.6 進入 GA 後 Percona 推出的第一個版本,而且剛剛看 Percona 的文件網站也發現建出來了:「Percona Server 5.6 - Documentation」。

Percona XtraDB Cluster 目前還是基於 5.5 的版本,不知道 Codership (Galera Cluster 的開發公司) 有沒有打算換新...

換 NoSQL 前的建議...

原文是「Medium Data: things to try before abandoning SQL」,放棄 SQL 前應該要嘗試的事情,原文一開始就用粗體說明帶有強烈的偏見 XD

First, my thesis: a lot of less-experienced developers are using big data and NoSQL technologies because they are new and cool, and because SQL is old and hard. A lot of these people would save themselves time and effort by learning more about SQL and tuning their databases and hardware just a little bit.

文章寫的相當概念性,主要是說明幾件事情:

  • 其實 SQL 可以解決大部分的事情,大家都知道 SQL 的瓶頸在哪裡,有哪些 workaround 可以避開。
  • 不要因為 MySQL 做不到就覺得 SQL 不好用,在這種情況下,PostgreSQL 的功能與成熟度很值得看看。
  • 不要用 Oracle 官方版本的 MySQL... XD
  • 通常可以用 cache 解決的就用 cache 試著解看看,雖然 invalidate 問題不太好處哩... XD
  • 如果是 Read 數量太多,可以用 replication 解決不少問題。
  • 試著去理解 index 的「原理」,也就是資料結構,這對於要怎麼用 index 絕對有強力的幫助。
  • 當上面都做完而發現還是不夠的時候就 sharding 吧。

MySQL 5.5 與 5.6 的預設值差異...

Oracle 放出 MySQL 5.6 後,Percona 將 MySQL 5.5 與 5.6 設定值的差異整理列出來:「MySQL 5.5 and 5.6 default variable values differences」。

因為這是直接 dump 系統設定值比較,理論上所有「可以設定的值」都可以透過這個方法找出差異,不是靠設定值的改變就沒辦法了...

文章後面有對作者覺得比較需要講的部份提出來。其中 innodb_file_per_table 終於變成預設值了 XD

先繼續觀望...

熱 MySQL 的方法...

看到 jnlin 寫的「利用 Percona Playback warm-up MySQL 資料庫...」,把之前用到的「用 pt-find 加熱 (暖機) InnoDB table」改良讓他可以平行跑,儘可能吃完 I/O capacity:

pt-find --charset=utf8 --print -h $1 -u USER -p PASSWORD | xargs -t -P8 -I% -n1 sh -c "echo 'SELECT COUNT(*) FROM %;' | mysql -h $1 > /dev/null"

在 PostgreSQL 裡分析 PostgreSQL mailing list 行為...

在「Analyzing PostgreSQL Email Archives with PostgreSQL」這篇文章看到的,用 PostgreSQL 所提供的功能找出一些資訊... (像是 full text search 的功能)

於是就產生出這樣的圖:(應該不用解釋?)

還有「Probability that a new thread gets a response」或是與 Competitors 相關的統計 XD

MySQL 平行執行的 Replication...

MySQL Replication – Multi-Threaded Slaves (Parallel Event Execution)」這篇在講 MySQL 5.6 的 multi-threaded replication。

在文章裡提到,在 5.6.3 之前的版本,MySQL replication 都是 single-threaded,所以當 master 可以充分發揮多 CPU 能力時,slave 仍然要一個更新跑完才會跑下一個更新。

舉例來說,假設 master server 上有兩個 thread 在跑:

  • thread 1 正在執行 UPDATE table1 SET foo = 0 WHERE ...; (SQL 1,假定是 CPU bound,需要跑 100 秒)
  • thread 2 正在執行 UPDATE table2 SET bar = 1 WHERE ...; (SQL 2,也假定是 CPU bound,也需要跑 100 秒)

假設 thread 1 先執行完,這時候 slave 就會在跑完的時候收到 SQL 1,然後把資料同步進去。等到 100 秒過去後,再跑 SQL 2,再花 100 秒。這導致了最少 100 秒的 replication lag (master 與 slave 不同步的時間)。

在 master server 執行時會是這樣:

兩個 SQL query 可以同時跑。

到了 slave 時,在 MySQL 5.6.3 之前的 replication 會變成這樣:

可以看到還是得先執行 SQL 1 再執行 SQL 2,所以最長會有 200 秒的 replication lag。

而 5.6.3 之後支援 multi-threaded replication,可以用 slave_parallel_workers 指定平行執行 SQL query 的數量,這讓 master server 與 slave server 之間的 replication lag 降低不少:

在收到同步的 SQL 指令後就可以同時跑,這讓 replication lag 降到 100 秒。

不過還是要提,如果希望把資料同步問題降到最低,那麼 Galera Cluster 可以解的更徹底,不論是寫入的那台 master server,或是其他的 master server (在 Galera Cluster 架構裡都是為 master),一律都是同步執行:

不會有 master server 與 slave server 不同步的問題,可以減少很多 application 層的麻煩...