Advanced Software Engineering Internet Applications PDF

Document Details

SmilingHibiscus5596

Uploaded by SmilingHibiscus5596

Université de Fribourg

2024

Jacques Pasquier/Mourad Khayati/Quentin Nater

Tags

asynchronous programming software engineering internet applications computer science

Summary

This document presents lecture notes on advanced software engineering focusing on asynchronous programming. It covers various aspects of this topic, including motivation, definitions (with examples in Python), its implications in Node.js (including callbacks and promises), and a summary of the underlying Node.js model.

Full Transcript

Advanced Software Engineering Internet Applications A Few Words about Asynchronous Programming Advanced Software Engineering /Internet Applications AS 2024 – Prof. Jacques Pasquier / Dr. Mourad Khayati/ Quentin Nater 1/20 Overview 1. Motivation 2. Definition / Alternat...

Advanced Software Engineering Internet Applications A Few Words about Asynchronous Programming Advanced Software Engineering /Internet Applications AS 2024 – Prof. Jacques Pasquier / Dr. Mourad Khayati/ Quentin Nater 1/20 Overview 1. Motivation 2. Definition / Alternative Models 3. Illustrative Example (very simple in Python) 4. Evolution of Async Programming within Node.js - Callbacks - Promises - async/await 5. Wrapping up - Recap - Node.js Model Summary 6. Bibliography Advanced Software Engineering /Internet Applications AS 2024 – Prof. Jacques Pasquier / Dr. Mourad Khayati/ Quentin Nater 2/20 1. Motivation – 1 In a single-threaded synchronous program, if n (independent) tasks have to be performed, the CPU wastes a lot of time waiting (e.g. on disk or network I/O). From : http://cs.brown.edu/courses/cs168/f16/content/docs/async.pdf Advanced Software Engineering /Internet Applications AS 2024 – Prof. Jacques Pasquier / Dr. Mourad Khayati/ Quentin Nater 3/20 1. Motivation – 2 The only reason behind asynchronous programming is making code go fast without consuming too much memory resources. For a busy (REStful) server with a lot of connections and little memory resources (e.g. embarked on a smart thing), it offers much better scalability than other solutions. (e.g. a multi-thread server needs more memory resources and does not scale as well). Advanced Software Engineering /Internet Applications AS 2024 – Prof. Jacques Pasquier / Dr. Mourad Khayati/ Quentin Nater 4/20 2. Definition / Alternatives – 1 Definition 1 Asynchronous programming is a style of concurrent programming, which means making many things at once. The way to do it is to use the processor at its maximum by liberating it, while slower tasks (e.g. reading / writing on a disk, receiving / sending network packets, or executing database requests) are taking place. Three models are possible to implement concurrent programming : ▶ Using multiple processes. The OS does the work, but processes are quite heavy and resources demanding. ▶ Using a multi-threaded synchronous model. Threads are less resources consuming than processes, but they often share access to the same spaces and programming with events and many threads can become quite a headache. ▶ Using an asynchronous programming language and / or library. Advanced Software Engineering /Internet Applications AS 2024 – Prof. Jacques Pasquier / Dr. Mourad Khayati/ Quentin Nater 5/20 2. Definition / Alternatives – 2 Definition 2 Asynchronous programming is a style of concurrent programming, in which tasks release the CPU during waiting periods so that other tasks can use it. It is based on cooperative multi-tasking. From : http://cs.brown.edu/courses/cs168/f16/content/docs/async.pdf Advanced Software Engineering /Internet Applications AS 2024 – Prof. Jacques Pasquier / Dr. Mourad Khayati/ Quentin Nater 6/20 2. Definition / Alternatives – 3 From : https://www.youtube.com/watch?v=iG6fr81xHKA&feature=youtu.be Advanced Software Engineering /Internet Applications AS 2024 – Prof. Jacques Pasquier / Dr. Mourad Khayati/ Quentin Nater 7/20 3. Illustrative Example See all examples on GitHub: https://bit.ly/asyncpython Advanced Software Engineering /Internet Applications AS 2024 – Prof. Jacques Pasquier / Dr. Mourad Khayati/ Quentin Nater 8/20 4. Node.js : Callbacks – 1 2 1 Advanced Software Engineering /Internet Applications AS 2024 – Prof. Jacques Pasquier / Dr. Mourad Khayati/ Quentin Nater 9/20 4. Node.js : Callbacks – 2 param Advanced Software Engineering /Internet Applications AS 2024 – Prof. Jacques Pasquier / Dr. Mourad Khayati/ Quentin Nater 10/20 4. Node.js : Callbacks – 3 Advanced Software Engineering /Internet Applications AS 2024 – Prof. Jacques Pasquier / Dr. Mourad Khayati/ Quentin Nater 11/20 4. Node.js : Promises – 1 Advanced Software Engineering /Internet Applications AS 2024 – Prof. Jacques Pasquier / Dr. Mourad Khayati/ Quentin Nater 12/20 4. Node.js : Promises – 2 Advanced Software Engineering /Internet Applications AS 2024 – Prof. Jacques Pasquier / Dr. Mourad Khayati/ Quentin Nater 13/20 4. Node.js : Promises – 3 Advanced Software Engineering /Internet Applications AS 2024 – Prof. Jacques Pasquier / Dr. Mourad Khayati/ Quentin Nater 14/20 4. Node.js : Promises – 4 Advanced Software Engineering /Internet Applications AS 2024 – Prof. Jacques Pasquier / Dr. Mourad Khayati/ Quentin Nater 15/20 4. Node.js : async/await – 1 Advanced Software Engineering /Internet Applications AS 2024 – Prof. Jacques Pasquier / Dr. Mourad Khayati/ Quentin Nater 16/20 4. Node.js : async/await – 2 Advanced Software Engineering /Internet Applications AS 2024 – Prof. Jacques Pasquier / Dr. Mourad Khayati/ Quentin Nater 17/20 5. Wrapping up : Node Model Summary Advanced Software Engineering /Internet Applications AS 2024 – Prof. Jacques Pasquier / Dr. Mourad Khayati/ Quentin Nater 18/20 5. Wrapping up : Recap Advanced Software Engineering /Internet Applications AS 2024 – Prof. Jacques Pasquier / Dr. Mourad Khayati/ Quentin Nater 19/20 6. Bibliography  Miguel Grinberg Asynchronous Python for the Complete Beginner PyCon 2017  https://youtu.be/iG6fr81xHKA  Implementing Promises by Forbes Lindesay  https://www.promisejs.org/implementing/  Async function – JavaScript  https://developer.mozilla.org/en- US/docs/Web/JavaScript/Reference/Statements/async_function  Dayley, B. (2014). Node.js, MongoDB and AngularJS web development. Advanced Software Engineering /Internet Applications AS 2024 – Prof. Jacques Pasquier / Dr. Mourad Khayati/ Quentin Nater 20/20

Use Quizgecko on...
Browser
Browser