Slashdot 的 Comment 數超過 MEDIUMINT 的限制

上看到這則讓人 XD 的報導:Slashdot Posting Bug Infuriates Haggard Admins

的後端是 ,Comment 都放在同一個 Table 裡面。一開始他們用 MEDIUMINT (224) 來放 Comment ID,在五年前的時候他們改成 Unsigned Integer (232),但是忘了改 Index 的部分,於是昨天就出問題了...

裡把 Index 改好其實也很簡單,只是一個 ALTER 指令,但是在一千多萬筆資料的 Table 裡重建 Index 最少要三個小時,所以只好發一篇文章跟大家道歉,因為為了轉換會關掉一些功能... XD



  • 只要有 (key,value) 即可,不需要到 SQL 那種複雜的架構
  • 可以用多台機器 Cluster,並且有 Replication,不受到單一機器的 Bottleneck
  • 不存在 Single Point of Failure
  • 可線上擴充機器

的 Replication (即 Single Master, Read-only Slave) 最後會卡在 Writing,而且空間的消耗讓人不是很滿意。 的架構仍然有 Single Point of Failure (我想他們應該是用 Layer 4 Switch 或是其他配合硬體的方式解決),所以我想問的是,有沒有數學方法就可以滿足上面要求的資料庫?

Update:我希望每個 node 都是 1TB,初期大約三十台到六十台機器,以後可以擴充到上千台,每個 key 都會有四份資料放在 DB 裡面。



這裡看到 4.1 之後的版本可以有 INSERT ... ON DUPLICATE KEY UPDATE 這種用法:MySQL Counters。引用的原文在 INSERT ON DUPLICATE KEY UPDATE and summary counters. 這篇。

如果你對於 race condition 有瞭解,你可以在文章裡看到這種用法將本來要自己做的檢查交給 處理:

INSERT INTO ipstat VALUES(inet_aton(''), 1, now()) ON duplicate KEY UPDATE hits = hits + 1;

這個功能在 4.1 以及之後的版本有提供。

一些改進 PHP 與 MySQL 效率的技巧

看到的:Simple Optimization for PHP and MySQL,原文在 Simple Optimization for PHP and MySQL 這裡,其實都是一些習慣問題積少成多。

的部分在 裡都有講到。 的部分有些是經驗,倒是可以看一看...


是一套多人修改自 的軟體,以提供多人使用。WordPress and Lyceum 這篇提到關於 對於資料庫的設計:

From my examination of the code, it seems it’s exactly what is except they’ve modified every SQL statement (what a pain!) to use a monolithic table structure. We tested this approach for MU, but found it was too expensive to scale past a certain point. With monolithic structures you hit a wall based on your hardware.

In MU users are divided and can be partitioned easily, for example on we have the users partitioned between 4096 databases, which allows you to scale very cheaply and efficiently to hundreds of thousands and even millions of users and extremely high levels of traffic.

結果 對於 Database 的作法都一樣... (默)

MySQL 4.x/5.0 安全問題

MySQL 4.x/5.0 User-Defined Function Local Privilege Escalation Exploit,還看到 cvs tag...:

 * $Id: raptor_udf2.c,v 1.1 2006/01/18 17:58:54 raptor Exp $
 * raptor_udf2.c - dynamic library for do_system() MySQL UDF
 * Copyright (c) 2006 Marco Ivaldi <>
 * This is an helper dynamic library for local privilege escalation through
 * MySQL run with root privileges (very bad idea!), slightly modified to work 
 * with newer versions of the open-source database. Tested on MySQL 4.1.14.

Oracle 與 Sleepycat 的消息

Greg Linden 的 Blog 上看到 想要買下 (也就是目前搞 Berkeley DB 的公司) 的新聞:Oracle to buy Sleepycat?。原新聞在 Oracle's Open-Source Shopping Spree

如果成真, 又有一個 Backend 被買走... (上次是 目前唯一支援 Row-Locking 的 Backend)

Update 【已經】被 買下了,參考:Oracle buys Sleepycat Software

FreeBSD 6.0 MySQL Performance

I use databases/mysql50-{client,server} and use benchmarks/super-smack to test. There are 3*2*2*2 = 24 cases:

  • Compile options: none, WITH_PROC_SCOPE_PTH=yes, WITH_LINUXTHREADS=yes
  • /etc/libmap.conf: none (libpthread), libthr
  • kern.timecounter.choice: ACPI-fast, TSC

These benchmarking were tested on my laptop (IBM x31 2672-IQV, Pentium-M 1.5G with 512MB RAM), and powerd was disabled. Detail informations (dmesg, sysctl, and kernel config file) will post later.

The commands are:

for i in 1 2 3 4 5; do super-smack select-key.smack 10 1000 | grep select_index; done
for i in 1 2 3 4 5; do super-smack update-select.smack 10 1000 | grep select_index; done


select_index    20000   0       0       14097.47
select_index    20000   0       0       13741.43
select_index    20000   1       0       13704.01
select_index    20000   0       0       13626.05
select_index    20000   0       0       13769.32
select_index    10000   2       0       1891.63
select_index    10000   2       0       1758.65
select_index    10000   2       0       1836.00
select_index    10000   4       0       2058.71
select_index    10000   14      0       2050.05

Continue reading "FreeBSD 6.0 MySQL Performance"