Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

High availability for Python's asyncio

I am trying to create an asynchronous application using Python's asyncio module. However, all implementations I can find on the documentation is based on a single Event Loop.

Is there any way to launch multiple Event Loops running the same application, so I can achieve high availability and fault tolerance? In other words, I want to scale-out my application by inserting new nodes that would share the execution of coroutines behind a load balancer.

I understand there is an inherent issue between asynchronous programming and thread-safety, perhaps what I have in mind isn't even possible. If so, how to avoid this kind of SPOF on asynchronous architectures?

like image 532
Renato Siqueira Massaro Avatar asked Mar 25 '15 09:03

Renato Siqueira Massaro


People also ask

Is Asyncio in standard Python library?

The asyncio module is part of the Python standard library since Python 3.4. asyncio is a free software distributed under the Apache license version 2.0.

What version of Python has Asyncio?

Installation. asyncio requires Python 3.3 or later! The asyncio module is part of the Python standard library since Python 3.4.

What is the use of Asyncio in Python?

asyncio is used as a foundation for multiple Python asynchronous frameworks that provide high-performance network and web-servers, database connection libraries, distributed task queues, etc. asyncio is often a perfect fit for IO-bound and high-level structured network code.

Is Asyncio built in Python?

Asyncio is a built-in library of Python to write concurrent code using async/await syntax. This library provides high-performance network and web servers, database connection libraries, distributed task queues, etc., for asynchronous programming.


1 Answers

The standard way to deal with this is by starting multiple server processes (each with its own event loop), with a load balancer in front. Each such process typically cannot utilize more than one CPU core, so you might want to have as many processes as you have cores.

like image 87
nikow Avatar answered Nov 03 '22 20:11

nikow