Posted on 2011-12-14 03:14
S.l.e!ep.¢% 閱讀(2188)
評論(1) 編輯 收藏 引用 所屬分類:
FastDB
前不久,項(xiàng)目需要實(shí)時運(yùn)算處理大規(guī)模數(shù)據(jù),因?yàn)轫?xiàng)目要支持多線程,并發(fā)性,事務(wù)性。第一反應(yīng)是要找一個這樣的內(nèi)存數(shù)據(jù)庫,商用的有Oracle的TimesTen和SOUTH KOREA的Altibase,但是費(fèi)用不菲。我們只需要對內(nèi)存數(shù)據(jù)庫的一些簡單操作即可。所以我們就鎖定了開源的fastdb。其代碼非常簡練,一共不過3萬代碼左右,它并不是用想象的SysV IPC mechanism (shmat) 實(shí)現(xiàn),而是用Memory mapping mechanism (mmap) 。雖然使用了部分shmat存儲一些數(shù)據(jù)庫控制變量信息等,但是數(shù)據(jù)還是用內(nèi)存文件映射的。對于千萬級的數(shù)據(jù),其需內(nèi)存是4GB以上,所以感覺用內(nèi)存映射文件數(shù)據(jù)庫更合適。
fastdb實(shí)現(xiàn)的方法重要的幾點(diǎn)特征:
1、內(nèi)存文件映射時更改了系統(tǒng)的自動提交更新頁數(shù)據(jù)機(jī)制,為事務(wù)性性能提高基礎(chǔ)。
2、數(shù)據(jù)庫事務(wù)提交機(jī)制是基于一個影子根頁算法(shadow?root?pages algorithm),對數(shù)據(jù)庫進(jìn)行原子更新操作,所以恢復(fù)非常快。
3、提供游標(biāo)化,結(jié)構(gòu)化語句的查詢。
4、還提供了一個可視化的數(shù)據(jù)查詢工具SUBSQL。
?
?
對于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.