BerkeleyDB和eXtremeDB性能在LINUX下的比较.docx
《BerkeleyDB和eXtremeDB性能在LINUX下的比较.docx》由会员分享,可在线阅读,更多相关《BerkeleyDB和eXtremeDB性能在LINUX下的比较.docx(18页珍藏版)》请在冰豆网上搜索。
![BerkeleyDB和eXtremeDB性能在LINUX下的比较.docx](https://file1.bdocx.com/fileroot1/2022-12/30/2a7118ed-2eae-45c0-9e78-1a0eebcd8406/2a7118ed-2eae-45c0-9e78-1a0eebcd84061.gif)
BerkeleyDB和eXtremeDB性能在LINUX下的比较
BerkeleyDB和eXtremeDB性能在LINUX下的比较
1、BerkeleyDB测试源程序:
#include
#include
#include
#include
#include
#ifdef_WIN32
externintgetopt(int,char*const*,constchar*);
#else
#include
#endif
#include"db.h"
externvoid__os_clock__P((DB_ENV*,u_int32_t*,u_int32_t*));
voidusage__P((void));
structdb_time{
u_int32_tsecs,usecs;
};
structdb_time start_time,end_time;
u_int32_t pagesize=32*1024;
u_int bulkbufsize=4*1024*1024;
u_int logbufsize=8*1024*1024;
u_int cachesize=32*1024*1024;
u_int datasize=32;
u_int keysize=8;
u_int numitems=0;
FILE *fp;
char *progname;
voidop_ds(u_int,int);
voidop_ds_bulk(u_int,u_int*);
voidop_tds(u_int,int,u_int32_t);
voidres(char*,u_int);
void
res(char*msg,u_intops)
{
doubleelapsed;
structdb_timev;
v.secs=end_time.secs-start_time.secs;
v.usecs=end_time.usecs-start_time.usecs;
if(start_time.usecs>end_time.usecs){
v.secs--;
v.usecs+=1000000;
}
elapsed=v.secs+v.usecs/1e6;
printf("%s\n\telapsedtime:
%fseconds:
%gkey/datapairspersec\n",
msg,elapsed,ops/elapsed);
}
void
op_ds(u_intops,intupdate)
{
char*letters="abcdefghijklmnopqrstuvwxuz";
DB*dbp;
DBTkey,data;
char*keybuf,*databuf;
DB_MPOOL_STAT *gsp;
(void)remove("a");
assert((keybuf=malloc(keysize))!
=NULL);
assert((databuf=malloc(datasize))!
=NULL);
memset(&key,0,sizeof(key));
memset(&data,0,sizeof(data));
key.data=keybuf;
key.size=keysize;
memset(keybuf,'a',keysize);
data.data=databuf;
data.size=datasize;
memset(databuf,'b',datasize);
assert(db_create(&dbp,NULL,0)==0);
dbp->set_errfile(dbp,stderr);
assert(dbp->set_pagesize(dbp,pagesize)==0);
assert(dbp->open(dbp,NULL,NULL,NULL,DB_BTREE,DB_CREATE,0666)==0);
dbp->dbenv->memp_stat(dbp->dbenv,&gsp,NULL,DB_STAT_CLEAR);
if(update){
__os_clock(NULL,&start_time.secs,&start_time.usecs);
for(;ops>0;--ops){
keybuf[(ops%keysize)]=letters[(ops%26)];
assert(dbp->put(dbp,NULL,&key,&data,0)==0);
}
__os_clock(NULL,&end_time.secs,&end_time.usecs);
}else{
assert(dbp->put(dbp,NULL,&key,&data,0)==0);
__os_clock(NULL,&start_time.secs,&start_time.usecs);
for(;ops>0;--ops)
assert(dbp->get(dbp,NULL,&key,&data,0)==0);
__os_clock(NULL,&end_time.secs,&end_time.usecs);
}
dbp->dbenv->memp_stat(dbp->dbenv,&gsp,NULL,0);
assert(gsp->st_cache_miss==0);
assert(dbp->close(dbp,0)==0);
}
void
op_ds_bulk(u_intops,u_int*totalp)
{
DB*dbp;
DBC*dbc;
DBTkey,data;
u_int32_tlen,klen;
u_inti,total;
char*keybuf,*databuf;
void*pointer,*dp,*kp;
DB_MPOOL_STAT *gsp;
(void)remove("a");
assert((keybuf=malloc(keysize))!
=NULL);
assert((databuf=malloc(bulkbufsize))!
=NULL);
memset(&key,0,sizeof(key));
memset(&data,0,sizeof(data));
key.data=keybuf;
key.size=keysize;
data.data=databuf;
data.size=datasize;
memset(databuf,'b',datasize);
assert(db_create(&dbp,NULL,0)==0);
dbp->set_errfile(dbp,stderr);
assert(dbp->set_pagesize(dbp,pagesize)==0);
assert(dbp->set_cachesize(dbp,0,cachesize,1)==0);
assert(dbp->open(dbp,NULL,NULL,NULL,DB_BTREE,DB_CREATE,0666)==0);
for(i=1;i<=numitems;++i){
(void)sprintf(keybuf,"%10d",i);
assert(dbp->put(dbp,NULL,&key,&data,0)==0);
}
#if0
fp=fopen("before","w");dbp->set_msgfile(dbp,fp);
assert(dbp->stat_print(dbp,DB_STAT_ALL)==0);
#endif
assert(dbp->cursor(dbp,NULL,&dbc,0)==0);
data.ulen=bulkbufsize;
data.flags=DB_DBT_USERMEM;
dbp->dbenv->memp_stat(dbp->dbenv,&gsp,NULL,DB_STAT_CLEAR);
if(ops>10000)
ops=10000;
__os_clock(NULL,&start_time.secs,&start_time.usecs);
for(total=0;ops>0;--ops){
assert(dbc->c_get(
dbc,&key,&data,DB_FIRST|DB_MULTIPLE_KEY)==0);
DB_MULTIPLE_INIT(pointer,&data);
while(pointer!
=NULL){
DB_MULTIPLE_KEY_NEXT(pointer,&data,kp,klen,dp,len);
if(kp!
=NULL)
++total;
}
}
__os_clock(NULL,&end_time.secs,&end_time.usecs);
*totalp=total;
dbp->dbenv->memp_stat(dbp->dbenv,&gsp,NULL,0);
assert(gsp->st_cache_miss==0);
#if0
fp=fopen("before","w");dbp->set_msgfile(dbp,fp);
assert(dbp->stat_print(dbp,DB_STAT_ALL)==0);
#endif
/*assert(dbp->close(dbp,0)==0);*/
}
void
op_tds(u_intops,intupdate,u_int32_ttxn_flags)
{
DB*dbp;
DBTkey,data;
DB_ENV*dbenv;
DB_TXN*txn;
char*keybuf,*databuf;
DB_MPOOL_STAT *gsp;
#ifndef_WIN32
(void)system("rm-rfTESTDIR;mkdirTESTDIR");
#endif
assert((keybuf=malloc(keysize))!
=NULL);
assert((databuf=malloc(datasize))!
=NULL);
memset(&key,0,sizeof(key));
memset(&data,0,sizeof(data));
key.data=keybuf;
key.size=keysize;
memset(keybuf,'a',keysize);
data.data=databuf;
data.size=datasize;
memset(databuf,'b',datasize);
assert(db_env_create(&dbenv,0)==0);
dbenv->set_errfile(dbenv,stderr);
assert(dbenv->set_flags(dbenv,DB_AUTO_COMMIT|txn_flags,1)==0);
assert(dbenv->set_lg_bsize(dbenv,logbufsize)==0);
assert(dbenv->open(dbenv,"TESTDIR",
DB_CREATE|DB_PRIVATE|DB_INIT_LOCK|
DB_INIT_LOG|DB_INIT_MPOOL|DB_INIT_TXN,
0666)==0);
assert(db_create(&dbp,dbenv,0)==0);
assert(dbp->set_pagesize(dbp,pagesize)==0);
assert(dbp->open(dbp,NULL,"a",
NULL,DB_BTREE,DB_CREATE,0666)==0);
if(update){
dbenv->memp_stat(dbenv,&gsp,NULL,DB_STAT_CLEAR);
__os_clock(NULL,&start_time.secs,&start_time.usecs);
for(;ops>0;--ops){
assert(dbenv->txn_begin(dbenv,NULL,&txn,0)==0);
assert(dbp->put(dbp,NULL,&key,&data,0)==0);
assert(txn->commit(txn,0)==0);
}
__os_clock(NULL,&end_time.secs,&end_time.usecs);
dbenv->memp_stat(dbenv,&gsp,NULL,0);
assert(gsp->st_page_out==0);
}else{
assert(dbp->put(dbp,NULL,&key,&data,0)==0);
dbenv->memp_stat(dbenv,&gsp,NULL,DB_STAT_CLEAR);
__os_clock(NULL,&start_time.secs,&start_time.usecs);
for(;ops>0;--ops){
assert(dbenv->txn_begin(dbenv,NULL,&txn,0)==0);
assert(dbp->get(dbp,NULL,&key,&data,0)==0);
assert(txn->commit(txn,0)==0);
}
__os_clock(NULL,&end_time.secs,&end_time.usecs);
dbenv->memp_stat(dbenv,&gsp,NULL,0);
assert(gsp->st_cache_miss==0);
}
assert(dbp->close(dbp,0)==0);
assert(dbenv->close(dbenv,0)==0);
}
int
main(intargc,char*argv[])
{
externchar*optarg;
externintoptind;
u_intops,total;
intch;
intmajor,minor,patch;
if((progname=strrchr(argv[0],'/'))==NULL)
progname=argv[0];
else
++progname;
ops=100000;
while((ch=getopt(argc,argv,"d:
k:
o:
p:
"))!
=EOF)
switch(ch){
case'd':
datasize=(u_int)atoi(optarg);
break;
case'k':
keysize=(u_int)atoi(optarg);
break;
case'o':
ops=(u_int)atoi(optarg);
break;
case'p':
pagesize=(u_int32_t)atoi(optarg);
break;
case'?
':
default:
usage();
}
argc-=optind;
argv+=optind;
numitems=(cachesize/(keysize+datasize-1))/2;
db_version(&major,&minor,&patch);
printf("UsingBerkeleyDB%d.%d.%d-",major,minor,patch);
printf("ops:
%u;keysize:
%d;datasize:
%d\n",ops,keysize,datasize);
op_ds(ops,0);
res("DS(read):
",ops);
if(keysize>=8){
op_ds_bulk(ops,&total);
res("DS(bulkread):
",total);
}else{
printf("DS(bulkread):
\n");
printf("\tskipped:
bulkgetrequiresakeysize>=10\n");
}
op_ds(ops,1);
res("DS(write):
",ops);
op_tds(ops,0,0);
res("TDS(read):
",ops);
op_tds(ops,1,DB_LOG_INMEMORY);
res("TDS(write,in-memorylogging):
",ops);
op_tds(ops,1,DB_TXN_NOSYNC);
res("TDS(write,no-synconcommit):
",ops);
op_tds(ops,1,DB_TXN_WRITE_NOSYNC);
res("TDS(write,write-no-synconcommit):
",ops);
op_tds(ops,1,0);
res("TDS(write,synconcommit):
",ops);
return(EXIT_SUCCESS);
}
void
usage()
{
fprintf(stderr,
"usage:
%s[-ddatasize][-kkeysize][-oops][-ppagesize]\n",
progname);
exit
(1);
}
2、eXtremeDB测试源程序:
/*****************************************************************
* *
*Copyright(c)2001-2006McObjectLLC.AllRightReserved. *
* *
*****************************************************************/
/*ThistestallowstoreceivesomeresultsabouttheeXtremeDBperformance
*forallbasicoperations.ThistestinsertsNobjectsintoaclass,creating
*ahashindexasitdoesinsertions;thenseparatellybuildsatreeindex,
*performssearchesusingatreeandahashtable,anasequentialsearch.
*Atlastthetreeisremovedandalltheobjectaredeletedone-by-one.
*EachInsetrtionanddeletiondoneinaseparatetransaction,sothe
*committimeisincludedinthemeasurements.
*/
#include
#include
#include
#include
//#include
#include"perf2.h"
/*Makesureyou'vegotthis16M,otherwiseyou'llbemeasuring
*theperformanceofyourdisk.
*/
#defineDBSIZE (1024*16000)
#definePAGESIZE 128
constintMAP_ADDRESS= 0x20000000;
/*Ifyouchangethenumberofobjectsinserted,makesurethatyou
*firsthaveenoughmemory(DBSIZE),andalsodecalredhashtable
*sizeappropriatelly(hkey[estimated_numeber_of_entries]inperf2.mco
*/
constintnRecords=100000;
void_SH_(void){
chartext[]={
"\nThistestallowstoreceivesomeresultsabouttheeXtremeDB\n"
"performance