Wednesday, May 27, 2015

Asynchronous Python in Web Applications

Asynchronous or non-blocking IO allows worker to process other requests before current request has finished. That is possible in case a processing of current web request is related to an operation that is IO bound.

Prerequisites

What is important to understand about applicability of async pattern for IO bound operations, they must:
  1. Utilize the same event loop, in this case worker's event loop can switch to next in the queue (otherwise it is blocked).
  2. Have long latency (otherwise you are wasting event loop queue for short requests).
If operation is not IO bound it is considered blocking.