大家在猜 Amazon DocumentDB 的底層是不是 PostgreSQL...

Amazon DocumentDB 的出現讓人驚訝的倒不是 AWS 推出這塊服務,而是 AWS 對於這類對 PaaS 有攻擊性的 license model 的反擊姿態。這也導致了在 AWS 推出後 MongoDB 的股價掉了 13%。

另外一方面,大家也都想要知道 AWS 怎麼堆底層的系統,畢竟要從頭開發一個所需要的功夫應該不小... (雖然 AWS 應該有這個能力)

從「Is DocumentDB really PostgreSQL?」這邊看到 Hacker News 上的「My bet is that it is built on top of Aurora PostgreSQL.」這篇討論,透過目前 DocumentDB 的限制,大家在猜 Amazon DocumentDB 是不是拿 PostgreSQL 改出來的...

目前看起來 Identifiers 的 63 chars 限制,單一 collection 的 32TB 限制 (對應到表格),以及 UTF-8 null character 限制,都跟 PostgreSQL 一樣。

也許過一陣子 AWS 的人會找個地方透漏,不過目前看起來只能猜...

AWS 推出 MongoDB 服務:Amazon DocumentDB

AWS 推出了 Amazon DocumentDB 服務,相容於 MongoDB 3.4 3.6 的界面:「New – Amazon DocumentDB (with MongoDB Compatibility): Fast, Scalable, and Highly Available」。

這個新聞其實引起不少關注,不單純是 AWS 支援了 MongoDB service,而是 AWS 對去年一系列 license issue 的態度。

先講 license 的事情,後面再提技術上的差異。

背景是 MongoDB 在去年十月的時候決定換 license,決定從 GNU AGPL 換成他們自己定義的 SSPL:「MongoDB now released under the Server Side Public License」。

相關的報導可以參考 TechCrunch 當時寫的「MongoDB switches up its open-source license」,主要的重點在於:

[T]he SSPL explicitly states that anybody who wants to offer MongoDB as a service — or really any other software that uses this license — needs to either get a commercial license or open source the service to give back the community.

而 AWS 在三個月後的回應也意外的清楚,他直接照著 MongoDB 3.6 版的 API 刻一個出來,不需要用你的軟體提供服務 (所以就不用照你的 license 走):

Amazon DocumentDB implements the Apache 2.0 open source MongoDB 3.6 API by emulating the responses that a MongoDB client expects from a MongoDB server, allowing you to use your existing MongoDB drivers and tools with Amazon DocumentDB.

TechCrunch 下的標題也頗直接,認為 AWS 對這套搞法不怎麼認同:「AWS gives open source the middle finger」。

回到技術上的層面來看,可以看到 Amazon DocumentDB 提供的技術資料看起來跟 Amazon Aurora 很像,都是六份三區:

Amazon DocumentDB uses a purpose-built SSD-based storage layer, with 6x replication across 3 separate Availability Zones.

連 read replica 的限制也都是 15 份,可以「猜測」後面應該是用同一套技術在運作...:

In Amazon DocumentDB, the storage and compute are decoupled, allowing each to scale independently, and developers can increase the read capacity to millions of requests per second by adding up to 15 low latency read replicas in minutes, regardless of the size of your data.

看了一下價錢,最小台是 db.r4.large,需要 USD$0.277/hr,相當於一個月要 USD$200 左右,而且 storage 與 i/o 要另外計算,門檻不算低。

目前主要還是歐美區先上:

Amazon DocumentDB (with MongoDB compatibility) is available now and you can start using it today in the US East (N. Virginia), US East (Ohio), US West (Oregon), and Europe (Ireland) Regions.

隔壁棚的 Redis 不知道有什麼感想...

MongoDB 的 Index 種類

Percona 的人寫了一篇簡單的文章介紹 MongoDB 的 Index:「MongoDB Indexing Types: How, When and Where Should They Be Used?」。

官方文件的「Indexes」算清楚,不過有些地雷沒講,像是 Unique Indexes 只這樣說:

The unique property for an index causes MongoDB to reject duplicate values for the indexed field. Other than the unique constraint, unique indexes are functionally interchangeable with other MongoDB indexes.

但 Percona 的人就有說出「地雷」,算是不錯的補充教材 XDDD

Unique indexes work as in relational databases. They guarantee that the value doesn’t repeat and raise an error when we try to insert a duplicated value. Unique doesn’t work across shards.

話說前陣子聽到傳言抱怨,MongoDB 的文件是行銷 & 團隊寫出來的,一堆限制都沒寫在明顯的地方... XD

MongoDB 的 consistent backup

PerconaGitHub 上放出 MongoDB 的 consistent backup 工具:「Percona-Lab/mongodb_consistent_backup: 1.0 Release Explained」。

程式碼在「Percona-Lab/mongodb_consistent_backup」這邊,首頁也講了對應的條件。

Percona 在 MongoDB 上投入愈來愈多資源了... (但我還是沒很想用 XD)

eBay 把 MongoDB 當 cache layer 的用法...

在「How eBay’s Shopping Cart used compression techniques to solve network I/O bottlenecks」這邊 eBay 描述了他們怎麼解決在 MongoDB 上遇到的問題,不過我看的是他們怎麼用 MongoDB,而不是這次解決的問題:

It’s easier to think of the MongoDB layer as a “cache” and the Oracle store as the persistent copy. If there’s a cache miss (that is, missing data in MongoDB), the services fall back to recover the data from Oracle and make further downstream calls to recompute the cart.

把 MongoDB 當作 cache layer,當 cache miss 的時候還是會回去底層的 Oracle 撈資料計算,這用法頗有趣的...

不拿 memcached 出來用的原因不知道是為什麼,是要找個有 HA 方案的 cache layer 嗎?還是有針對 JSON document 做判斷操作?

vm.swappiness 設成 1 或是 0 的差異

在「MongoDB System Tuning Best Practices」這份投影片裡面看到:

To avoid disk-based swap: 1 (not zero!)

以及:

‘0’ can cause unpredicted behaviour

在 kernel 的說明文件是這樣描述,設成 0 時表示只有在避免 oom 時才會 swap:

This control is used to define how aggressive the kernel will swap memory pages. Higher values will increase agressiveness, lower values decrease the amount of swap. A value of 0 instructs the kernel not to initiate swap until the amount of free and file-backed pages is less than the high water mark in a zone.

設成 1 的想法頗有趣的,來看看在 MySQL 上是不是也有同樣的情況要注意...

MongoDB 的 replica-set 設定

Percona 的人寫了一份文件,以 MySQL DBA 的角度說明兩者在 replication 上的差異,然後示範怎麼在單機上架起三個 MongoDB 並且設定 replica-set:「First MongoDB replica-set Configuration for MySQL DBAs」。

這邊文章拿的是 Percona Server for MongoDB,不過應該也還行,並竟是拿 MongoDB 3.2 改的,而不是完全重寫,所以裡面的步驟拿到原版的 MongoDB 上應該也行...

可以拿 Docker 或是在 AWS 開一台 t2.medium 測試玩看看...

Percona 正式推出相容於 MongoDB 的產品「Percona Server for MongoDB」

Percona 正式推出與 MongoDB 相容的產品 Percona Server for MongoDB:「Percona Delivers Free, Open Source Percona Server for MongoDB」。

挑重點講,其實最重要的是 data engine 多了 Percona 自家的 PerconaFT 以及 FacebookRocksDB

Percona Server for MongoDB offers all the features of MongoDB 3.0 Community Edition, along with two additional storage engine options – PerconaFT and Facebook’s RocksDB

PerconaFT 是基於被併購的 Tokutek 所研發的 TokuDB (Fractal tree index) 而誕生的產品,在效能上有相當的優勢...

如果有機會的話來研究看看吧 :o

Stripe 發表了將 MongoDB 資料倒到 PostgreSQL 的工具:MoSQL

Stripe 是家電子付款的新創公司,相較於既有的電子付款機制 (像是 PayPal),Stripe 所提供的工具與介面對開發者與使用者非常友善。

昨天 Stripe 推出了即時將 MongoDB 的資料倒到 PostgreSQL 的工具 MoSQL:「Announcing MoSQL」。

據官方說法,要撈資料的時候用 SQL 比較方便,而且每個人都懂 SQL,所以他們開發了 MoSQL:

The thing is, we also love SQL. We love the ease of doing ad-hoc data analysis over small-to-mid-size datasets in SQL. We love doing JOINs to pull together reports summarizing properties across multiple datasets. We love the fact that virtually every employee we hire already knows SQL and is comfortable using it to ask and answer questions about data.

由於 PostgreSQL 9.2 支援 JSON 資料結構,感覺很像是要逃離 MongoDB 的工具啊... 雖然官方都不承認 XD