synchronous vs asynchronous programming
play

Synchronous vs. Asynchronous Programming Jan Pascal Maas Institute - PowerPoint PPT Presentation

Synchronous vs. Asynchronous Programming Jan Pascal Maas Institute for Software Engineering and Programming Languages University of Luebeck 25. January 2016 Seminar Concepts of Programming Languages Introduction 3 Synchronous vs.


  1. Synchronous vs. Asynchronous Programming Jan Pascal Maas Institute for Software Engineering and Programming Languages University of Luebeck 25. January 2016 Seminar Concepts of Programming Languages

  2. Introduction 3 Synchronous vs. Asynchronous Programming J. P. Maas (University of Luebeck) Conclusion 4 Asynchronous Synchronous Approaches Asynchronous Programming Classification Synchronous Programming Classification 2 Introduction 1 Agenda Conclusion Approaches 2/ 30

  3. Introduction Classification Approaches Conclusion Introduction programs rely on multiple constraints especially concurrency and communication increase complexity concurrency is largely explored general programming paradigms can be used multiple approaches exist J. P. Maas (University of Luebeck) Synchronous vs. Asynchronous Programming 3/ 30

  4. Introduction Classification Approaches Conclusion Introduction—Communication increases complexity largely Example (Air Traffic Control System) information is known beforehand all tasks can run independently low complexity information and communication during execution system needs to be capable of accepting and processing information requires high amount of synchronized communication J. P. Maas (University of Luebeck) Synchronous vs. Asynchronous Programming 4/ 30

  5. Introduction Classification Approaches Conclusion Introduction—Communication increases complexity largely Example (Air Traffic Control System) information is known beforehand all tasks can run independently low complexity information and communication during execution system needs to be capable of accepting and processing information requires high amount of synchronized communication J. P. Maas (University of Luebeck) Synchronous vs. Asynchronous Programming 4/ 30

  6. Introduction Classification Approaches Conclusion Introduction—Paradigms to Synchronize blocking (scheduler-based): block task to use resources differently blocked task ensures resuming of computation specific synchronization condition required busy-waiting : use of an evaluation loop reevaluated specific condition till it becomes true J. P. Maas (University of Luebeck) Synchronous vs. Asynchronous Programming 5/ 30

  7. Introduction Classification Approaches Conclusion Synchronous Programming applies scheduler-based synchronization blocks a task if it is necessary resources can be used for a different task if needed resources are available, computation continues ensures correctness of the system J. P. Maas (University of Luebeck) Synchronous vs. Asynchronous Programming 6/ 30

  8. Introduction Classification Approaches Conclusion Figure: Synchronous blocking model [1]. J. P. Maas (University of Luebeck) Synchronous vs. Asynchronous Programming 7/ 30

  9. Introduction Classification Approaches Conclusion Figure: Asynchronous model [1]. J. P. Maas (University of Luebeck) Synchronous vs. Asynchronous Programming 8/ 30

  10. Introduction Classification Approaches Conclusion Asynchronous Programming uses busy-waiting re-evaluation of a specific condition if true, condition depends on an external system actions to compute are specified before execution main thread continues running actions that depend on external system(s) are executed on different thread J. P. Maas (University of Luebeck) Synchronous vs. Asynchronous Programming 9/ 30

  11. Introduction Classification Approaches Conclusion Synchronous Approaches— LUSTRE data-flow oriented language focussed on temporal correctness variables are treated as infinite sequences J. P. Maas (University of Luebeck) Synchronous vs. Asynchronous Programming 10/ 30 ( x 0 = e 0 , x 1 = e 1 , ..., x n = e n ,... )

  12. Introduction Y = current(X) X = E when B =( x 0 e 0 x 1 e 2 x 2 e 3 . . . ) =( . . . e 0 e 0 e 2 e 3 e 3 e 3 . . . ) J. P. Maas (University of Luebeck) Synchronous vs. Asynchronous Programming ) ff Classification ff Approaches Conclusion LUSTRE—Operators E =( e 0 e 1 e 2 e 3 e 4 e 5 . . . ) B =( tt ff tt tt 11/ 30 Let X = ( x 0 , x 1 , ..., x n , ... ) and Y = ( y 0 , y 1 , ..., y n , ... ) . pre(X) = ( nil , x 0 , x 1 , ..., x n − 1 , ... ) X − > Y = ( x 0 , y 1 , ..., y n , ... )

  13. Introduction =( ff . . . ) X = E when B =( . . . ) Y = current(X) e 0 tt e 0 e 2 e 3 e 3 e 3 . . . ) J. P. Maas (University of Luebeck) Synchronous vs. Asynchronous Programming Classification ff tt ff Approaches Conclusion LUSTRE—Operators E =( e 0 e 1 e 2 e 3 e 4 e 5 . . . ) B =( tt 11/ 30 Let X = ( x 0 , x 1 , ..., x n , ... ) and Y = ( y 0 , y 1 , ..., y n , ... ) . pre(X) = ( nil , x 0 , x 1 , ..., x n − 1 , ... ) X − > Y = ( x 0 , y 1 , ..., y n , ... ) x 0 = e 0 x 1 = e 2 x 2 = e 3

  14. Introduction Classification Approaches Conclusion LUSTRE—Synchronization when is used to create streams streams allow synchronization of the program to synchronize differently clocked streams, current is used assertions generalize equations facts to synchronize program assert not (x and y) J. P. Maas (University of Luebeck) Synchronous vs. Asynchronous Programming 12/ 30

  15. Introduction Classification Approaches Conclusion LUSTRE—Synchronization when is used to create streams streams allow synchronization of the program to synchronize differently clocked streams, current is used assert not (x and y) J. P. Maas (University of Luebeck) Synchronous vs. Asynchronous Programming 12/ 30 assertions generalize equations → facts to synchronize program

  16. Introduction Classification Approaches Conclusion SIGNAL concept similar to LUSTRE allows explicit synchronization using synchro merging of two signals with default J. P. Maas (University of Luebeck) Synchronous vs. Asynchronous Programming 13/ 30

  17. Introduction Classification Approaches Conclusion ESTEREL imperative language variables are called signals reaction : process of computing output based on input J. P. Maas (University of Luebeck) Synchronous vs. Asynchronous Programming 14/ 30 fixed status and current value (initially � ) in the same reaction

  18. Introduction I1 Synchronous vs. Asynchronous Programming J. P. Maas (University of Luebeck) emit O2 I2 ; watching O1 do Classification present: detects for presence of a signal watching: await specific signal emit: sending output signals ESTEREL—Synchronization Conclusion Approaches 15/ 30

  19. Introduction Classification Approaches Conclusion ESTEREL—Synchronization emit: sending output signals watching: await specific signal present: detects for presence of a signal do watching I2 ; emit O2 J. P. Maas (University of Luebeck) Synchronous vs. Asynchronous Programming 15/ 30 I1 − > O1

  20. Introduction Classification Approaches Conclusion Asynchrony through Concurrency multiple threads used to perform IO-bound tasks Problem: Scalability is limited requirement of different approaches J. P. Maas (University of Luebeck) Synchronous vs. Asynchronous Programming 16/ 30

  21. Introduction Classification Approaches Conclusion Asynchrony through Concurrency multiple threads used to perform IO-bound tasks Problem: Scalability is limited requirement of different approaches J. P. Maas (University of Luebeck) Synchronous vs. Asynchronous Programming 16/ 30

  22. Introduction Classification Approaches Conclusion Asynchronous Approaches—Event Loop inversion of control efficiency and scalability control over switching between application activities relies on notification facilities application handles occurrence of events commonly used: Node.js J. P. Maas (University of Luebeck) Synchronous vs. Asynchronous Programming 17/ 30

  23. Introduction Response- n non-blocking is processed here Event Queue Internal Thread Pool Blocking IO handler Request-1 Request-2 Request- n Response-1 Response-2 Pick up Requests from Queue Classification no no yes non-blocking IO non-blocking IO blocking IO pickup one Thread Figure: Node.js processing model [2]. J. P. Maas (University of Luebeck) Synchronous vs. Asynchronous Programming Send Responses Event Loop Blocking IO? handled by Approaches Conclusion Client 1 Client 2 Client n Request 1 Request 2 . . . Request n Request 1 Request 2 Request n Request 1 Request 2 Request n T1 T2 . . . T m Thread T1 Database File System 18/ 30 ⋮ ⇐ �

  24. Introduction Response- n non-blocking is processed here Event Queue Internal Thread Pool Blocking IO handler Request-1 Request-2 Request- n Response-1 Response-2 Pick up Requests from Queue Classification no no yes non-blocking IO non-blocking IO blocking IO pickup one Thread Figure: Node.js processing model [2]. J. P. Maas (University of Luebeck) Synchronous vs. Asynchronous Programming Send Responses Event Loop Blocking IO? handled by Approaches Conclusion Client 1 Client 2 Client n Request 1 Request 2 . . . Request n Request 1 Request 2 Request n Request 1 Request 2 Request n T1 T2 . . . T m Thread T1 Database File System 18/ 30 ⋮ ⇐ �

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend