1 Getting to know asyncio
This chapter covers
- What asyncio is and the benefits it provides
- Concurrency, parallelism, threads and processes
- The global interpreter lock and the challenges it poses to concurrency
- How non-blocking sockets can achieve concurrency with only one thread
- The basics around how event-loop based concurrency works
Many applications especially in today’s world of web applications rely heavily on I/O operations. These types of operations include downloading the contents of a webpage from the internet, communicating over a network with a group of microservices, or running several queries together against a database such as MySQL or Postgres. A web request or communication with a microservice may take hundreds of milliseconds, or even seconds if the network is slow. A database query could be expensive especially if that database is under high load or the query is complex. A web server may need to handle hundreds if not thousands of requests at the same time. These operations can be expensive in terms of time.