AppFabric & "Protocol Buffers"

Tagged: technology .net c#

In the last few days I've been struggling with a quite hard task: introducing some caching mechanism in an existing and complex infrastructure, which is already using AppFabric caching (aka: Velocity) in some other areas.

It's been natural to think about using AppFabric again, but due to the peculiar nature of the problem, we had to design a custom caching algorithm, which prepares several blocks containing thousands of objects in a "dictionary" structure (simplified description) and then stores them in AppFabric. That introduced a big serialization problem, which was causing a serious overhead. We were fighting against a scenario where certain tasks took at least 2 minutes to complete (or even more, depending on database response time), and with caching we improved reaching a 50 seconds lower limit, but that was not enough.

So we thought to slightly change the serialization phase introducing protobuf-net, a .NET implementation of the "protocol buffers" mechanism from Google. It is a quite complex library, I mean, it sets up a few constraints over things you want to do with it, like using definition files (.proto) or marking your data structures with custom attributes. Even more, I had to change my DTO because the library did not like a field defined as "object", and I'm sure it has good reasons to behave like that (but I had no time to dig it yet), so I thought it was ok to rewrite some code in order to use it, and after a couple of hours the library was there... and the execution time went down to 14 seconds in the worst case! :) Now we are almost 4 times faster compared with standard serialization.

Definitely, protobuf-net saved my day :)

Add a Comment