Sunday, September 2, 2012

Introducing Sentries

I recently needed a friendly to use circuit breaker in a Scala program. What I found was okay, but not nearly good enough for high volume, highly concurrent applications. So I set out to make it better.

After some iterations of changing I realized that the circuit breaker could be combined with other stuff like rate limiting, monitoring and such. Now, three months later, Sentries is ready for the world.

Here is an example usage: Please visit Sentries on Githib and let me know what you think.

Update 2012-09-04: Version 0.2 will be available in Maven central around 2012-09-04 18:00 GMT.

Update 2012-10-08: Version 0.3 has just landed in Maven central. Its only feature is the new 'clean()' method on the sentry registry which is useful during testing.

Update 2013-02-06: Version 0.5 is out. This is the first to support Scala 2.10. Breaking change is that all durations are now of type akka.util.Duration or scala.concurrent.duration.Duration (depending on the Scala version) instead of Long.

Friday, April 27, 2012

Getting size of a file in shell script

This is really too silly. There seems to be no consistent way to get the size of a file (in bytes) on multiple platforms. Here is a solution that works in bash on Linux (tested under Debian and Ubuntu) and BSD (tested under OSX):

# Echo's size of a file (first argument). # Tested under Linux (Debian) and BSD (OSX). function filesize() { echo $(stat --format=%s "$1" 2>/dev/null || stat -f '%z' "$1" 2>/dev/null) } # Example usage: echo $(filesize readme.txt)

Monday, January 16, 2012

X forwarding as root

Often is useful to run jconsole on a remote (production) machine. One basically has 2 options to do so. First, you can pierce your firewall and let your application listen to the appropriate JMX and RMI ports. This however always tricky (in particular the RMI). In addition, creating the connection string that jconsole accepts is not nice at all.

The other option, is to do X forwarding. I'll describe here how to do this on MacOS X, with jconsole on any Unix server with, ssh-server, no root password and sudo installed.

  1. Start X11 (you'll need to install it from the installation CDs).
  2. Start iterm2.
  3. Login to the target system with ssh -X remote_user@system
  4. Switch to root with sudo -s.
  5. Get X authorities with xauth merge ~remote_user/.Xauthority
  6. Start jconsole