/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package plugs.memdb.hsqldb.test;
/**
*
* @author Administrator
*/
public class MemDbWriteTestUtil {
HqlTestDataCacheBeanDao dao=new HqlTestDataCacheBeanDao();
public void testWrite(int time){
long t1=System.currentTimeMillis();
System.out.println("write to memory:");
TestData tdata=new TestData();
//25k
String c= tdata.getData(25);
HqlTestDataCacheBean e=new HqlTestDataCacheBean();
e.setContent(c);
System.out.println("write to memory start:"+time);
for (int i=0;i<time;i++){
long eid=i;
e.setIpAddressLong(eid);
this. dao.add(e);
// System.out.println("write to memory:"+i);
}
long t2=System.currentTimeMillis();
System.out.println("total:"+ (t2-t1));
double d= (double) (t2-t1) / time ;
System.out.println("avg:"+d +" t:"+(double)1/2);
}
//读取测试
public void testRead(int time){
long t1=System.currentTimeMillis();
System.out.println("read to memory:");
TestData tdata=new TestData();
//25k
String c= tdata.getData(25);
HqlTestDataCacheBean e=new HqlTestDataCacheBean();
e.setContent(c);
System.out.println("read to memory start:"+time);
for (int i=0;i<time;i++){
long eid=i;
e.setIpAddressLong(eid);
this. dao.getClientRealIpByLongIpAddress(i);
// System.out.println("read from memory:"+i);
}
long t2=System.currentTimeMillis();
System.out.println("total:"+ (t2-t1));
double d= (double) (t2-t1) / time ;
System.out.println("avg:"+d +" t:"+(double)1/2);
}
public static void main(String argvs[]){
MemDbWriteTestUtil mu=new MemDbWriteTestUtil();
int s=100*10000;
mu.testWrite(s);
System.out.println(" last:"+ mu.dao.queryList_top_new(10).get(0).getIpAddressLong());
;
mu.testRead(10);
}
}
run:
初始化数据库表执行: CREATE TABLE ipentry_cache (
ipEntryid bigint NOT NULL ,
ipAddress varchar(45),
agentIpAddress varchar(45),
ipAddressLong bigint NULL, totalCount bigint,
lastVisitDay datetime NULL ,
lastVisitDayLong bigint NULL
);
执行:CREATE TABLE ip_limit_iplog_cache (
logid bigint GENERATED BY DEFAULT AS IDENTITY(START WITH 1) NOT NULL primary key ,
ipEntryId bigint NULL ,
addDay varchar(15) ,
dayCount int NULL ,
ipAddress varchar(15),
ipAddressLong bigint NULL
)
执行: CREATE TABLE test_hqldb_data (
ipEntryid bigint NOT NULL ,
ipAddress varchar(45),
agentIpAddress varchar(45),
content varchar(65535),
ipAddressLong bigint NULL, totalCount bigint,
lastVisitDay datetime NULL ,
lastVisitDayLong bigint NULL
);
初始化数据库表
执行: CREATE TABLE ipentry_cache (
ipEntryid bigint NOT NULL ,
ipAddress varchar(45),
agentIpAddress varchar(45),
ipAddressLong bigint NULL, totalCount bigint,
lastVisitDay datetime NULL ,
lastVisitDayLong bigint NULL
);
执行:CREATE TABLE ip_limit_iplog_cache (
logid bigint GENERATED BY DEFAULT AS IDENTITY(START WITH 1) NOT NULL primary key ,
ipEntryId bigint NULL ,
addDay varchar(15) ,
dayCount int NULL ,
ipAddress varchar(15),
ipAddressLong bigint NULL
)
执行: CREATE TABLE test_hqldb_data (
ipEntryid bigint NOT NULL ,
ipAddress varchar(45),
agentIpAddress varchar(45),
content varchar(65535),
ipAddressLong bigint NULL, totalCount bigint,
lastVisitDay datetime NULL ,
lastVisitDayLong bigint NULL
);
write to memory:
write to memory start:100000
total:9141
avg:0.09141 t:0.5
last:0
read to memory:
read to memory start:100
total:2125
avg:21.25 t:0.5
成功构建 (总时间: 14 秒)
10w级别读写:
run:
初始化数据库表
执行: CREATE TABLE ipentry_cache (
ipEntryid bigint NOT NULL ,
ipAddress varchar(45),
agentIpAddress varchar(45),
ipAddressLong bigint NULL, totalCount bigint,
lastVisitDay datetime NULL ,
lastVisitDayLong bigint NULL
);
执行:CREATE TABLE ip_limit_iplog_cache (
logid bigint GENERATED BY DEFAULT AS IDENTITY(START WITH 1) NOT NULL primary key ,
ipEntryId bigint NULL ,
addDay varchar(15) ,
dayCount int NULL ,
ipAddress varchar(15),
ipAddressLong bigint NULL
)
执行: CREATE TABLE test_hqldb_data (
ipEntryid bigint NOT NULL ,
ipAddress varchar(45),
agentIpAddress varchar(45),
content varchar(65535),
ipAddressLong bigint NULL, totalCount bigint,
lastVisitDay datetime NULL ,
lastVisitDayLong bigint NULL
);
write to memory:
write to memory start:100000
total:9141
avg:0.09141 t:0.5
last:0
read to memory:
read to memory start:100
total:2125
avg:21.25 t:0.5
成功构建 (总时间: 14 秒)