Skip to main content

A wrapper for running your Python web application using Twisted in a way that works well for Kubernetes.

Project description

# Kubernetes_WSGI

A wrapper for running your Python web application using Twisted in a way that works well for Kubernetes.

This also includes Prometheus metrics support.

## Quick Start

To install:

` pip install kubernetes-wsgi `

To launch your application:

` python -m kubernetes_wsgi myapp 8000 `

where myapp is an importable module name containing your WSGI application function.

## Why Threads?

The gold standard for Python WSGI servers is Gunicorn, renowned for its multi-process execution mode for effcient concurrency despite the dreaded Python GIL (Global Interpreter Lock). Unfortunately when working with containers, multi-process worker models can be difficult to work with as containers generally expect to only have a single process. Specifically this means if one of the forked workers is hit by an OOM and killed, the main process will simply restart it without triggering the usual metrics in Kubernetes for OOM’d Pods. Similarly we have a different way to handle multi-process concurrency in Kubernetes, through a Deployment with many replicas. In the simplest version would could use multiple replicas each handling only one request at a time, but using a thread pool improves throughput by taking advantage of the fact that most web applications are blocked on I/O most of the time (usually waiting for a response from a database or another web service).

## Why Twisted?

Gunicorn itself does have a threadpool mode, however it’s somewhat awkward to work with as it uses the futures ThreadPool implementation. Twisted’s ThreadPool is more efficent. This also allows installing the Prometheus metrics as a native Twisted web handler so it will work even if the threadpool is exhausted, meaning your metrics keep working even during a system overload.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

kubernetes_wsgi-1.1.tar.gz (11.1 kB view details)

Uploaded Source

Built Distribution

kubernetes_wsgi-1.1-py3-none-any.whl (9.3 kB view details)

Uploaded Python 3

File details

Details for the file kubernetes_wsgi-1.1.tar.gz.

File metadata

  • Download URL: kubernetes_wsgi-1.1.tar.gz
  • Upload date:
  • Size: 11.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.6

File hashes

Hashes for kubernetes_wsgi-1.1.tar.gz
Algorithm Hash digest
SHA256 42250080f4655e344bef972b92673e4638ea1c058eff121a7fe39527535391a0
MD5 a648175629c3c33c00e40b40b4c03351
BLAKE2b-256 4b26232b1051a61f7ceacb5e1427dcd2048d0920e4e7fa3d511edf58064ecff2

See more details on using hashes here.

File details

Details for the file kubernetes_wsgi-1.1-py3-none-any.whl.

File metadata

  • Download URL: kubernetes_wsgi-1.1-py3-none-any.whl
  • Upload date:
  • Size: 9.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.6

File hashes

Hashes for kubernetes_wsgi-1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d436fcea30fd74b29776f39757c6b03c507c0989da38913de4e8487e208c88be
MD5 6434cfbdca0f40fc812f84dfe415adc8
BLAKE2b-256 35b39f8f2819f8beb34ed367e6b030d5519b4b7f1c34ad45ebfccf7e7cd87cc9

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page