Initial object storing requires little calculation, but can be resource consuming on disk access. Therefore the main hardware resource that will affect db4o insert performance is the hard drive. The faster is the hard drive the better performance you will get.
An alternative to a hard drive database storage can be a database file stored in RAM. This can be done by placing the database file in a designated RAM-drive or by using db4o memory io-adapter:
.NET:
configuration.Io(new MemoryIoAdapter());
The following test can be performed to compare performance of a hard drive and a RAM drive:
01private void RunRamDiskTest() 02
{ 03
04
ConfigureRamDrive(); 05
06
InitForHardDriveTest(); 07
Clean(); 08
System.Console.WriteLine("Storing " + _count + " objects of depth " + _depth + " on a hard drive:"); 09
Open(); 10
Store(); 11
Close(); 12
13
InitForRamDriveTest(); 14
Clean(); 15
System.Console.WriteLine("Storing " + _count + " objects of depth " + _depth + " on a RAM disk:"); 16
Open(); 17
Store(); 18
Close(); 19
}
1private void ConfigureRamDrive() 2
{ 3
IConfiguration config = Db4oFactory.Configure(); 4
config.LockDatabaseFile(false); 5
config.WeakReferences(false); 6
config.FlushFileBuffers(true); 7
}
1private void InitForHardDriveTest() 2
{ 3
_count = 100000; 4
_depth = 3; 5
_filePath = "performance.db4o"; 6
_isClientServer = false; 7
}
1private void InitForRamDriveTest() 2
{ 3
_count = 100000; 4
_depth = 3; 5
_filePath = "r:\\performance.db4o"; 6
_isClientServer = false; 7
}
01private void Store() 02
{ 03
StartTimer(); 04
for (int i = 0; i < _count; i++) 05
{ 06
Item item = new Item("load", null); 07
for (int j = 1; j < _depth; j++) 08
{ 09
item = new Item("load", item); 10
} 11
objectContainer.Set(item); 12
} 13
objectContainer.Commit(); 14
StopTimer("Store " + TotalObjects() + " objects"); 15
}
The RAM driver was downloaded here and installed on R:\ drive.
The following results were achieved for the testing configuration:
.NET:
Storing 100000 objects of depth 3 on a hard drive:
Store 300000 objects: 18629ms
Storing 100000 objects of depth 3 on a RAM disk:
Store 300000 objects: 17752ms