Tuesday, April 17, 2012

The ekg package can now export string labels

I'm happy to announce a new minor release of the ekg package. The ekg package lets you monitor running executables using your web browser, or any monitoring tool that can speak HTTP. New in this release is support for exporting labels.

A label is an arbitrary text string, set dynamically by the running executable. Labels are more flexible than counters and gauges (which can only represent numerical values.) Typical uses of labels include exporting the command line arguments the executable was started with, the host it's running on, etc. Since labels are arbitrary strings you can use labels to export any type of internal state that can be represented as a string. Here's a simple example:

{-# LANGUAGE OverloadedStrings #-}
module Main where

import Control.Concurrent
import Control.Exception
import qualified Data.Text as T
import System.Environment
import qualified System.Remote.Label as Label
import System.Remote.Monitoring

mean :: Fractional a => [a] -> a
mean xs = sum xs / fromIntegral (length xs)

main :: IO ()
main = do
    handle <- forkServer "localhost" 8000
    label <- getLabel "args" handle
    args <- getArgs
    Label.set label $ T.intercalate " " $ map T.pack args
    -- Busy work:
    let loop n = do
            evaluate $ mean [1..n]
            threadDelay 2000
            loop n
    loop 1000000

This functionality was contributed by Iustin Pop.

cabal bench

With the release of cabal-install 0.14, you can use Cabal to build and run your benchmarks. No more Makefiles that try to replicate things Cabal already does. Just like cabal test allows us to automatically find and run tests using e.g. a buildbot, this feature should let us track performance of libraries over time and catch performance regressions earlier. There's some future work needed to make this convenient, but it's already possible today if you're willing to parse the output of your favorite benchmarking library (e.g. Criterion.)

Writing benchmark sections in your Cabal file is very similar to writing test suite sections. Here's an example taken from the bytestring package:

benchmark bench-builder-all
  type:             exitcode-stdio-1.0
  hs-source-dirs:   . bench
  main-is:          BenchAll.hs
  build-depends:    base, deepseq, ghc-prim,
                    criterion
  c-sources:        cbits/fpstring.c
                    cbits/itoa.c
  include-dirs:     include
  ghc-options:      -O2
                    -fmax-simplifier-iterations=10
                    -fdicts-cheap
                    -fspec-constr-count=6

To run just do:

cabal configure --enable-benchmarks && cabal build && cabal bench

Monday, April 2, 2012

Time to apply for Google Summer of Code

The student application deadline for this year's Google Summer of Code is this Friday, April 6th, at 19:00 UTC. Have a look at our ideas page and write an application for e.g. your top three picks. Applying for more than one project increases your chance to get accepted in the case where several students apply for the same project.