Persistence

Christian Decker wrote this late at night:

 

Data Persistence is probably one of the hardest things to implement in a modern application, because one has to handle huge amounts of data, needs it to be done very fast not to waste too much time, and it needs to be done correctly, because nothing is more annoying, not to say dangerous, is an application gets its data out of sync or looses part of it.

We had chosen Prevayler to manage the persistence Layer on WW2, but we suddenly realised that this is not an optimal solution. Being not as configurable as one might expect we had to hack some of the sources and find complex workarounds for the problems. Prevayler just serializes all the content of the memory at regular intervals. The only thing you can configure is what the base object is, from thereon you have no control at all about what is serialized and what isn’t, therefore you have to model the data-layer as a self-contained structure. That isn’t really a big problem since it is a good practice not to mix too much the business logic layer and the data layer. Next everything that modifies the data has to be modelled as self-contained Transaction therefore generating a huge overhead, which would still be acceptable compared to Database serialization. Last but not least (in fact this is the main point for our decision not to use Prevayler) is that since it serialized the objects right on files when a class changes, all objects of that type are useless and most likely to throw out some Exceptions, and therefore making the data useless. This is not only a disadvantage during the actual programming of the System but also during runtime since if a bug was found we’d had to reset the data if it is to be fixed by changing one of the data layer classes.

In a blog post I recently read there is a detailed analyse of Prevayler, here are some interesting points:

  • Only one such transaction can run at a time - no parallelism allowed.
  • it [the snapshot]’s the raw output of ObjectOutputStream.writeObject() called on your object tree. … There’s no Prevayler control pieces or boundaries induced. Just your raw, entire Object tree. Quite advanced, wouldn’t you say? Worthy of a revolution, even.
  • There’s no rollback/undo, no locking, no thought whatsoever for concurrency in any form.
There are many more good points in this article which I strongly suggest to read emoticon

 

As for our project we decided to drop Prevayler and look for a standard solution, like Hibernate.

 For more information about Persistence Layers for Java applications I’d suggest you to read this article which might give you a quick overview about existing persistence layers and points to some in depth reading too.

World War 2: The Game

Christian Decker wrote this late at night:

For some weeks now, some Friends of mine and I are working on a next generation browser game. Why next generation? Well it’s completely Web 2.0 emoticon
Basically we have 4 Components:

  •  The AJAX Frontend, which will be the part the user spends his time on. Its Task is to visually display all the data to the user in a nice way. Currently we’re thinking about using the community edition of BackBase which looks really nice and is easy to use. And now a thing the AJAX-Community has been waiting for: we’ll use the Google Maps API as a the base framework for our maps. That means you move your troops on the real map. We’ll discuss the map later on.
  • The Web-Server, which doesn’t do really much being relieved of the task of handling layout and such stuff it will serve the static pages that are used to bootstrap the game itself, and then it is used to generate the XML-Files containing the game data. We’re currently using Tomcat since it allows us to use the Java objects that are then used in the WorkHorse/Simulator directly (more or less as you’ll see later).
  • The persister, which has the task of managing the whole lot of data that we generate and make sure we don’t loose anything. The persister is based upon Prevayler which allows us to keep a "cloud of object" without the need to save and reload to a flat structure like an SQL-Database everytime we do something, all the references are kept in place and no extra loading is done for queries, while for commands we have a slight overhead to create and serialize Transactions.
  • And last but not least the WorkHorse/Simulator! This is the part where the magic happens emoticon. The WorkHorse is a Program that accesses directly the data in the persister (in fact until we find a better way to communicate persister and workhorse are part of the same Process…) that accesses a Priority Queue containing Events. The Events have a scheduled execution time and are processed one after another. Events may be simple tasks light change the password of a user, or really complex stuff like simulation of whole battles, in which case a separate Thread is launched to do the actual execution of the Event.

We played around with different technologies for the communication, which is absolutely non-trivial. The Persister has to be accessible by both the WorkHorse and the Web-Server, we therefore had to split the whole in 3 parts which communicate with each other:

  • The Web-Server mainly executes queries to the persister, asking for new information which is then passed to the AJAX-Frontend. All user interactions, such as sending a troup from one place to another, is then created as Transactions and passed back to the Persister for this a JMS-Server would be good enough.
  • The WorkHorse has to access in an efficient way the data in the persister, this means we have to be able to access the Object structure directly without serializing stuff to be send over a Connection. We thought about using RMI but let the thought drop soon since it restricts the way we can interact with objects. For now we have put the persister and the WorkHorse together, but we are brainstorming to find a better solution.
Well I think this about enough chatter for today, let’s get back to work emoticon