Asynchrony (computer programming): Difference between revisions

Content deleted Content added
See also: add portal
 
(27 intermediate revisions by 23 users not shown)
Line 1:
{{Short description|Computer programming technique}}
<!-- DO NOT ADD DISAMBIGUATION TAGS TO THIS PAGE (per [[WP:INCOMPDAB]] and [[WP:DABCONCEPT]]) -->
'''Asynchrony''', in [[computer programming]], refers to the occurrence of events independent of the main [[control flow|program flow]] and ways to deal with such events. These may be "outside" events such as the arrival of [[Unix signal|signals]], or actions instigated by a program that take place [[concurrent computing|concurrently]] with program execution, without the program ''blocking''[[hang (computing)|hanging]] to wait for results.<ref name="davies">{{cite book |title=Async in C# 5.0 |first=Alex |last=Davies |publisher=O'Reilly |year=2012 |pages=1–2 |isbn=9781449337124 |url=https://books.google.com/books?id=xT45qhFrVnUC}}</ref> [[Asynchronous I/O|Asynchronous input/output]] is an example of the latter causecase of asynchrony, and lets programs issue commands to storage or network devices that service these requests while the [[Central processing unit|processor]] continues executing the program. Doing so provides a degree of [[parallel computingConcurrency_(computer_science)|parallelismconcurrency]].{{r|davies}}
 
A common way for dealing with asynchrony in a [[application programming interface|programming interface]] is to provide [[subroutine]]s (methods, functions) that return to their caller an object, sometimes called a [[futures and promises|future or promise]], that represents the ongoing events.operation, Such an object will then typically come withand a synchronizing operation that [[Blocking (computing)|blocks]] until the operationfuture or promise is completed. Some programming languages, such as [[Cilk]], have special syntax for expressing an asynchronous procedure call.<ref name="spp">{{cite book |first1=Michael |last1=McCool |first2=James |last2=Reinders |first3=Arch |last3=Robison |title=Structured Parallel Programming: Patterns for Efficient Computation |publisher=Elsevier |year=2013 |pages=30}}</ref>
 
Examples of asynchrony include the following:
* [[Asynchronous procedure call]], a method to run a procedure concurrently, a lightweight alternative to [[Thread_(computing)|Threadsthreads]].
}}</ref>* [[Ajax (programming)|Ajax]] is a set of [[web developmentclient-side]] techniques utilizing many[[web development|web technologies]] used onby the [[client-side]] to create asynchronous I/O [[Webweb application]]s.
* "[[Ajax (programming)|Ajax]]", short for "asynchronous [[JavaScript]] and [[XML]]")<ref>{{cite web|url=http://shiflett.org/blog/2007/apr/ajax-is-not-an-acronym|title=Ajax Is Not an Acronym|author=Chris Shiflett|publisher=}}</ref><ref>{{cite web|url=https://blogs.oracle.com/arungupta/entry/ajax_vs_ajax_ajax_ofcourse|title=AJAX vs Ajax - Ajax ofcourse! (Arun Gupta, Miles to go ...)|publisher=}}</ref><ref name="garrett">{{cite web
* '''Asynchronous method dispatch''' (AMD), a [[data communication]] method used when there is a need for the server side to handle a large number of long lasting client requests.<ref>[https://web.archive.org/web/20130721031512/http://zeroc.com/doc/Ice-3.3.0/manual/Overview.3.2.html ICE usage of AMD].</ref> Using synchronous method dispatch (SMD), this scenario may turn the server into an unavailable busy state resulting in a connection failure response caused by a [[Computer network|network]] connection request [[Timeout (computing)|timeout]]. The servicing of a client request is immediately dispatched to an available [[thread (computer science)|thread]] from a [[Thread pool pattern|pool of threads]] and the client is put in a blocking state. Upon the completion of the task, the server is notified by a callback. The server unblocks the client and transmits the response back to the client. In case of thread [[Starvation_(computer_science)|starvation]], clients are blocked waiting for threads to become available.
| url=http://adaptivepath.org/ideas/ajax-new-approach-web-applications/
| title=Ajax: A New Approach to Web Applications
| publisher=AdaptivePath.com
| author=Jesse James Garrett
| date=18 February 2005
| accessdate=19 June 2008
}}</ref> is a set of [[web development]] techniques utilizing many web technologies used on the [[client-side]] to create asynchronous I/O [[Web application]]s.
* '''Asynchronous method dispatch''' (AMD), a data communication method used when there is a need for the server side to handle a large number of long lasting client requests.<ref>[https://web.archive.org/web/20130721031512/http://zeroc.com/doc/Ice-3.3.0/manual/Overview.3.2.html ICE usage of AMD].</ref> Using synchronous method dispatch (SMD), this scenario may turn the server into an unavailable busy state resulting in a connection failure response caused by a [[Computer network|network]] connection request [[Timeout (computing)|timeout]]. The servicing of a client request is immediately dispatched to an available [[thread (computer science)|thread]] from a [[Thread pool pattern|pool of threads]] and the client is put in a blocking state. Upon the completion of the task, the server is notified by a callback. The server unblocks the client and transmits the response back to the client. In case of thread starvation, clients are blocked waiting for threads to become available.
 
==Scenarios for Async==
1. '''I/O operations''': I/O operations like file I/O, network I/O, database I/O, (which is generally just network I/O), and web service calls benefit from asynchrony. Anytime that your code is making a database call, or a web service call or a network call or talking to the file system, that can be done asynchronously while that operation is in progress.
 
2. '''Performing multiple operations parallelly''': When you need to do different operations in parallel, for example, making a database call, web service call and any calculations, then we can use asynchrony.
 
3. '''Long-running event-driven requests:''' This is the idea where you have a request that comes in, and the request goes to sleep for some time waiting for some other event to take place when that event takes place, you want the request to continue and then send a response to client. So in this case, when request comes in, then thread is assigned to that request and as request goes to sleep, then thread is sent back to threadpool and as the task completes, then it generates the event and picks a thread from thread pool for sending response (the thread sent and picked from thread pool might or might not be the same.<ref>{{Cite web|url=https://www.codeproject.com/Tips/866962/Async-and-Await-Tutorial|title=Async and Await Tutorial|last=Goel|first=Gaurav|date=|website=Code Project|url-status=live|archive-url=|archive-date=|access-date=March 3, 2020}}</ref>
 
==See also==
{{Portal|Computer programming}}
* [[Asynchronous system]]
* [[Asynchronous circuit]]
Line 29 ⟶ 17:
==References==
{{reflist}}
Testing wiki edit
[[Category:Computer programming]]
[[Category:Inter-process communication]]
[[Category:Middleware]]
 
 
{{comp-sci-stub}}