Synchronous vs. Asynchronous Programming
Jan Pascal Maas
Institute for Software Engineering and Programming Languages University of Luebeck
- 25. January 2016
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.
Institute for Software Engineering and Programming Languages University of Luebeck
Introduction Classification Approaches Conclusion
1
2
3
4
Synchronous vs. Asynchronous Programming 2/ 30
Introduction Classification Approaches Conclusion
Synchronous vs. Asynchronous Programming 3/ 30
Introduction Classification Approaches Conclusion
Synchronous vs. Asynchronous Programming 4/ 30
Introduction Classification Approaches Conclusion
Synchronous vs. Asynchronous Programming 4/ 30
Introduction Classification Approaches Conclusion
Synchronous vs. Asynchronous Programming 5/ 30
Introduction Classification Approaches Conclusion
Synchronous vs. Asynchronous Programming 6/ 30
Introduction Classification Approaches Conclusion
Synchronous vs. Asynchronous Programming 7/ 30
Introduction Classification Approaches Conclusion
Synchronous vs. Asynchronous Programming 8/ 30
Introduction Classification Approaches Conclusion
Synchronous vs. Asynchronous Programming 9/ 30
Introduction Classification Approaches Conclusion
Synchronous vs. Asynchronous Programming 10/ 30
Introduction Classification Approaches Conclusion
Synchronous vs. Asynchronous Programming 11/ 30
Introduction Classification Approaches Conclusion
Synchronous vs. Asynchronous Programming 11/ 30
Introduction Classification Approaches Conclusion
Synchronous vs. Asynchronous Programming 12/ 30
Introduction Classification Approaches Conclusion
Synchronous vs. Asynchronous Programming 12/ 30
Introduction Classification Approaches Conclusion
Synchronous vs. Asynchronous Programming 13/ 30
Introduction Classification Approaches Conclusion
Synchronous vs. Asynchronous Programming 14/ 30
Introduction Classification Approaches Conclusion
Synchronous vs. Asynchronous Programming 15/ 30
Introduction Classification Approaches Conclusion
Synchronous vs. Asynchronous Programming 15/ 30
Introduction Classification Approaches Conclusion
Synchronous vs. Asynchronous Programming 16/ 30
Introduction Classification Approaches Conclusion
Synchronous vs. Asynchronous Programming 16/ 30
Introduction Classification Approaches Conclusion
Synchronous vs. Asynchronous Programming 17/ 30
Introduction Classification 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 . . . Tm Thread T1 Database File System handled by Blocking IO? Event Loop
Send Responses
non-blocking is processed here Event Queue Internal Thread Pool Blocking IO handler
Request-2 Request-n Response-1 Response-2 Response-n Pick up Requests from Queue
no no yes non-blocking IO non-blocking IO blocking IO pickup one Thread
Synchronous vs. Asynchronous Programming 18/ 30
Introduction Classification 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 . . . Tm Thread T1 Database File System handled by Blocking IO? Event Loop
Send Responses
non-blocking is processed here Event Queue Internal Thread Pool Blocking IO handler
Request-2 Request-n Response-1 Response-2 Response-n Pick up Requests from Queue
no no yes non-blocking IO non-blocking IO blocking IO pickup one Thread
Synchronous vs. Asynchronous Programming 18/ 30
Introduction Classification 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 . . . Tm Thread T1 Database File System handled by Blocking IO? Event Loop
Send Responses
non-blocking is processed here Event Queue Internal Thread Pool Blocking IO handler
Request-2 Request-n Response-1 Response-2 Response-n Pick up Requests from Queue
no no yes non-blocking IO non-blocking IO blocking IO pickup one Thread
Synchronous vs. Asynchronous Programming 18/ 30
Introduction Classification 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 . . . Tm Thread T1 Database File System handled by Blocking IO? Event Loop
Send Responses
non-blocking is processed here Event Queue Internal Thread Pool Blocking IO handler
Request-2 Request-n Response-1 Response-2 Response-n Pick up Requests from Queue
no no yes non-blocking IO non-blocking IO blocking IO pickup one Thread
Synchronous vs. Asynchronous Programming 18/ 30
Introduction Classification 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 . . . Tm Thread T1 Database File System handled by Blocking IO? Event Loop
Send Responses
non-blocking is processed here Event Queue Internal Thread Pool Blocking IO handler
Request-2 Request-n Response-1 Response-2 Response-n Pick up Requests from Queue
no no yes non-blocking IO non-blocking IO blocking IO pickup one Thread
Synchronous vs. Asynchronous Programming 18/ 30
Introduction Classification 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 . . . Tm Thread T1 Database File System handled by Blocking IO? Event Loop
Send Responses
non-blocking is processed here Event Queue Internal Thread Pool Blocking IO handler
Request-2 Request-n Response-1 Response-2 Response-n Pick up Requests from Queue
no no yes non-blocking IO non-blocking IO blocking IO pickup one Thread
Synchronous vs. Asynchronous Programming 18/ 30
Introduction Classification 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 . . . Tm Thread T1 Database File System handled by Blocking IO? Event Loop
Send Responses
non-blocking is processed here Event Queue Internal Thread Pool Blocking IO handler
Request-2 Request-n Response-1 Response-2 Response-n Pick up Requests from Queue
no no yes non-blocking IO non-blocking IO blocking IO pickup one Thread
Synchronous vs. Asynchronous Programming 18/ 30
Introduction Classification Approaches Conclusion
public int Divide ( int top , int bottom) { i f (bottom==0) { throw new InvalidOperationException (” div ␣by␣0” ) ; } else { return top/bottom ; } } public bool IsEven ( int aNumber) { var isEven = (aNumber % 2 == 0); return isEven ; }
Synchronous vs. Asynchronous Programming 19/ 30
Introduction Classification Approaches Conclusion
public T Divide< T >(int top , int bottom , Func < T > ifZero , Func <int ,T > ifSuccess ) { i f (bottom==0) { return ifZero ( ) ; } else { return ifSuccess ( top/bottom ) ; } } public T IsEven< T >(int aNumber , Func <int ,T > ifOdd , Func <int ,T > ifEven ) { i f (aNumber % 2 == 0) { return ifEven (aNumber ) ; } else { return ifOdd (aNumber ) ; } }
Synchronous vs. Asynchronous Programming 20/ 30
Introduction Classification Approaches Conclusion
Synchronous vs. Asynchronous Programming 21/ 30
Introduction Classification Approaches Conclusion
Synchronous vs. Asynchronous Programming 22/ 30
Introduction Classification Approaches Conclusion
Synchronous vs. Asynchronous Programming 23/ 30
Introduction Classification Approaches Conclusion
Synchronous vs. Asynchronous Programming 24/ 30
Introduction Classification Approaches Conclusion
Synchronous vs. Asynchronous Programming 24/ 30
Introduction Classification Approaches Conclusion
Synchronous vs. Asynchronous Programming 25/ 30
Introduction Classification Approaches Conclusion
Synchronous vs. Asynchronous Programming 26/ 30
Introduction Classification Approaches Conclusion
Synchronous vs. Asynchronous Programming 26/ 30
Introduction Classification Approaches Conclusion
Synchronous vs. Asynchronous Programming 27/ 30
Introduction Classification Approaches Conclusion
Synchronous vs. Asynchronous Programming 27/ 30
Introduction Classification Approaches Conclusion
Synchronous vs. Asynchronous Programming 28/ 30
Introduction Classification Approaches Conclusion
Synchronous vs. Asynchronous Programming 28/ 30
Introduction Classification Approaches Conclusion
Synchronous vs. Asynchronous Programming 29/ 30
Introduction Classification Approaches Conclusion
Synchronous vs. Asynchronous Programming 30/ 30