skip to Main Content

So we used to run our Pyramid server with Apache in production. But we are moving to Docker containerization for easier prod deployments etc, and we want to adhere to the philosophy of “one process per container”..so instead of running Apache in the container + 4 python procs, we just want 1 python proc.

So my question is – is there a way to run a Pyramid server in production directly? Without using WSGI+Apache?

https://www.digitalocean.com/community/tutorials/how-to-use-the-pyramid-framework-to-build-your-python-web-app-on-ubuntu

My understanding is that pserve is for development only?

Create an application.py file and fill it with the following contents:

from wsgiref.simple_server import make_server
from pyramid.config import Configurator
from pyramid.response import Response

def hello_world(request):
    return Response('<h1>Hello world!</h1>')

if __name__ == '__main__':
    config = Configurator()
    config.add_view(hello_world)
    app = config.make_wsgi_app()
    server = make_server('0.0.0.0', 8080, app)
    server.serve_forever()

Will the above work as a production-grade server?

3

Answers


  1. The latest official recommendation is one concern per container. From the Docker docs (emphasis my own):

    Each container should have only one concern. Decoupling applications
    into multiple containers makes it easier to scale horizontally and
    reuse containers. For instance, a web application stack might consist
    of three separate containers, each with its own unique image, to
    manage the web application, database, and an in-memory cache in a
    decoupled manner.

    Limiting each container to one process is a good rule of thumb, but it
    is not a hard and fast rule.
    For example, not only can containers be
    spawned with an init process, some programs might spawn additional
    processes of their own accord. For instance, Celery can spawn multiple
    worker processes, and Apache can create one process per request.

    In your case, your web application server is a single concern. Running Apache+WSGI is totally fine. Don’t worry about the processes—That’s Apache’s job.

    For a better understanding of the “one concern” rule, this post is a good overview of what problems its trying to solve.

    Login or Signup to reply.
  2. You can use Waitress, which, according to their documentation, is

    … meant to be a production-quality pure-Python WSGI server with very
    acceptable performance. It has no dependencies except ones which live
    in the Python standard library.

    Waitress is a part of the Pylons Project just like Pyramid is.

    Login or Signup to reply.
  3. It looks like Bjoern is a solid choice when it comes to running Python directly, where the Python server has WSGI bindings:

    https://www.appdynamics.com/blog/engineering/a-performance-analysis-of-python-wsgi-servers-part-2/

    https://github.com/jonashaag/bjoern

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search