Latest Articles

The Cost Of Consistency: When 9ms Is 1s Too Much

The CAP theorem remains one of the most important tools in my software developer's toolbelt. Used correctly, it can help create services and products that can offer an excellent user experience and protect revenue during partial failures. Used incorrectly, it can lead to a poor user experience and loss of revenue. Throughout this article, I look to explain the unexpected latency of specific transactions in MySQL, a CP system.

Pessimistic Optimism: The Case Of Unexpected Deadlocks

Despite the fact I've been developing software in one way or another for almost 20 years, I'm constantly surprised how things work, and, once the frustration wears off, I'm intrigued when things break. Lucky for me, over the last few weeks, I've been surprised, frustrated, and intrigued by what, on the surface, seems like a very trivial problem: MySQL reporting deadlocks in unexpected places and unexplainable slow query log entries when using optimistic concurrency control.

Perceiving The Effects Of Cache Coherency In Spin Locks

The "test-and-test-and-set" algorithm is a fairly well-understood solution to reducing latency in spin locks. In particular, the algorithm is often employed to reduce the latency exhibited in the similar "test-and-set" algorithm. Understanding how and why a seeming-superfluous read results in lower latency is rather interesting.

Downcasting Longs To Ints On x86

Last week, my esteemed colleague and close friend asked a remarkably straight-forward question about downcasting a long to an int in Java. I'll admit the question caught me off guard. While the JLS offered the correct answer, I couldn't help but ponder what's actually happening in the machine.

The Concurrency Of ConcurrentHashMap

Java's ConcurrentHashMap is an excellent point of study when learning about Java's Memory Model. It employs numerous techniques to provide lock-free reads while still guaranteeing safe publication of objects. This article represents my attempt to take the magic out of the ConcurrentHashMap implementation.

Latest Notes

An In-Memory CSS Compressor For django-pipeline

I recently discovered the convenience of the django-pipeline library when attempting to reduce the asset size of a Django project. Currently, this library only seems to support external CSS compressors, such as Yuglify and YUI. While I have no objection to these specific tools, I simply do not want to complicate the deployment strategy by depending on additional external applications.

Disable Artifact Archiving With Jenkins DSL

Out of the box, the Jenkins DSL project doesn't currently provide a way of disabling artifact archiving. For projects with large outputs built on slave nodes, this can cause dramatic slowdowns as gigabytes of data are sent back to the master.

Freeing MappedByteBuffer

While investigating a production bug that indicated that the operating system of a server running only a JVM continually ran out of memory under a specific set of circumstances, I discovered a very interesting idiosyncrasy of the JVM. Specifically, memory allocated with mmap through the MappedByteBuffer (the super class of DirectByteBuffer) does not get munmapped until the allocating MappedByteBuffer is garbage collected.

Dropwizard IT Port Randomisation

Dropwizard's testing package includes a @ClassRule, DropwizardAppRule, that may be used to create end-to-end integration tests. However, you may rapidly discover that parallel test execution is severely impaired, as each test attempts to use the same application and admin ports as another.

Retain Your CDI Qualifiers

The CDI specifications is very clear in its definition of qualifiers. Of particular importance is the @Retention information: with the default retention, CLASS, a container's behaviour is undefined.

Finally, Rollback Your Transaction

Lately, I've been working with code that exhibits a fairly poor practice: programmatic transactions (namely Spring) don't always get committed or rolled-back, even though the code appears correct.

Enum Hash Codes Are Non-Deterministic

An annoying discovery: Java Enum objects have non-deterministic hash codes. Specifically, a hash code is the Enum's identity (or memory address).

No ConcurrentHashSet? No Problem

The JDK provides several concurrent Set classes, each with their own application, but it does not provide a ConcurrentHashSet. Using the Collections utility class, however, such a structure may be created.