Prevayler Asynchronous Writing Patch

A patch to the Prevayler library that enables faster but less reliable performance.

My Homepage

I created a  patch to add support for asynchronous disk writing to Prevayler.

 

Download 

prevayler_patch_for_asyncronous_writing.diff  (5 kb)

 

Motivation

Normally Prevayler writes the transactions synchronously to disk.
That means that the thread won't return from the I/O operation before the transaction has been physically written to the disk.  This ensures reliability, in that once a transaction has been written, it can be rolled back.

However, in some applications performance is more important than high reliability like this.  If the number of transactions per second is significant, the synchronous writing will slow down the execution significantly (in addition to abusing the harddrive with a lot of frequent short writes).

I'm using this for a persistent RPG game server that I'm working on,
where transactions are incoming player actions and world simulation clock ticks.  In this application, it's okay if the transactions from the last few minutes are lost in the event of a server crash, if the system can perform faster because of it.

Changes

The patch enables the user to select between asynchronous and
synchronous disk writing, using the
PrevaylerFactory.configureSyncronousDiskWriting method (the default is still synchronous like before).  Asynchronous disk writing uses Javas normal file flushing, which will write changes to the disk in batches typically every few seconds or so (depending on operating system settings).


The patch modifies three classes: PrevaylerFactory, PersistentJournal, and DurableOutputStream.  It adds some new methods and constructors, but doesn't otherwise change the API.  The default behavior remains unchanged, so it should have no effect on existing applications.


The patch is generated against the Prevayler 2.3 release sources, using unified diff format.