Capping CPU Usage with Cgroups

Ever felt like you wanted your machine to run slower? No? Well, I have. Sort of.

Ok, I didn’t exactly want it to run slower, rather more predictably. The problem is, some virtual machines you can rent out there in the cloud use CPU bursting, so may run much faster than their default for some limited amount of time. T2 instances on Amazon EC2 being one such example. That’s generally a good thing, but makes life pretty difficult when it comes to benchmarking. You run the same test twice on the same machine and you get two completely different results. Continue reading

Testing Amazon SQS locally with ElasticMQ

If you’re developing an application that uses the Amazon Simple Queue Service (SQS), you may find yourself asking how you can run and test your application locally without having to connect to the real SQS every time. At least, I did – when running our test suite was getting painfully slow.

Luckily, there is at least one option: ElasticMQ provides an SQS-compatible interface.

Continue reading

Scala 2.10 reflection experiments

Scala 2.10.0 is now officially available and includes a new reflection API. The relevant section of the official documentation is still largely missing though, and the feature is marked as “experimental” – with thread-safety being a known issue.

To take it for a spin, I wrote a simple library to serialize and deserialize objects in JSON format, using reflection to auto-detect field names and types. The code is available at Github as Seriala.

Continue reading

Creating a Neo4j graph of Wikipedia links

I started looking at Neo4j and thought: I need to write a simple but non-trivial application to really try it out. Something with lots of nodes and relationships. I need to find a large dataset that I can import into a graph database.

To my delight, I found that Wikipedia provides database dumps for download. That serves my purpose beautifully: I can represent each wiki page as a node, and the links between pages as relationships. Continue reading

Saner Maven Dependencies

Maven’s popularity is partly due to its dependency management feature. It’s easy to add a new JAR to your project and let Maven take care of importing any other JARs required as transitive dependencies.

But this is a double-edged sword. I’ve seen plenty of projects ending up with multiple versions of the same JARs – or multiple versions of the same classes in different JARs – in their classpath. In such cases the Java class loader simply picks classes from the first JAR it finds, with unpredictable results. Most of the time it’s harmless, but occasionally it causes e.g. a NoSuchMethodException at runtime in one environment, despite everything working fine in another environment. Continue reading