https://objectoriented.ru/arch:does-async-io-help-in-increasing-throughput-in-practical-applications
By Vladislav Belovitskiy (vibelovitskiy@edu.hse.ru)
In programming, there are two ways to perform tasks: synchronously and asynchronously. Synchronous tasks are executed in a sequential order, meaning that each task must be completed before moving on to the next one. On the other hand, asynchronous can be executed in any order or even simultaneously, without waiting for the completion of previous tasks [1].
The question is: does async input/output (IO) always increase throughput in modern applications? Current paper will compare asynchronous and synchronous approaches in context of different application types and throughput capabilities.
Nowadays, most of programming languages are being significantly developed in the field of asynchronous programming. It is required in modern high load web applications, as well as in mobile apps that handles complex user interactions.
In certain types of applications, such as web services and load balancers, which typical use case is passing the requests to the other backend services or databases while waiting for the corresponding responses, utilizing asynchronous actions can significantly enhance the overall throughput and performance [2]. By employing asynchronous actions, these applications can efficiently handle multiple concurrent requests without blocking the execution flow. As a result, they can process incoming requests in parallel and make optimal use of available system resources. This approach helps to minimize idle time and improve the overall responsiveness of the application.
Also there are some scenarios, when may be a need to cancel running requests. Let's consider an example where an application initiates 10 different requests concurrently and waits for the results. However, the application is only interested in the result of the first request completed, and the remaining 9 results are not needed. So, it becomes necessary to cancel the remaining requests to avoid unnecessary resource consumption. Asynchronous actions provide the flexibility to abort the execution of a task, thereby freeing up system resources and improving efficiency.
Thus, asynchronous approach is suitable for applications that are highly dependend on IO operations and when load is unpredictable. This approach increases application scalability and usually it is the best choice for modern web applications, that handles many users requests, which amount is significantly higher than acceptable amount of threads [3].
The main scenario for synchronous approach is applications, that runs CPU-bound tasks. In applications that runs optimization algorithms or processing large files in memory, the execution is typically dependent on the CPU and does not involve blocking I/O operations. In such cases, using asynchronous actions may not provide any significant benefits, as the threads executing the tasks are not blocked by IO operations. In fact, making these types of applications asynchronous may introduce unnecessary overhead without delivering any noticeable advantages. Therefore, it is often more suitable to write these applications using synchronous actions.
The other scenario for synchronous approach are the applications with low throughput requirements. In certain applications, the number of concurrent requests may be quite low due to low amount of users or specific use cases. Office applications often fall into this category. In such scenarios, where there are not many concurrent requests to be fulfilled, the use of asynchronous actions may not be necessary or beneficial. Synchronous actions, which execute tasks in a sequential and blocking manner, can handle the workload without introducing the complexities associated with asynchronous programming.
Thus, synchronous approach is suitable for CPU-bound tasks or for applications with predictable load and low amount of concurrent requests, that could be handled by reasonable amount of threads.
In my opinion, asynchronous approach is a silver bullet for the most of modern web applications, that requires scalability and serves to high amount of users. In this scenarios it significantly increases application throughput [4]. Synchronous approach, on the other hand, is preffered in some specific cases, such as CPU-bound tasks or when load is predictable and high throughput is not a requirement.
I hope this paper helps you to distinguish the difference between asynchronous and synchronous approaches in context of different types of modern applications.
1. Ossian Muscad. Synchronous Vs. Asynchronous: A Guide To Choosing The Ideal Programming Model (2022). URL: https://datamyte.com/blog/synchronous-vs-asynchronous/
2. Gokhan Sengun. ASP.NET MVC and Web API - Comparison of Async/Sync Actions (2016). URL: https://gokhansengun.com/asp-net-mvc-and-web-api-comparison-of-async-or-sync-actions/
3. Stephen Cleary. Async Programming : Introduction to Async/Await on ASP.NET (2014). URL: https://learn.microsoft.com/en-us/archive/msdn-magazine/2014/october/async-programming-introduction-to-async-await-on-asp-net
4. Eugene D. Gubenkov, Stephen Cleary. Does asynchronous model really give benefits in throughput against properly configured synchronous? URL: https://stackoverflow.com/questions/55823184/does-asynchronous-model-really-give-benefits-in-throughput-against-properly-conf