Posted on 2011-12-14 03:14
S.l.e!ep.¢% 閱讀(2183)
評(píng)論(1) 編輯 收藏 引用 所屬分類(lèi):
FastDB
前不久,項(xiàng)目需要實(shí)時(shí)運(yùn)算處理大規(guī)模數(shù)據(jù),因?yàn)轫?xiàng)目要支持多線(xiàn)程,并發(fā)性,事務(wù)性。第一反應(yīng)是要找一個(gè)這樣的內(nèi)存數(shù)據(jù)庫(kù),商用的有Oracle的TimesTen和SOUTH KOREA的Altibase,但是費(fèi)用不菲。我們只需要對(duì)內(nèi)存數(shù)據(jù)庫(kù)的一些簡(jiǎn)單操作即可。所以我們就鎖定了開(kāi)源的fastdb。其代碼非常簡(jiǎn)練,一共不過(guò)3萬(wàn)代碼左右,它并不是用想象的SysV IPC mechanism (shmat) 實(shí)現(xiàn),而是用Memory mapping mechanism (mmap) 。雖然使用了部分shmat存儲(chǔ)一些數(shù)據(jù)庫(kù)控制變量信息等,但是數(shù)據(jù)還是用內(nèi)存文件映射的。對(duì)于千萬(wàn)級(jí)的數(shù)據(jù),其需內(nèi)存是4GB以上,所以感覺(jué)用內(nèi)存映射文件數(shù)據(jù)庫(kù)更合適。
fastdb實(shí)現(xiàn)的方法重要的幾點(diǎn)特征:
1、內(nèi)存文件映射時(shí)更改了系統(tǒng)的自動(dòng)提交更新頁(yè)數(shù)據(jù)機(jī)制,為事務(wù)性性能提高基礎(chǔ)。
2、數(shù)據(jù)庫(kù)事務(wù)提交機(jī)制是基于一個(gè)影子根頁(yè)算法(shadow?root?pages algorithm),對(duì)數(shù)據(jù)庫(kù)進(jìn)行原子更新操作,所以恢復(fù)非常快。
3、提供游標(biāo)化,結(jié)構(gòu)化語(yǔ)句的查詢(xún)。
4、還提供了一個(gè)可視化的數(shù)據(jù)查詢(xún)工具SUBSQL。
?
?
對(duì)于fastdb的一些使用心得和技巧將繼續(xù)貼出。
?
?
下面是作者給我回的郵件(作者:Konstantin 很熱心):
By default size of FastDB database is limited by 4Gb.
But it also depends on OS limits on maximal size of memory mapped object.
In 32-bit OS it usually smaller than 2Gb.
To support work with larger databases, you need to use 64-bit OS and define dbDatabaseOffsetBits to have some large value than 32.?(for example 40 corresponds to terrabyte database).
Memory mapping mechanism (mmap) also allows shared access to the memory from multiple applications.
The main idea of mapping fiel on memory is that modified pages are automatically stored in the file by OS.
But you can use SysV IPC mechanism (shmat) instead of mmap if for some reasons use of mmap is not desired.