這是我的官方第一個問題,我歡迎對我的帖子的任何/所有批評,以便我可以學習如何成爲一個更好的SO公民。比較MongoDB和RethinkDB Bulk插入性能
我正在審覈非關係型數據庫管理系統,用於存儲可能使用各自的Python客戶端庫的大型電子郵件退出列表,傾向於MongoDB或RethinkDB。我的應用程序的難點在於批量插入性能,所以我已經設置了兩個Python腳本,以便將5,000個批量的20,000條記錄插入到MongoDB和RethinkDB集合中。
MongoDB的Python腳本mongo_insert_test.py:
NUM_LINES = 20000
BATCH_SIZE = 5000
def insert_records():
collection = mongo.recips
i = 0
batch_counter = 0
batch = []
while i <= NUM_LINES:
i += 1
recip = {
'address': "test%[email protected]%d.com" % (i, i)
}
if batch_counter <= BATCH_SIZE:
batch.append(recip)
batch_counter += 1
if (batch_counter == BATCH_SIZE) or i == NUM_LINES:
collection.insert(batch)
batch_counter = 0
batch = []
if __name__ == '__main__':
insert_records()
幾乎相同的RethinkDB python腳本rethink_insert_test.py:
NUM_LINES = 20000
BATCH_SIZE = 5000
def insert_records():
i = 0
batch_counter = 0
batch = []
while i <= NUM_LINES:
i += 1
recip = {
'address': "test%[email protected]%d.com" % (i, i)
}
if batch_counter <= BATCH_SIZE:
batch.append(recip)
batch_counter += 1
if (batch_counter == BATCH_SIZE) or i == NUM_LINES:
r.table('recip').insert(batch).run()
batch_counter = 0
batch = []
if __name__ == '__main__':
insert_records()
在我的開發環境,MongoDB的腳本插入20,000條記錄中下秒:
$ time python mongo_insert_test.py
real 0m0.618s
user 0m0.400s
sys 0m0.032s
在相同的環境中,R ethinkDB腳本執行慢得多,在過了2分鐘插入20,000條記錄:
$ time python rethink_insert_test.py
real 2m2.502s
user 0m3.000s
sys 0m0.052s
我缺少的東西在這裏龐大對於這兩個數據庫管理系統是如何工作的?爲什麼RethinkDB在這個測試中表現得如此糟糕?
我的開發機器有大約1.2GB的可用內存用於這些測試。
標題說明了一切;)http://www.rethinkdb.com/blog/the-benchmark-youre-reading-is-probably-wrong/ – 2013-03-21 16:44:14
@FabianoPS,我沒有真正瞄準任何科學的東西;只是想知道爲什麼要花更多的時間在Rethink上做和MongoDB一樣的操作。我不認爲網絡/磁盤延遲扮演了很多角色(如果有的話)。反思已經發布了一個更新,以一種有希望的有意義的(非膚淺的)方式來解決這個問題。 – njyunis 2013-03-22 17:26:22
嗨@njyunis嗨@njyunis,這篇文章在它的核心信息中有很多有趣的地方:有很多解釋速度的寫作,這是一個評論而不是答案 – 2013-03-22 23:46:03