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