A Log Writing Demonstration
Explore how Python manages log writing in a concurrent environment by running a compute-intensive client application. Understand how multiple workers perform inefficient sorting while maintaining responsive logging. Learn the practical use of threads, multiprocessing, and limitations of AsyncIO for compute-bound workloads through a detailed demonstration.
We'll cover the following...
Overview
To demonstrate how this log catching works, this client application writes a bunch of messages and does an immense amount of computing. To see how responsive the log catcher is, we can start a bunch of copies of this application to stress-test the log catcher.
This client doesn’t leverage asyncio; it’s a contrived example of compute-intensive work with a few I/O requests wrapped around it. Using coroutines to perform the I/O requests concurrently with the computation is—by design—unhelpful in this example.
Example
We’ve written an application that applies a variation on the bogosort algorithm to some random data. This isn’t a practical algorithm, but it’s simple: it enumerates all possible orderings, searching for one that is the desired, ascending order. Here are the imports and an abstract superclass, ...