最近需要一个大Map保存大量KV,找了一下最新的JDBM4(已经重命名为MapDB)来测了一下性能,性能不错~
1亿条记录测试:
5千万读,5千万写:103417 ms
1亿条记录读:1ms<
十万条记录平均处理时间: 1295 ns
1亿条记录+(测试过3亿条)
时间成线性增长
import java.io.File; import java.util.Map; import org.mapdb.DB; import org.mapdb.DBMaker; public class StatMapDB { private static final String MAP_NAME = "STAT_MAP"; private String filePath; DB db = null; Map<Long,Long> statMap = null; DBMod type = null; static enum DBMod { READ, WRITE } public StatMapDB(String filePath,DBMod type) { this.filePath = filePath; this.type = type; init(); } private void init() { File file = new File(filePath); db = DBMaker .newFileDB(file) .transactionDisable() .asyncFlushDelay(100) .make(); if(type.equals(DBMod.WRITE)) { if(file.exists()) { file.delete(); new File(filePath + ".p").delete(); } statMap = db.createTreeMap(MAP_NAME).make(); } else{ statMap = db.getTreeMap(MAP_NAME); } } public Map<Long,Long> getStatMapDB() { return this.statMap; } public void close() { if(db!=null){ db.close(); db = null; } } }
import java.util.Map; import java.util.Map.Entry; public class TestApp { private static final String PATH = "test"; //private static long TOTAL = 10000; private static long TOTAL = 100000000; private static void write() { StatMapDB db = new StatMapDB(PATH, StatMapDB.DBMod.WRITE); Map<Long,Long> map = db.getStatMapDB(); long sum = 0; long count = 0; long startTime = System.currentTimeMillis(); for (long i = -1 * TOTAL / 2; i < TOTAL / 2; i++) { Long key = Math.abs(i); long oneStartTime = System.nanoTime(); if (!map.containsKey(key)) { map.put(key, key); } else { map.put(key, map.get(key) + key); } if (i % 100000 == 0) { sum += (System.nanoTime() - oneStartTime); count++; } } System.out.println("avg:" + sum / count + " ns"); System.out.println("write 10 million times:" + (System.currentTimeMillis() - startTime) + " ms"); db.close(); } private static void read() { StatMapDB db = new StatMapDB(PATH, StatMapDB.DBMod.READ); Map<Long,Long> map = db.getStatMapDB(); long startTime = System.currentTimeMillis(); for (Entry<Long, Long> entry : map.entrySet()) { Long key = entry.getKey(); Long value = entry.getValue(); } System.out.println("read 10 million times:" + (System.currentTimeMillis() - startTime) + " ms"); db.close(); } public static void main(String[] args) { write(); read(); } }
相关推荐
标签:apollo-jdbm2-1.0-beta4.jar,apollo,jdbm2,1.0,beta4,jar包下载,依赖包
JDBM3, 嵌入式 key-value Java数据库 注意:这个项目处于维护模式,我将精力转向 JDBM4,这应该提供更好的并发可以伸缩性。JDBM提供由磁盘存储备份的TreeMap,HashMap和其他集合。 现在你可以处理数十亿项而不用耗尽...
标签:apacheds-jdbm-1.5.7.jar.zip,apacheds,jdbm,1.5.7,jar.zip包下载,依赖包
jdbm NMS
标签:apacheds-jdbm-1.5.4.jar.zip,apacheds,jdbm,1.5.4,jar.zip包下载,依赖包
标签:activemq-store-jdbm-2.1.jar.zip,activemq,store,jdbm,2.1,jar.zip包下载,依赖包
标签:apollo-jdbm2-1.0-beta4-javadoc.jar,apollo,jdbm2,1.0,beta4,javadoc,jar包下载,依赖包
标签:apollo-jdbm2-1.0-beta4-sources.jar,apollo,jdbm2,1.0,beta4,sources,jar包下载,依赖包
标签:apollo-jdbm2-1.0-beta4-scaladoc.jar,apollo,jdbm2,1.0,beta4,scaladoc,jar包下载,依赖包
磁盘的KV存储 JDBM2
磁盘的KV存储 JDBM2.7z
基于Java的磁盘的KV存储 JDBM2.zip
基于java的磁盘的KV存储 JDBM2.zip
对话框调用文件,并画出取线,比较简单,适合初学者,
标签:activemq-store-jdbm-1.4.jar.zip,activemq,store,jdbm,1.4,jar.zip包下载,依赖包
标签:apollo-jdbm2-1.0-beta2.jar,apollo,jdbm2,1.0,beta2,jar包下载,依赖包
标签:apollo-jdbm2-1.0-beta3.jar,apollo,jdbm2,1.0,beta3,jar包下载,依赖包
标签:apollo-jdbm2-1.0-beta5.jar,apollo,jdbm2,1.0,beta5,jar包下载,依赖包
标签:activemq-store-jdbm-1.5.jar.zip,activemq,store,jdbm,1.5,jar.zip包下载,依赖包
标签:activemq-store-jdbm-2.0.jar.zip,activemq,store,jdbm,2.0,jar.zip包下载,依赖包