![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
I've just starting to use BDB and was trying to find out how to optimize loading data into db. Below is the code i used to load data; but this one could not beat my SQLite version. I had 6million records to load. In SQLite it took 4~5 mins yet in BDB it took me 12~15 mins. Could someone give me some hints to optimize this. Thanks. Radzi. Db master(NULL, 0); master.open(NULL, "bdbMaster.db", NULL, DB_BTREE, DB_CREATE, 0); Db detail(NULL, 0); detail.set_flags(DB_DUP); detail.open(NULL, "bdbDetail.db", NULL, DB_BTREE, DB_CREATE, 0); std::ifstream inputFile(asciiName.c_str()); unsigned long long offset = 0; union { char buf[4096]; Taiwan2004::OPD r; } opdData; FactTableRecord factRec; long id = 0; char key[2048], prevKey[2048]; memset(prevKey, 0, 2048); while (inputFile.good() && inputFile.peek() != EOF) { offset = inputFile.tellg(); inputFile.getline(opdData.buf, sizeof(opdData.buf)); strcpy(key, GetKey(opdData.r).c_str()); if (std::strcmp(key, prevKey) != 0) { nCons++; Dbt data(key, std::strlen(key)); Dbt key(&nCons, sizeof(nCons)); master.put(NULL, &key, &data, 0); std::strcpy(prevKey, key); } nDet++; FactTableDetailRecord dr; AssignValues(dr, opdData.r); Dbt data(&dr, sizeof(dr)); Dbt key(&nCons, sizeof(nCons)); detail.put(NULL, &key, &data, 0); } master.close(0); detail.close(0); |
#3
| |||
| |||
|
|
Hi, I've done some couple of tests. And it seems that SQLite is faster than BDB. How can it be? I still believe that BDB *should* be faster than SQLite. Or am I wrong? |
#4
| |||
| |||
|
|
Radzi wrote: Hi, I've done some couple of tests. And it seems that SQLite is faster than BDB. How can it be? I still believe that BDB *should* be faster than SQLite. Or am I wrong? Yes, but you often have to be careful to get the best performance. Are the records sorted? -Mike |
#5
| |||
| |||
|
|
No. It was not sorted, since the records has to be read in sequence. I was using the same input file for both. In SQLite I used Prepare and bracket all insert in a Begin-Commit transaction. When I display record no processed; I saw SQLite running at the same speed for all records; whereas BDB started to slow down after 1 million records... |
#6
| ||||
| ||||
|
|
Radzi wrote: No. It was not sorted, since the records has to be read in sequence. I was using the same input file for both. In SQLite I used Prepare and bracket all insert in a Begin-Commit transaction. When I display record no processed; I saw SQLite running at the same speed for all records; whereas BDB started to slow down after 1 million records... Which access method are you using? Btree? Hash? |
|
Have you configured a large enough cache? |
|
http://www.oracle.com/technology/doc...cachesize.html It might help to tune the page size, so that an optimal number of records can fit on each page. http://www.oracle.com/technology/doc.../pagesize.html Are you using transactions? If so are you committing each record or grouping the commits together? |
|
- Alex |
#7
| |||
| |||
|
|
Have you configured a large enough cache? No. Just accept the default one. Similarly with the pagesize. |
#8
| |||
| |||
|
|
No. It was not sorted, since the records has to be read in sequence. I was using the same input file for both. In SQLite I used Prepare and bracket all insert in a Begin-Commit transaction. When I display record no processed; I saw SQLite running at the same speed for all records; whereas BDB started to slow down after 1 million records... |
![]() |
| Thread Tools | |
| Display Modes | |
| |