Scala Actors Library. Robert Hilbrich



Similar documents
ACTOR-BASED MODEL FOR CONCURRENT PROGRAMMING. Sander Sõnajalg

Monitoring Hadoop with Akka. Clint Combs Senior Software Engineer at Collective

A distributed system is defined as

Multi-core Programming System Overview

Ruby's Newest Actor: Abrid Programming Concurrency Models

Software and the Concurrency Revolution

Real Time Programming: Concepts

Scaling Up & Out with Actors: Introducing Akka

Ambient-oriented Programming & AmbientTalk

In Memory Accelerator for MongoDB

Improving the performance of data servers on multicore architectures. Fabien Gaud

Chapter 6, The Operating System Machine Level

ODROID Multithreading in Android

HelenOS IPC and Behavior Protocols

Tomcat Tuning. Mark Thomas April 2009

Clojure on Android. Challenges and Solutions. Aalto University School of Science Master s Programme in Mobile Computing Services and Security

Building Scalable Applications Using Microsoft Technologies

Kernel Types System Calls. Operating Systems. Autumn 2013 CS4023

Reactive Slick for Database Programming. Stefan Zeiger

Performance Improvement In Java Application

ADOBE AIR. Working with Data in AIR. David Tucker

Ubiquitous access Inherently distributed Many, diverse clients (single purpose rich) Unlimited computation and data on demand

ebay : How is it a hit

Introduction. What is an Operating System?

Achieving Nanosecond Latency Between Applications with IPC Shared Memory Messaging

Operatin g Systems: Internals and Design Principle s. Chapter 10 Multiprocessor and Real-Time Scheduling Seventh Edition By William Stallings

Titolo del paragrafo. Titolo del documento - Sottotitolo documento The Benefits of Pushing Real-Time Market Data via a Web Infrastructure

Chapter 3: Operating-System Structures. Common System Components

Middleware. Peter Marwedel TU Dortmund, Informatik 12 Germany. technische universität dortmund. fakultät für informatik informatik 12

Practical Performance Understanding the Performance of Your Application

Unit 8: Immutability & Actors

Oracle JRockit Mission Control Overview

Programming Language Pragmatics

EVALUATION. WA1844 WebSphere Process Server 7.0 Programming Using WebSphere Integration COPY. Developer

Event-driven plugins with Grails 3. Göran Ehrsson, Technipelago AB

Scalable and Reactive Programming for Semantic Web Developers

Driving force. What future software needs. Potential research topics

Erlang, Open Networking, and the Future of Computing. Stu Bailey, Founder/CTO

REACTIVE systems [1] currently lie on the final frontier

Mission-Critical Java. An Oracle White Paper Updated October 2008

Page 1 of 5. IS 335: Information Technology in Business Lecture Outline Operating Systems

CS555: Distributed Systems [Fall 2015] Dept. Of Computer Science, Colorado State University

CSCI E 98: Managed Environments for the Execution of Programs

Using Protothreads for Sensor Node Programming

The Hotspot Java Virtual Machine: Memory and Architecture

Intel DPDK Boosts Server Appliance Performance White Paper

TYPESAFE TOGETHER - SUBSCRIBER TRAINING. Training Classes

Symmetric Multiprocessing

A Comparative Study on Vega-HTTP & Popular Open-source Web-servers

Experimental Evaluation of Distributed Middleware with a Virtualized Java Environment

PROFESSIONAL. Node.js BUILDING JAVASCRIPT-BASED SCALABLE SOFTWARE. Pedro Teixeira WILEY. John Wiley & Sons, Inc.

Multithreading and Java Native Interface (JNI)!

Applications to Computational Financial and GPU Computing. May 16th. Dr. Daniel Egloff

Mutual Exclusion using Monitors

Virtual Machine Learning: Thinking Like a Computer Architect

Mobile RFID solutions

An Implementation Of Multiprocessor Linux

ANDROID PROGRAMMING - INTRODUCTION. Roberto Beraldi

Software design (Cont.)

System Software and TinyAUTOSAR

Android Application Development Course Program

Zing Vision. Answering your toughest production Java performance questions

Comparison of Concurrency Frameworks for the Java Virtual Machine

The Java Virtual Machine and Mobile Devices. John Buford, Ph.D. Oct 2003 Presented to Gordon College CS 311

Using In-Memory Computing to Simplify Big Data Analytics

Vodafone Plus. User Guide for Windows Mobile

Code and Process Migration! Motivation!

Java Performance. Adrian Dozsa TM-JUG

General Introduction

Insight into Performance Testing J2EE Applications Sep 2008

ArcGIS for Server: Administrative Scripting and Automation

Software Life-Cycle Management

PTC System Monitor Solution Training

A Thread Monitoring System for Multithreaded Java Programs

Why Threads Are A Bad Idea (for most purposes)

SEER PROBABILISTIC SCHEDULING FOR COMMODITY HARDWARE TRANSACTIONAL MEMORY. 27 th Symposium on Parallel Architectures and Algorithms

MA-WA1920: Enterprise iphone and ipad Programming

How to analyse your system to optimise performance and throughput in IIBv9

Chapter 6 Concurrent Programming

E) Modeling Insights: Patterns and Anti-patterns

1 An application in BPC: a Web-Server

GTask Developing asynchronous applications for multi-core efficiency

Resource Utilization of Middleware Components in Embedded Systems

Kernel comparison of OpenSolaris, Windows Vista and. Linux 2.6

Validating Java for Safety-Critical Applications

Introducing Tetra: An Educational Parallel Programming System

How To Understand The Concept Of A Distributed System

HeapStats: Your Dependable Helper for Java Applications, from Development to Operation

Informatica Ultra Messaging SMX Shared-Memory Transport

PART IV Performance oriented design, Performance testing, Performance tuning & Performance solutions. Outline. Performance oriented design

Introducing Apache Pivot. Greg Brown, Todd Volkert 6/10/2010

Concurrent Programming for you and me

ANDROID BASED MOBILE APPLICATION DEVELOPMENT and its SECURITY

From L3 to sel4: What Have We Learnt in 20 Years of L4 Microkernels?

An Oracle White Paper July Load Balancing in Oracle Tuxedo ATMI Applications

Architecture Design & Sequence Diagram. Week 7

Using UML Part Two Behavioral Modeling Diagrams

GUI and Web Programming

Chapter 12 Programming Concepts and Languages

Stream Processing on GPUs Using Distributed Multimedia Middleware

Transcription:

Scala Actors Library Robert Hilbrich

Foreword and Disclaimer I am not going to teach you Scala. However, I want to: Introduce a library Explain what I use it for My Goal is to: Give you a basic idea about Scala Actors Tell you about ist underlying thread magic Seite 2

Agenda 1. Introduction 2. Scala Actors Library 3. Good Actors Style 4. Actors and Threads 5. Actors in My Life References Seite 3

1 INTRODUCTION Why should you care? Seite 4

Introduction About me: SPES Project Multicore / Manycore Processors Multicore Programming Today: Manually deal with Threads Often Shared Memory approaches Synchronization is hard, slow and error prone Thread -level = = Assembler -level (?) Future Challenges: Manycore Rise in Complexity Want: Less sharing, less synchronization Want: Message Passing instead of Shared Memory Want: Abstraction of Threads Tilera: 100 Cores (2010) Seite 5

2 SCALA ACTORS LIBRARY An introduction and brief overview Seite 6

Actors and Concurrency Classical Java Thread Programming Shared data and locks Scala Actors Library Simplify JVM thread programming Uses flexibility of Scala to create an abstraction layer that looks native Share-nothing and Message Passing approach (no locks!) Add some runtime Thread-Magic A1 Sync. Message A2 Async. Message Actor 1 Actor 2 Seite 7

A simple actor import scala.actors._ object actor1 extends Actor { def act() { println( I am acting ) Actor1 scala> actor1.start() I am acting scala> Seite 8

Message Passing: an echo actor import scala.actors._ object echoactor extends Actor { def act() { receive { case msg => println(msg) scala> echoactor.start() scala> echoactor! "Hallo FIRST" Hallo FIRST scala> echoactor Seite 9

Details about Message Passing Sending an asynchronous message is done via "!" actor! msg Sending a synchronous message is done via "!?" actor!? msg Retrieving a single message from the mailbox (blocks!) receive { Filter messages (returns the first message that matches) receive { case (msg: Type) => Reply to a synchronous message with reply msg msg msg msg msg msg actor receive { case (req) => reply(rep) Seite 10

Message Passing: async with case types example object intactor extends Actor { def act() { receive { case x:int => println(x) intactor scala> intactor.start() scala> intactor! "hello" scala> intactor! Math.Pi scala> intactor! 12 12 scala> Seite 11

Message Passing: sync example object intactor extends Actor { def act() { receive { case x:int => reply(x*x) intactor scala> intactor.start() scala> intactor!? 12 144 scala> Blocks! Seite 12

Background: Actors model - "Actors" is a generic computational model for concurrent and distributed computations - Has (first?) been implemented in Erlang "processes" - Erlang was developed at Ericson - Often used at Telco providers, especially for reliable (!) line switching - Its goodness has been proven in many Real- Time Control Systems - Until now: no similar abstraction to Threads has been available for popular virtual machines Seite 13

3 GOOD ACTORS STYLE Some ideas about good programming practice with actors Seite 14

Style Tips Actors should not block because it may block the processing of another message instead of Thread.sleep() create a seperate sleepactor Communicate only via immutable message going back to shared memory and locks requires thinking! message objects may be shared between different actors thread safe implementation required Make messages self-contained "Fire-and-Forget" demands for redundant information in messages Seite 15

4 ACTORS AND THREADS An actor is not just a thread! Seite 16

Mapping Actors to Threads Until now: Actors only as concurrency abstraction to Java Threads N receiving Actors N Java Threads Heavy weight exhaustion of virtual address space Context switch is expensive (spawn 500'000'000 Actors for a computation?!) Event-driven programming models circumvent this overhead But: "Inversion of control" register a handler for an event Fragmentation of logic Control flow is implicitly expressed by modifying shared state Design goal for Actors: make them thread-less Seite 17

Actors and Threads Actors are implemented as lightweight event objects Scheduled and executed on an underlying worker thread pool Worker Thread Pool gets automatically resized A1 A2 A3 A4 A5 A6 Actors Scheduling T1 T2 T3 T4 Threads Worker Thread Pool Seite 18

Actors and Suspension Actors can thus be used thread-based and event-based! Two Actor suspension mechanisms exist: Via receive thread-based Via react execution is "piggy-backed" onto the senders thread object echoactor extends Actor { def act() { react { case msg => println(msg) Why? With react all actors could be implemented with a single worker thread Control flow is explicitely expressed Reduced overhead for context switches Seite 19

More on React A wait on react is represented by a continuation closure (= a closure capturing the rest of the actor's computation) Closure is executed by the senders thread once a matching message arrived When closure terminates: control is returned to the sender When closure blocks again (another react): control is returned to the sender ( special exception) unwinding of receivers call stack Seite 20

React Example I object echoactor extends Actor { def act() { react { case msg => println(msg) act() Seite 21

React Example II object echoactor extends Actor { def act() { loop { react { case msg => println(msg) Seite 22

5 ACTORS IN MY LIFE Why did I stumble upon actors? Seite 23

Trading and financial speculation Seite 24

Implementing a Strategy Framework Ultimate goal: get rich! (at least die trying!) Immediate goal: a framework to study different investment strategies Underlying model: data pipeline Each actor receives stock data and decisions from the previous actor Some actors may have no memory, others may memorize decisions of other actors Data Reader Strategy 2 Strategy 4 DecisionMaker Real Data Strategy 1 Strategy 3 Seite 25

REFERENCES Where to look for more? Seite 26

References "Event-Based Programming without Inversion of Control", P. Haller and M. Odersky, in Proceedings JMLC 2006. "Actors that Unify Threads and Events", P. Haller and M. Odersky, in Proceedings COORDINATION 2007. Overview: http://java.dzone.com/articles/scala-threadless-concurrent Seite 27