More on terracotta and wicket
So recently I have been working on session clustering on Zoomf, which is written in apache wicket.
We decided to go down the terracotta route, because at the time we were running on Jetty and I couldn’t get the WADI clustering to work right, plus terracotta claimed to be easy to get up and running, which in fairness it was. All was going to plan and we deployed the code to our production site. Unfortunately we started running into problems. Basically loads of wicket objects were being created and distributed, because of the way wicket stores pages in its session. With the amount of traffic our site was getting the terracotta distributed garbage collector (dgc) couldn’t keep up, and so the persistent disk store was using up more and more disk space. We’re talking tens of gigabytes here, which is clearly a problem.
After playing around with the different terracotta config options it became apparent that a wicket solution to limit what was distributed was needed.
The simplest solution I could think of was instead of storing the wicket pages as page objects I should serialize them and store them as byte arrays instead. This proved to be as easy as implementing a new wicket IPageMapEntry which does the serialization and deserialization and overriding the getPageMapEntry() method in my base page to make all my pages use the new class.
The new class itself is really simple:
public class NewPageMapEntry extends AbstractPageMapEntry { private transient Page page; private byte[] data; public NewPageMapEntry(final Page page) { this.page = page; data = Objects.objectToByteArray(page); setNumericId(page.getNumericId()); } @Override public Page getPage() { if(this.page == null) { page = (Page) Objects.byteArrayToObject(data); } return page; } }
With any luck the new code should be running Zoomf next week and on Tomcat too (tomcats terracotta support is more mature than jettys). If are are interested seeing the progress of this you can read this thread on the terracotta forum, which was extremely useful. A big thanks to all the guys who helped me on there!
EDIT:
I am now working on a better way for to integrate wicket and terracotta, see this thread for more information.
Tags: terracotta, Wicket