Molecule: Using monadic threads and streams to compose scalable process networks (with graceful termination)

21 October 2012

New Image

Molecule is a library offering a domain specific language embedded in Scala for easing the elaboration of scalable and modular interactive applications. Interactive applications are modeled as parallel process networks that exchange information over mobile communication channels as described in -calculus. In this paper, we present a novel concurrent programming environment that distinguishes itself by its fusion of object oriented and functional programming techniques. The approach allies modularity, efficiency and robustness. Using a monad, we encapsulate user-level threads and structure continuations, without compiler support. Using a thin recursive channel interface, we isolate system-level side effects from parallelizable algebraic stream transformations on first-class communication channels. Channel termination is integrated with the exception and automatic resource management extensions we brought to the monad to support the seamless and graceful termination of complete process networks. We illustrate the benefits on three simple examples. One of them, a terse parallel prime sieve algorithm, shows 4000 times performance improvement on a 24x core machine at no cost on clarity. Categories and Subject Descriptors D.x.x [Programming Techniques]: Domain Specific Embedded Languages; D.1.3 [Programming Techniques]: Concurrent Programming ; D.2.11 [Software]: Software Architectures--patterns General Terms decentralized computing, component model, architectural guidelines, end-to-end telco systems, concurrency, heterogeneity.