You are here: Configuration > File Configuration > Storage > NonFlushingStorage

NonFlushingStorage

NonFlushingStorage is a special IO Storage, which can be used to improve commit performance. Committing is a complex operation and requires flushing to the hard drive after each stage of commit. This is necessary as most operating system try to avoid the overhead of disk access by caching disk write data and only flushing the resulting changes to the disk. In the case of db4o commit it would mean that the physical write of some commit stages will be partially skipped and the data will be irreversibly lost.

However, physical access to the hard drive is a time-consuming operation and may considerably affect the performance. That is where NonFlushingStorage comes in: it allows the operating system to keep commit data in cache and do the physical writes in a most performant order. This may sound very nice, but in fact a system shutdown while the commit data is still in cache will lead to the database corruption.

The following example shows how to use the NonFlushingStorage. You can run it and see the performance improvement on commit stage.

IEmbeddedConfiguration configuration = Db4oEmbedded.NewConfiguration();
IStorage fileStorage = new FileStorage();
// the non-flushing storage improves performance, but risks database corruption.
IStorage cachingStorage = new NonFlushingStorage(fileStorage);
configuration.File.Storage = cachingStorage;
IObjectContainer container = Db4oEmbedded.OpenFile(configuration, "database.db4o");
IOConfigurationExamples.cs: Using the non-flushing storage
Dim configuration As IEmbeddedConfiguration = Db4oEmbedded.NewConfiguration()
Dim fileStorage As IStorage = New FileStorage()
' the non-flushing storage improves performance, but risks database corruption.
Dim cachingStorage As IStorage = New NonFlushingStorage(FileStorage)
configuration.File.Storage = cachingStorage
Dim container As IObjectContainer = Db4oEmbedded.OpenFile(Configuration, "database.db4o")
IOConfigurationExamples.vb: Using the non-flushing storage

Please, remember, that NonFlushingStorage is potentially dangerous and any unexpected system shutdown may corrupt your database. Use with caution and avoid using in production environments.