Event Handling Patterns Asynchronous Completion Token

Slides:



Advertisements
Similar presentations
Executional Architecture
Advertisements

E81 CSE 532S: Advanced Multi-Paradigm Software Development Chris Gill Department of Computer Science and Engineering Washington University in St. Louis.
E81 CSE 532S: Advanced Multi-Paradigm Software Development Chris Gill Department of Computer Science and Engineering Washington University in St. Louis.
Extensibility, Safety and Performance in the SPIN Operating System Department of Computer Science and Engineering, University of Washington Brian N. Bershad,
Precept 3 COS 461. Concurrency is Useful Multi Processor/Core Multiple Inputs Don’t wait on slow devices.
Software Engineering and Middleware: a Roadmap by Wolfgang Emmerich Ebru Dincel Sahitya Gupta.
Active Messages: a Mechanism for Integrated Communication and Computation von Eicken et. al. Brian Kazian CS258 Spring 2008.
A. Frank - P. Weisberg Operating Systems Introduction to Tasks/Threads.
Software Patterns - F04 Asynchronous Completion Token 1.
E81 CSE 532S: Advanced Multi-Paradigm Software Development Chris Gill Department of Computer Science Washington University, St. Louis
Pattern Oriented Software Architecture for Networked Objects Based on the book By Douglas Schmidt Michael Stal Hans Roehnert Frank Buschmann.
DCE (distributed computing environment) DCE (distributed computing environment)
Operating Systems Lecture 2 Processes and Threads Adapted from Operating Systems Lecture Notes, Copyright 1997 Martin C. Rinard. Zhiqing Liu School of.
E81 CSE 532S: Advanced Multi-Paradigm Software Development Venkita Subramonian, Christopher Gill, Guandong Wang, Zhenning Hu, Zhenghui Xie Department of.
Proactor Pattern Venkita Subramonian & Christopher Gill
Software Architectural Styles Andrew Midwinter, Mark Mullen, Kevin Wong, Matt Jones 1.
E81 CSE 532S: Advanced Multi-Paradigm Software Development Chris Gill Department of Computer Science and Engineering Washington University, St. Louis
1 Qualitative Reasoning of Distributed Object Design Nima Kaveh & Wolfgang Emmerich Software Systems Engineering Dept. Computer Science University College.
The Client-Server Model And the Socket API. Client-Server (1) The datagram service does not require cooperation between the peer applications but such.
AMQP, Message Broker Babu Ram Dawadi. overview Why MOM architecture? Messaging broker like RabbitMQ in brief RabbitMQ AMQP – What is it ?
E81 CSE 532S: Advanced Multi-Paradigm Software Development Venkita Subramonian, Christopher Gill, Ying Huang, Marc Sentany Department of Computer Science.
1 Why Threads are a Bad Idea (for most purposes) based on a presentation by John Ousterhout Sun Microsystems Laboratories Threads!
Netprog: Client/Server Issues1 Issues in Client/Server Programming Refs: Chapter 27.
E81 CSE 532S: Advanced Multi-Paradigm Software Development Chris Gill Department of Computer Science and Engineering Washington University in St. Louis.
Interrupts and Interrupt Handling David Ferry, Chris Gill CSE 522S - Advanced Operating Systems Washington University in St. Louis St. Louis, MO
Chapter 29: Program Security Dr. Wayne Summers Department of Computer Science Columbus State University
C++11 Atomic Types and Memory Model
Threads Some of these slides were originally made by Dr. Roger deBry. They include text, figures, and information from this class’s textbook, Operating.
Component Configurator
Introduction to Generic Programming in C++
Module 12: I/O Systems I/O hardware Application I/O Interface
Chapter 4: Threads.
Boots Cassel Villanova University
How & When The Kernel Runs
Wrapper Façade Pattern
Lecture 21 Concurrency Introduction
Part 3 Design What does design mean in different fields?
Interrupts and Interrupt Handling
Advanced Operating Systems
Distributed Systems - Comp 655
Chapter 4: Threads.
The Active Object Pattern
Interpreter Style Examples
Operating System Concepts
Architectures of distributed systems Fundamental Models
Half-Sync/Half-Async (HSHA) and Leader/Followers (LF) Patterns
Issues in Client/Server Programming
Architectures of distributed systems Fundamental Models
Monitor Object Pattern
Channels.
Multithreaded Programming
Testing and Debugging Concurrent Code
Distribution Infrastructures
CSE 451: Operating Systems Autumn 2003 Lecture 2 Architectural Support for Operating Systems Hank Levy 596 Allen Center 1.
Prof. Leonardo Mostarda University of Camerino
Chapter 29: Program Security
CSE 451: Operating Systems Autumn 2001 Lecture 2 Architectural Support for Operating Systems Brian Bershad 310 Sieg Hall 1.
Chapter 13: I/O Systems I/O Hardware Application I/O Interface
Channels.
CSE 451: Operating Systems Winter 2003 Lecture 2 Architectural Support for Operating Systems Hank Levy 412 Sieg Hall 1.
Architectures of distributed systems Fundamental Models
Channels.
Chapter 4: Threads.
Interrupts and Interrupt Handling
Message Passing Systems Version 2
CSc 453 Interpreters & Interpretation
Shared Memory David Ferry, Chris Gill
Module 12: I/O Systems I/O hardwared Application I/O Interface
Threads CSE 2431: Introduction to Operating Systems
Message Passing Systems
Presentation transcript:

Event Handling Patterns Asynchronous Completion Token E81 CSE 532S: Advanced Multi-Paradigm Software Development Event Handling Patterns Asynchronous Completion Token Chris Gill, Derek Chen-Becker, Frank Hunleth Department of Computer Science and Engineering Washington University, St. Louis cdgill@cse.wustl.edu Title slide

Motivation for Event Handling Patterns Context Programs often have limited knowledge, learn about things via events Limitations of synchronous architectures Latency and jitter due to blocking, deadlock potential But, a common trade-off is less complicated programs Common Intent for Event Handling Patterns Reconcile event handling, concurrency, distribution design forces in canonical ways, to reduce accidental complexity

Event Handling Patterns (continued) Asynchronous Completion Token (Design Pattern) Passes information between asynchronous activities Reactor (Architectural Pattern) Asynchronous notification of ready events De-multiplexing and dispatch mechanisms for initiation Acceptor-Connector (Design Pattern) Decouples connection establishment from connection use Decouples passive role from active role during connection establishment Often used with the reactor Proactor (Architectural Pattern) Asynchronous notification of completion events Small pattern languages involving event handling Active object + ACT (asynch computations) Reactor + Acceptor/Connector + ACT (distributed systems) Limitations of synchronous architectures: Threading overhead (context switch, OS thread overhead) Less scalable than asynchronous Asynchronous model matches better the flow of events in GUIs and network servers What tradeoffs are made when moving from a synchronous to an asynchronous architecture? Need to correlate asynchronous requests to replies Need to demultiplex completions Need to maintain state between requests and replies How does ACT help mitigate these? Provides mechanism to correlate requests to replies Can provide efficient demultiplexing

Photo Courtesy of Derek Chen-Becker and Frank Hunleth Asynchronous Completion Token (ACT) Photo Courtesy of Derek Chen-Becker and Frank Hunleth Also Known as the “Cookie” Pattern

When Should We Use ACT? Context Problem Event-driven systems Invocation and response are asynchronous E.g., functions dispatched using std::async, std::packaged_task, or in separate threads Problem Completion events must be de-multiplexed Service does not know what a client needs to be able to de-multiplex responses Communication overhead must be minimal De-multiplexing should be efficient

ACT Solution Service (eventually) passes “cookie” to client Examples with C++11 futures and promises A future (eventually) holds ACT (or an exception) from which initiator can obtain the result Client thread can block on a call to get the data or can repeatedly poll (with timeouts if you’d like) for it A future can be packaged up with an asynchronously running service in several ways Directly: e.g., returned by std::async Bundled: e.g., via a std::packaged_task As a communication channel: e.g., via std::promise A promise can be kept or broken If broken, an exception is thrown to client

Some ACT Representations Data ACTs The most straightforward variation, holds result directly Pointer ACTs E.g. use T* to pass event handler’s memory location Issues: portability, inheritance/interface polymorphism Iterator-style ACTs Index into an array, STL iterator, etc. Watch out for copy/move semantics, etc. Memento/Command ACTs Holds all necessary information for response handler upcall Pointer ACT: void* may take up different numbers of bytes depending on the platform. How to choose? Pointer – local; no concerns about getting bad pointers back; don’t care about type safety if void* Object Reference ACTs – have middleware support; distributed calls; like type safety Index ACTs – Easier to validate; needed if state structures are remapped with shutdown Memento ACTs – Small amount of state; ACT used over long periods of time

Potential Liabilities Memory (and ) leaks Especially in client, if service doesn’t return ACT Need to use RAII, reference counted smart pointers, etc., to ensure entries are cleaned up Race conditions and deadlock Global vs. local identity, expire/retry Application remapping Affects pointer ACTs, sequence numbers etc. E.g., application crashes and restarts may remap pointer addresses Security implications Authentication, authorization, privacy Security implications: Authentication If service can’t be trusted, need to verify contents. Easier with index ACTs Make sure that responses aren’t spoofed Authorization Authorization may change between ACT creation and response. E.g. web page authorization cookie Privacy ACT contents may represent private information Legal, corporate, or user policy may limit contents and exposure