Ce diaporama a bien été signalé.
Le téléchargement de votre SlideShare est en cours. ×

Synchronous vs Asynchronous Programming

Publicité
Publicité
Publicité
Publicité
Publicité
Publicité
Publicité
Publicité
Publicité
Publicité
Publicité
Publicité
Prochain SlideShare
what is OSI model
what is OSI model
Chargement dans…3
×

Consultez-les par la suite

1 sur 18 Publicité

Plus De Contenu Connexe

Plus par jeetendra mandal (20)

Plus récents (20)

Publicité

Synchronous vs Asynchronous Programming

  1. 1. What is Synchronous programming? In programming, synchronous programs allocate a single thread to handle a request or complete a task. Since synchronous operations happen one at a time, a painstakingly long task like a database query will block all other threads in the meantime. While asynchronous operations can run multiple tasks concurrently on a single thread, synchronous programs have a task queue where every other task remains idle while the first is completed. By definition, synchronous means ‘connected’ or ‘dependent’. In essence, synchronous communication is tightly coupled. For reactive systems, when programs work best when they react to environmental input, synchronous programs can be useful
  2. 2. What is Synchronous programming? Synchronous programs use blocking I/O operations in which each operation has to run before the next is executed. Generally, computers are fast, so synchronous communication isn’t necessarily disadvantageous. However, in a real-life, non-technical application, this would be the equivalent of your waiter refusing to bring out any of the dishes you ordered until each and every dish were fully prepared.
  3. 3. Benefits of Synchronous programming? Synchronous programming is well-supported amongst all programming languages. Developers do not have to worry about whether it is possible to code asynchronous applications as this is the default. Plus, writing synchronous programs is objectively easier than writing asynchronous programs. In utilizing a blocking I/O architecture you can save time in the software development process and run tests with fewer complications.
  4. 4. Benefits of Synchronous programming? Search engines find it easier to crawl for web pages that make use of traditional synchronous architecture. For marketers who depend on search engine optimization (SEO) to build their reputation and brand awareness, this is an appreciable advantage.
  5. 5. What is Asynchronous programming? Asynchronous programming relies on a non-blocking input and output (I/O) protocol. This signifies that an asynchronous program does not execute operations in a hierarchical or sequential order. The resulting parallelization means an asynchronous program can take on multiple requests simultaneously and independently. When one request fails, it has no effect on another request. And the program can move to another task before finishing the last. In software development, an advantage of this kind is called loose coupling. Loosely coupled communication and/or programming allows for decentralized processes.
  6. 6. What is Asynchronous programming? Fewer dependencies lead to higher fault tolerance and increased flexibility. For businesses that prioritize getting things done, asynchronous programming can be a fundamental building block in meeting project requirements. Imagine a non-technical example of how asynchronous communication would look like in a real-world scenario. As an illustration, envision you’re at a restaurant. Your waiter has just taken multiple orders at your table and brings out your appetizer as soon as it’s ready, instead of waiting for your main entree to be prepared as well. Not only is this simply efficient service, but it’s an exemplary demonstration of a non- blocking I/O or asynchronous architecture.
  7. 7. Benefits of Asynchronous programming? In comparing asynchronous and synchronous programming, asynchronous programs improve user experience in a variety of ways. First, all the scripts of a program or web page can load at one time, resulting in better responsiveness and decreased page load delays. And the failure of a thread has no consequence on the ability of other threads to run or render. Therefore, there is more availability overall with asynchronous applications.
  8. 8. Benefits of Asynchronous programming? In practice, asynchronous programming requires writing callback functions in line with errors that may occur and disrupt a program. These callbacks instruct the machine to move past the error and run the next task. This also gives programmers the opportunity to write a personalized error message. As a result, errors do not mean that your program altogether fails to run. Users get a nice note while all the other features of the program work just fine.
  9. 9. Use case of Synchronous vs Asynchronous For example if you want to download a file from the internet you might use a synchronous function to do that but it will block your thread until the file finished downloading. This can make your application unresponsive to any user input. Instead you could download the file in the background using asynchronous method. In this case the download function returns immediately and program execution continues normally. All the download operations are done in the background and your program will be notified when it's finished.
  10. 10. Use case of Synchronous vs Asynchronous When you execute something synchronously, you wait for it to finish before moving on to another task. When you execute something asynchronously, you can move on to another task before it finishes. Synchronous execution means the execution happens in a series a->b->c->d. If you are calling methods ‘a ‘will run first and then when ‘a’ finish then ‘b’ will start. With Asynchronous execution , you can start with ‘a’, and then ‘a’ can go in background and we don’t need to wait for ‘a’ to finish, ‘b’ can start parallely.
  11. 11. Use case of Synchronous vs Asynchronous The biggest contribution that asynchronous programming provides is enhanced throughput. Throughput refers to the deliverables a product or company can produce within a specified time. As established, computers are fast. Thus, synchronous programming is not as time-consuming as you might imagine. If you merely wish to develop a front-end application or execute a basic central process unit (CPU) function, then asynchronous programming is way out of bounds.
  12. 12. Use case of Synchronous User Interfaces: User interface (UI) designs are typically synchronous. Since UIs are spaces where humans and computers interact, it is ideal for them to replicate the communication standards and practices humans are familiar with. Humans expect an immediate response when they interact with a computer! •HTTP APIs: HTTP APIs pass requests and responses in a synchronous fashion. Client programs sending HTTP requests usually expect a fast answer from the web server. Use case of Asynchronous •Batch-processing: is a data-processing method to handle large amounts of data asynchronously. With asynchronous batch-processing, large batches of data are processed at scheduled times to avoid blocking computing resources. •Long-running tasks: such as fulfilling an order placed on an e-commerce site are best handled asynchronously. There is no need to block resources while this task is executed.
  13. 13. Summary Synchronous and asynchronous, also known as sync and async, are two types of programming models. At an abstract level, programming models define how software is designed and executed. The basic programming models are synchronous, but asynchronous models are critical for performance reasons and to more efficiently use computing resources. Programming languages usually have built-in primitives to deal with asynchronous programming. Asynchronous programming is a style of programming in which the execution of a task is not guaranteed to occur in a specific order. This contrasts with synchronous programming, where all code execution is guaranteed to happen in a specific order.
  14. 14. THANK YOU Like the Video and Subscribe the Channel

×