Experiments in OTP-Compliant Dataflow Programming

Similar documents
Cliff Moon. Bottleneck Whack-A-Mole. Thursday, March 21, 13

FRANCESCO CESARINI. presents ERLANG/OTP. Francesco Cesarini Erlang

Erlang: distributed programming

BUILDING A SCALABLE MOBILE GAME BACKEND IN ELIXIR. Petri Kero CTO / Ministry of Games

Erlang. Functional Concurrent Distributed Soft real-time OTP (fault-tolerance, hot code update ) Open. Check the source code of generic behaviours

Computer Systems II. First Two Major Computer System Evolution Steps

Introduction to Processes in Computer Systems SEEM

Polling Sucks. So what should we do instead?

Apache Flink. Alessandro Margara

Processes and More. CSCI 315 Operating Systems Design Department of Computer Science

Distributed Shared Memory

An Introduction to Erlang

Message-passing concurrency in Erlang

Erlang. Functional Concurrent Distributed Soft real-time OTP (fault-tolerance, hot code update ) Open. Check the source code of generic behaviours

Processes. Dr. Yingwu Zhu

Problem Set: Processes

SMD149 - Operating Systems

Process Concepts. CSC400 - Operating Systems. 3. Process Concepts. J. Sumey

CSCE 313: Intro to Computer Systems

CSCE 313 Introduction to Computer Systems. Instructor: Dezhen Song

CHAPTER 3 - PROCESS CONCEPT

Questions answered in this lecture: CS 537 Lecture 19 Threads and Cooperation. What s in a process? Organizing a Process

Robust Erlang (PFP Lecture 11) John Hughes

Architectural Styles. Software Architecture Lecture 5. Copyright Richard N. Taylor, Nenad Medvidovic, and Eric M. Dashofy. All rights reserved.

3.1 Introduction. Computers perform operations concurrently

Chapter 3: Processes. Operating System Concepts 9 th Edition

Announcements Processes: Part II. Operating Systems. Autumn CS4023

Part V. Process Management. Sadeghi, Cubaleska RUB Course Operating System Security Memory Management and Protection

20: Networking (2) TCP Socket Buffers. Mark Handley. TCP Acks. TCP Data. Application. Application. Kernel. Kernel. Socket buffer.

MultiJav: A Distributed Shared Memory System Based on Multiple Java Virtual Machines. MultiJav: Introduction

VM Migration, Containers (Lecture 12, cs262a)

ECE 650 Systems Programming & Engineering. Spring 2018

Distributed Deadlock

Scalable ejabberd. Konstantin Tcepliaev. Moscow Erlang Factory Lite June 2012

Chapter 3: Processes. Operating System Concepts Essentials 8 th Edition

Erlang: An Overview. Part 2 Concurrency and Distribution. Thanks to Richard Carlsson for most of the slides in this part

Erlang-DTrace. Garry Bulmer. Team DTrace: Tim Becker

Introduction to reactive programming. Jonas Chapuis, Ph.D.

Roadmap. Tevfik Ko!ar. CSC Operating Systems Fall Lecture - III Processes. Louisiana State University. Processes. September 1 st, 2009

Threads. Computer Systems. 5/12/2009 cse threads Perkins, DW Johnson and University of Washington 1

Chapter 4: Processes

Chapter 3: Processes. Operating System Concepts 8 th Edition,

Diagram of Process State Process Control Block (PCB)

Lecture 2 Process Management

Wednesday, September 14, Chapter 3: Processes

Architecture or Parallel Computers CSC / ECE 506

Chapter 3: Processes

Chapter 3: Processes. Operating System Concepts 8 th Edition,

Real-time & Embedded Systems Workshop July 2007 Building Successful Real-time Distributed Systems in Java

An Introduction to Erlang

CS 471 Operating Systems. Yue Cheng. George Mason University Fall 2017

A NEW BEHAVIOUR PROPOSED FOR R15A JAY NELSON

Exercise (could be a quiz) Solution. Concurrent Programming. Roadmap. Tevfik Koşar. CSE 421/521 - Operating Systems Fall Lecture - IV Threads

Chapter 3 Processes. Process Concept. Process Concept. Process Concept (Cont.) Process Concept (Cont.) Process Concept (Cont.)

Chapter 3: Processes. Operating System Concepts 8 th Edition,

Kotlin/Native concurrency model. nikolay

CS 43: Computer Networks. HTTP September 10, 2018

Java Concurrency in practice Chapter 9 GUI Applications

What s in a process?

Vulnerability Scan Service. User Guide. Issue 20 Date HUAWEI TECHNOLOGIES CO., LTD.

Applications, services. Middleware. OS2 Processes, threads, Processes, threads, communication,... communication,... Platform

CPSC 341 OS & Networks. Processes. Dr. Yingwu Zhu

Executive Summary. It is important for a Java Programmer to understand the power and limitations of concurrent programming in Java using threads.

Asynchronous Events on Linux

Programmazione Avanzata e Paradigmi Ingegneria e Scienze Informatiche - UNIBO a.a 2013/2014 Lecturer: Alessandro Ricci

Problem Set: Processes

Process. Program Vs. process. During execution, the process may be in one of the following states

Chapter 3: Processes. Operating System Concepts 8th Edition,

! The Process Control Block (PCB) " is included in the context,

Chapter 3: Process Concept

Erlang and Concurrency. André Pang Rising Sun Research

Chapter 3: Process Concept

Chapter 3: Process Concept

Processes. CS3026 Operating Systems Lecture 05

Introduction to Erlang. Franck Petit / Sebastien Tixeuil

OpenEdge 12.0 Database Performance and Server Side Joins. Richard Banville Fellow, OpenEdge Development October 12, 2018

02 - Distributed Systems

Chapter 3: Process Concept

Process Description and Control. Chapter 3

CSC Operating Systems Fall Lecture - II OS Structures. Tevfik Ko!ar. Louisiana State University. August 27 th, 2009.

Announcements. Computer System Organization. Roadmap. Major OS Components. Processes. Tevfik Ko!ar. CSC Operating Systems Fall 2009

Lecture 9: MIMD Architectures

Chapter 3: Processes. Chapter 3: Processes. Process in Memory. Process Concept. Process State. Diagram of Process State

Inf2C - Computer Systems Lecture 16 Exceptions and Processor Management

Network Working Group. Category: Standards Track February 2009

Chapter 3: Processes. Operating System Concepts 9 th Edition

Architectural Design. CSCE Lecture 12-09/27/2016

Multicast Communications. Slide Set were original prepared by Dr. Tatsuya Susa

Chapter 3: Processes. Operating System Concepts 8th Edition, modified by Stewart Weiss

Process! Process Creation / Termination! Process Transitions in" the Two-State Process Model! A Two-State Process Model!

CHAPTER 2: PROCESS MANAGEMENT

Parallel Programming on Larrabee. Tim Foley Intel Corp

ERLANG EVOLVES FOR MULTI-CORE AND CLOUD ENVIRONMENTS

Chapter 1: Distributed Systems: What is a distributed system? Fall 2013

Rudy: a small web server. Johan Montelius. October 2, 2016

Remote Invocation. Today. Next time. l Overlay networks and P2P. l Request-reply, RPC, RMI

Ping Driver PTC Inc. All Rights Reserved.

Thinking in a Highly Concurrent, Mostly-functional Language

The Big Picture So Far. Chapter 4: Processes

Module 4: Processes. Process Concept Process Scheduling Operation on Processes Cooperating Processes Interprocess Communication

Transcription:

Experiments in OTP-Compliant Dataflow Programming Introducing Erlang Services Platform (Erlang/SP) San Francisco Erlang Factory, March 21, 2013 Jay Nelson Twitter: @duomark Email: Jay@duomark.com

Manycore Concurrency Erlang/OTP encourages server-style programming One process with a potentially large internal state Serialized mutations to the internal state No easy way to automatically break up a gen_* process Modern CPUs will soon have 100, 1K or even 10K cores How can Erlang programmers adapt to this future?

Keeping Cores Busy OS-Level virtualization (multiply your problem) One CPU appears to be 100s of machines Many tenants and applications run on the same hardware Single application concurrency (divide and conquer) Requires many fine-grained tasks Implies that existing state must be distributed to more processes

Erlang/SP OTP-compliant library Open source at https://github.com/duomark/erlangsp Can be included directly with rebar.config Undergoing active development and evolution Encourages the use of services over servers Service: set of co-ops implementing an independent subsystem Co-op: tightly bound graph of cooperating processes

Example Services for Texting Presence - users, bots or services that are online Connection listener - accepts user client connections Message routing - delivers messages from one user to others Attachment management - stores and ids attachments (image, sound) Push notifications - message count badges sent to offline users User search - discover users of the texting application

Goals of Erlang/SP Simplify and encourage the creation of massive concurrency Automate the generation of process networks Map mutable state to a structural representation of all states Use data flow to stimulate the network maps Allow incremental integration with existing OTP code Provide tools for understanding high concurrency performance

Process Networks Collection of processes wired together along messaging lines Build a Directed Acyclic Graph (DAG) template Create a co-op with a task function process per graph node Each process knows only its downstream receivers Inject data to propagate through the computation network Glue networks together with a mixture of OTP and SP constructs

Networked State Representation Each path through a network is unique Each path equals state Arrival at a specific node implies the path taken Process at that node has implicit state knowledge The process network embodies all states reachable Tradeoff: mutable state vs. processes + messaging Adding latency, but increasing concurrency

Networked State (cont.) Replacing a counter with a pipeline of processes Msg Try 1 Try 2 Try 3 Fail Notify subscriber

Networked State (cont.) Programming with Erlang/SP The art of disassembling and distributing state Selecting network patterns that describe the problem space Functional decomposition Choosing the smallest meaningful function granularity Mapping functions to separate processes

OTP-Compliance Processes which: respond to system messages (dbg, trace, etc) can be supervised (deal with EXIT messages properly) reply to reltool get_modules request Compatible with all OTP tools Can integrate freely with OTP constructs (e.g., gen_server, supervisor) Support software upgrade in the context of a larger OTP system

Example message loop code (erlangsp: coop_head_ctl_rcv.erl) msg_loop({} = State, Root_Pid, Timeout, Debug_Opts) -> receive %% System messages for compatibility with OTP... {'EXIT', _Parent, Reason} -> exit(reason); {system, From, System_Msg} -> Sys_Args = {State, Root_Pid, Timeout, Debug_Opts}, handle_sys(sys_args, From, System_Msg); {get_modules, From} -> From! {modules, [?MODULE]},?MSG_LOOP_RECURSE;?CTL_MSG({init_state, #coop_head_state{} = New_State}) ->?MSG_LOOP_RECURSE(New_State) end;

OTP-Compliance (cont.) More details in my Vancouver 2012 Erlang Factory Lite talk Managing Processes without OTP (and how to make them OTPcompliant) http://www.erlang-factory.com/upload/presentations/674/ OTPProcs.pdf

Implementation Details 1. Esp_service behaviour 2. Esp_tcp_service behaviour 3. Esp_epmd

Esp_service Behaviour Erlang/SP library provided behaviour Client module must implement new(args, Receiver) -> esp_service() {error, _}. start(service, Proplist) -> esp_service() {error, _}. stop(service) -> esp_service(). Services don t run on creation, until explicitly started A collection of services plus admin/control logic make a system

Esp_service Behaviour (cont.) Built-in functions make_service(coop()) -> esp_service(). link_service(esp_service()) -> ok. status(esp_service()) -> svc_state(). act_on(esp_service(), Data) -> ok {error, not_started} suspend, suspend_for / resume, resume_after set_overload / is_overloaded

Esp_tcp_service Behaviour Generic service for accepting TCP connections (like ranch or swarm) Uses prim_inet:async_accept internally Implements esp_service interface using a fanout co-op graph Client module handles incoming data Client module can be changed after acceptor is launched Listen socket, plus acceptors are all linked Client module can remove links on connect or data recv

Diagram of Esp_tcp_service Start create socket Listen broadcast Accept Accept Accept Client Client_Module:recv(..., Data) Client

Esp_tcp_service Behaviour (cont.) Fanout broadcast from socket listen to N acceptor children No downstream receivers from fanout Connection is kept in acceptor process, no tcp socket transfer Client module is free to generate side effects on data recv On completion, acceptor process is removed from co-op Replacement is slab allocated for higher volume performance

Epmd daemon Epmd maintains connection registry List of node name, port for shared cookie Erlang nodes Part of base distribution, written in C TCP to local node when erlang VM starts Epmd accepts queries for active nodes

Diagram of Epmd connect erl registry epmd erl query erl clients

Typical vs. Erlang/SP version Typical TCP connection listener pool Ets table of connections Central server for queries Erlang/SP style Esp_tcp service (connection listener fanout) Query service (fanout of connected nodes)

Esp_epmd Service Connection fanout is an esp_tcp_service Acceptor task for erl connection is to migrate to query fanout Acceptor task for other requests is reply and die Queries are routed to query service fanout Broadcast mode sends query to all live connections Each replies if query matches, ignores if not

Esp_epmd Query Reply Asynchronous distribution requires collection of results Newly spawned collector task listens for responses Replies must be sent to requestor within timeout Late to arrive messages find no process and are dropped After response, collector pid expires

Query Collection 3) result 1) query query service collector 2) broadcast erl1 erl2 erl3 4) late reply dropped

Erlang/SP Contribution Trade internal state (ets table) for process graph Database of connections is a fanout graph of processes Query occurs in parallel naturally Entirely eliminates need for mutable state update on connect Erlang/SP provides common library patterns Reduction in code to implement epmd logic Full OTP tool set can be used on live epmd connection processes

Conclusion Erlang/SP enables higher-level concurrency patterns Eschews state-based, single-server model Supports graph-oriented concurrent algorithm structures Allows integration with existing OTP structures Supports migration of systems to manycore architectures v0.1.0 with esp_service behaviours will be announced soon