Concurrent Programming for you and me



Similar documents
Akka Streams. Dr. Roland Typesafe

Scala Actors Library. Robert Hilbrich

Above the Clouds: Introducing Akka

Massachusetts Institute of Technology 6.005: Elements of Software Construction Fall 2011 Quiz 2 November 21, 2011 SOLUTIONS.

Java SE 8 Programming

Java SE 7 Programming

SSC - Concurrency and Multi-threading Java multithreading programming - Synchronisation (I)

Architectural Patterns (3)

Real-world Java 4 beginners. Dima, Superfish github.com/dimafrid

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

Ambient-oriented Programming & AmbientTalk

Scheduling Algorithms in MapReduce Distributed Mind

A Tool for Evaluation and Optimization of Web Application Performance

Java SE 7 Programming

Java SE 7 Programming

A Comparison Of Shared Memory Parallel Programming Models. Jace A Mogill David Haglin

: provid.ir

MBrace: Cloud Computing with Monads

Apache Spark 11/10/15. Context. Reminder. Context. What is Spark? A GrowingStack

MAPREDUCE Programming Model

How To Write A Data Processing Pipeline In R

GTask Developing asynchronous applications for multi-core efficiency

F1: A Distributed SQL Database That Scales. Presentation by: Alex Degtiar (adegtiar@cmu.edu) /21/2013

Seeking Opportunities for Hardware Acceleration in Big Data Analytics

Distributed Computing and Big Data: Hadoop and MapReduce

CS11 Java. Fall Lecture 7

Parallel Computing in Python: multiprocessing. Konrad HINSEN Centre de Biophysique Moléculaire (Orléans) and Synchrotron Soleil (St Aubin)

Chapter 7. Using Hadoop Cluster and MapReduce

Generating Web Applications from Process Models


HBase A Comprehensive Introduction. James Chin, Zikai Wang Monday, March 14, 2011 CS 227 (Topics in Database Management) CIT 367

GPU Hardware Performance. Fall 2015

Bayesian networks - Time-series models - Apache Spark & Scala

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

CUT YOUR GRAILS APPLICATION TO PIECES

Real-time Streaming Analysis for Hadoop and Flume. Aaron Kimball odiago, inc. OSCON Data 2011

Questions? Assignment. Techniques for Gathering Requirements. Gathering and Analysing Requirements

Weaving Stored Procedures into Java at Zalando

What is cloud computing?

A distributed system is defined as

Big Data for the JVM developer. Costin Leau,

Spark in Action. Fast Big Data Analytics using Scala. Matei Zaharia. project.org. University of California, Berkeley UC BERKELEY

q for Gods Whitepaper Series (Edition 7) Common Design Principles for kdb+ Gateways

NoSQL web apps. w/ MongoDB, Node.js, AngularJS. Dr. Gerd Jungbluth, NoSQL UG Cologne,

Spring 2011 Prof. Hyesoon Kim

Real Time Programming: Concepts

Liferay Performance Tuning

Using UML Part Two Behavioral Modeling Diagrams

Operations and Supply Chain Management Prof. G. Srinivasan Department of Management Studies Indian Institute of Technology, Madras

Scala type classes and machine learning. David Andrzejewski Bay Area Scala Enthusiasts - 1/14/2013, 1/16/2013

MapReduce and Hadoop. Aaron Birkland Cornell Center for Advanced Computing. January 2012

Cloud Computing at Google. Architecture

Fast Analytics on Big Data with H20

Hadoop: A Framework for Data- Intensive Distributed Computing. CS561-Spring 2012 WPI, Mohamed Y. Eltabakh

South East of Process Main Building / 1F. North East of Process Main Building / 1F. At 14:05 April 16, Sample not collected

Vertica Live Aggregate Projections

Introduction to Hadoop HDFS and Ecosystems. Slides credits: Cloudera Academic Partners Program & Prof. De Liu, MSBA 6330 Harvesting Big Data

SOLVING QUADRATIC EQUATIONS - COMPARE THE FACTORING AC METHOD AND THE NEW TRANSFORMING METHOD (By Nghi H. Nguyen - Jan 18, 2015)

Scaling Up & Out with Actors: Introducing Akka

Intruduction to Groovy & Grails programming languages beyond Java

Getting Started with Hadoop. Raanan Dagan Paul Tibaldi

Programming Language Rankings. Lecture 15: Type Inference, polymorphism & Type Classes. Top Combined. Tiobe Index. CSC 131! Fall, 2014!

Apache Tomcat. Load-balancing and Clustering. Mark Thomas, 20 November Pivotal Software, Inc. All rights reserved.

JProfiler: Code Coverage Analysis Tool for OMP Project

Big Data looks Tiny from the Stratosphere

Spark ΕΡΓΑΣΤΗΡΙΟ 10. Prepared by George Nikolaides 4/19/2015 1

On Correlating Performance Metrics

Design REST Services with CXF JAX- RS implementation: best practices and lessons learned

CSE-E5430 Scalable Cloud Computing Lecture 11

Overview Motivating Examples Interleaving Model Semantics of Correctness Testing, Debugging, and Verification

Hadoop IST 734 SS CHUNG

Load Testing Ajax Apps using head-less browser tools. NoVaTAIG April 13, 2011 Gopal Addada and Frank Hurley Cigital Inc.

KWIC Implemented with Pipe Filter Architectural Style

USERV Auto Insurance Rule Model in Corticon

ActiveVOS Performance Tuning

Lecture 3 Hadoop Technical Introduction CSE 490H

Continuous Integration in the Cloud with Hudson

Akka Stream and HTTP Experimental Java Documentation

Notes on Factoring. MA 206 Kurt Bryan

Java course - IAG0040. Unit testing & Agile Software Development

Open Source SOA with Service Component Architecture and Apache Tuscany. Jean-Sebastien Delfino Mario Antollini Raymond Feng

MongoDB and Couchbase

Liferay Portal Performance. Benchmark Study of Liferay Portal Enterprise Edition

Android Application Development Course Program

Motivation: Smartphone Market

State of the SSL Onion. Susan Hinrichs ATS Summit Fall 2015

YARN, the Apache Hadoop Platform for Streaming, Realtime and Batch Processing

RVS-Seminar Implementation and Evaluation of WinJTAP Interface. Milan Nikolic Universität Bern

Big Data for Investment Research Management

Transcription:

Concurrent Programming for you and me Dierk König Canoo Engineering AG Basel, Schweiz JUG Berlin-Brandenburg 2012

Welcome! Dierk König Fellow @ Canoo Engineering AG, Basel (CH) Rich Internet Applications Products, Projects, Consulting www.canoo.com Open-source committer Groovy, Grails, GPars

aus Herb Sutter: "The free lunch is over"

Groovy & GPars mission 1 Built for Java developers 2 3 Make concurrency safer Make concurrency simpler 4

The Java state of affairs Starting new threads is easy. Some real goodies in java.util.concurrent.* & Java 7 Manual thread-coordination is difficult. Access to shared state is error-prone. Scheduling issues for many threads with bad concurrency characteristics. Good use of pooling is not obvious. Concepts are rather low level. 5

It s all about coordination Fork/Join Map/Reduce Actor Agent Dataflow Working on collections with fixed coordination Explicit coordination Delegated coordination Implicit coordination 2.0

It s all about coordination Fork/Join Map/Reduce Actor Agent Dataflow Working on collections with fixed coordination Explicit coordination Delegated coordination Implicit coordination more Asynchronizer STM 2.0

Fork/Join on collections import static groovyx.gpars.gparspool.withpool def numbers = [1, 2, 3, 4, 5, 6] def squares = [1, 4, 9, 16, 25, 36] withpool { assert squares == numbers.collectparallel { it * it } } // in reality, find better chunks of work! 7

Fork/Join on collections import static groovyx.gpars.gparspool.withpool def numbers = [1, 2, 3, 4, 5, 6] def squares = [1, 4, 9, 16, 25, 36] withpool { assert squares == numbers.collectparallel { it * it } } // in reality, find better chunks of work! Variation makeconcurrent() 7

More such methods any {... } collect {... } count(filter) each {... } eachwithindex{... } every {... } find {... } findall {... } findany {... } fold {... } fold(seed) {... } grep(filter) groupby {... } max {... } max() min {... } min() split {... } sum() 8

Map/Filter/Reduce on collections import static groovyx.gpars.gparspool.withpool withpool { assert 55 == [0, 1, 2, 3, 4].parallel.map { it + 1 }.map { it ** 2 }.reduce { a, b -> a + b } } 9

Fork/Join vs Map/Filter/Reduce! 10

Fork/Join vs Map/Filter/Reduce fixed coordination! 10

Explicit coordination with Actors import static groovyx.gpars.actor.actors.* def printer = reactor { println it } def decryptor = reactor { reply it.reverse() } actor { decryptor.send 'lellarap si yvoorg' react { printer.send 'Decrypted message: ' + it decryptor.stop() printer.stop() } }.join() 11

Actors Process one message at a time. Dispatch on the message type, which fits nicely with dynamic languages. Are often used in composition, which can lead to further problems down the road. Personal note: Actors are overrated 12

Delegate to an Agent import groovyx.gpars.agent.agent def safe = new Agent<List>( ['GPars'] ) safe.send { it.add 'is safe!' } safe.send { updatevalue it * 2 } println safe.val 13

Agents Analogous to Clojure agents (atoms, refs,...) Implementations differ much in efficiency. 14

DataFlow for implicit coordination import groovyx.gpars.dataflow.dataflows import static groovyx.gpars.dataflow.dataflow.task final flow = new DataFlows() task { flow.result = flow.x + flow.y }! task { flow.x = 10 }!!! task { flow.y = 5 }!!! assert 15 == flow.result! 15

DataFlow Flavors: variables, streams, operators, tasks, flows Write-Once, Read-Many (non-blocking) Feel free to use millions of them Fast, efficient, safe, and testable! Model the flow of data, not the control flow! 16

KanbanFlow in code import static ProcessingNode.node import groovyx.gpars.kanban.kanbanflow def producer = node { below -> below << 1 } def consumer = node { above -> println above.take() } new KanbanFlow().with { link producer to consumer start() links*.addtray() // run for a while stop() } 17

Efficient Producer-Consumer KanbanFlow pattern by /me http://people.canoo.com/mittie/kanbanflow.html Simple idea, amazing results Resource efficient, composable, testable Non-blocking writes, Deadlock-free by design 18

Kanbanflow scenarios Producer Consumer 19

Kanbanflow chaining Producer Filter Consumer 20

Kanbanflow cycles Generator Filter Collector 21

Kanbanflow cycles Generator Filter Collector 21

Kanbanflow cycles Generator Filter Collector 21

Kanbanflow load balancer Slave Master Slave Slave 22

Kanbanflow broadcast Consumer Producer Consumer Consumer 23

Kanbanflow combinator Producer Producer Combinator Producer 24

Takeaways 1 Experiment with GPars! 2 Great for learning concepts! 3 Get involved! 25

26

26

Further reading Groovy in Action, 2nd Edition chapter 17 gpars.codehaus.org

Discussion credits: Paul King

Discussion dierk.koenig@canoo.com @mittie credits: Paul King