You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: docs/concepts/sync-vs-async.rst
+28-74
Original file line number
Diff line number
Diff line change
@@ -4,36 +4,54 @@ Sync vs Async Applications
4
4
5
5
TL;DR
6
6
------
7
-
1. For applications with horizontal scaling: multiple users, lots of i/o throughput,... go with async. Check out:
7
+
8
+
Burr supports synchronous (standard python) and asynchronous (``async def``/``await``) applications. At a high leveL:
9
+
10
+
1. Use the `async` interfaces when you have I/O-heavy applications that require horizontal scaling, and have avaialble asynchronous APIs (E.G. async LLM APIs)
A synchronous application processes tasks sequentially for every thread/process it executes, blocking entirely on the result
28
+
of the prior call. For Burr, this means that two separate applications have to run in a separate thread/process, and that running
29
+
parallel processes have to launch in a multithreaded/multi-processing environment, run, and join the results.
30
+
31
+
In the case of Burr, this means that you have a 1:1 app -> thread/process mapping (unless you're using :ref:`parallelism <parallelism>` and explicitly multithreading sub-actions).
21
32
22
-
Burr does both sync and async
23
-
------------------------------
24
-
Bellow we give a short breakdown when to consider each case.
33
+
An asynchronous application can parallelize multiple I/O bound tasks within the confines of a single thread. At the time that
34
+
a task blocks on I/O it can give control back to the process, allow it to run other tasks simultaneously.
35
+
36
+
In the case of Burr, this allows you to run more than one applications,in parallel, on the same thread.
37
+
Note, however, that you have to ensure the application is async all the way down -- E.G. that every blocking call
38
+
is called using `await` -- if it blocks the event loop through a slow, synchronous call, it will block *all* current
39
+
applications.
25
40
26
41
In general, Burr is equipped to handle both synchronous and asynchronous runs. We usually do that by
27
42
providing both methods (see specific references for more detail and reach out if you feel like we
28
-
are missing a specific implementation).
43
+
are missing a specific implementation). Furthermore, Burr suports the following APIs for both synchronous/asynchronous interfaces:
44
+
45
+
- :ref:`hooks <hooksref>`
46
+
- :ref:`persisters <persistersref>`
29
47
30
-
We hope the switch from one to another is as convenient as possible; you only need to substitute
31
-
functions/adapters/method calls.
48
+
Nuances of Sync + Async together
49
+
--------------------------------
32
50
33
-
We highly encourage to make a decision to either commit fully to sync or async. Having said that,
51
+
We encourage to make a decision to either commit fully to sync or async. That said,
34
52
there are cases where a hybrid situation may be desirable or unavoidable (testing, prototyping,
35
53
legacy code, ...) and we give some options to handle that. The table bellow shows the
36
-
possibilities Burr now supports.
54
+
possibilities Burr now supports -- combining the set of synchronous/asynchronous.
37
55
38
56
39
57
.. table:: Cases Burr supports
@@ -73,67 +91,3 @@ possibilities Burr now supports.
0 commit comments