Subsections

15. Deploying your website for production

So there you are, with a nice big website you've spent weeks working on. And it's finally ready for the world to use it !

But you still have to decide how you will deploy it, which means: how will you set it up on the production machine(s).

15.1 Choosing you deployment configuration

When you are developing your website, you're usually the only one (maybe with a few other developers) accessing the website, so it doesn't need to be fast and robust. But on the production website, many people (if you're lucky) will access your website. This means that you have to choose the proper CherryPy configuration in order to provide a fast/reliable service to your users.

Criteria to help you choose your configuration include:

Note that there is a HowTo called "Sample deployment configuration for a real-world website" that shows a full sample configuration that is recommended for most websites.

15.1.1 Should I use the CherryPy HTTP server directly or behind another webserver like Apache ?

The first decision to make is whether to use the CherryPy HTTP server directly or behind another webserver like Apache. Here is a list of advantages for each method:

15.1.1.1 Use it directly

15.1.1.2 Use it behind Apache

Once you've decided if you wanted to use CherryPy directly or behind another webserver, you still have to decide among several configurations...

15.1.2 Options for deploying CherryPy directly

The following subsections show you what the different options are and what the advantages/drawbacks are:

15.1.2.1 Single thread/process

Explaination: This means that the CherryPy HTTP server will run in one single thread/process. While it is handling a request, no other request can connect to it during that time.

Advantages:

Drawbacks: Conclusion: This method is the default configuration and it works fine for development, but it should be banned for production if you might have several users accessing your website at the same time.

15.1.2.2 Forking server

Explaination: This means that the CherryPy HTTP server will create a new process to handle each request. After the response is sent back, the process is destroyed.

Advantages:

Drawbacks: Conclusion: This method can be used on non-Windows machines if the website's traffic isn't too high.

15.1.2.3 Threading server

Explaination: This means that the CherryPy HTTP server will create a new thread to handle each request. After the response is sent back, the thread is destroyed.

Advantages:

Drawbacks: Conclusion: This method can be used if the website's traffic isn't too high.

15.1.2.4 Process pool

Explaination: This means that the CherryPy HTTP server will create a fixed number of processes at startup, and these processes will remain all the time. If one process if busy handling a request and another request comes in, then the next process will step up and handle it.

Advantages:

Drawbacks: Conclusion: This method works well on non-Windows machines, as long as you don't have hundreds of concurrent users.

15.1.2.5 Thread pool

Explaination: This means that the CherryPy HTTP server will create a fixed number of threads at startup, and these threads will remain all the time. If one thread if busy handling a request and another request comes in, then the next thread will step up and handle it.

Advantages:

Drawbacks: Conclusion: This method works very well and it is the recommended set-up in many cases (as long as you don't have hundreds of concurrent users).

15.1.2.6 Other alternatives

If you really have a lot of traffic and the previous methods are not enough or you can not use them (if you're on Windows for instance), then you can use generic load-balancing. There is a HowTo in the documentation about it.

15.1.3 Options for deploying CherryPy behind another webserver

All the configurations described in the previous section are also available when deploying CherryPy behind another webserver. The third-party webserver will generally be multi-threaded or multi-processes. There is a HowTo in the documentation that explains how to set this up.

15.2 Configuration file options

Here is the list of the configuration file options that are used to specify how the CherryPy server will be deployed. All these options are used within the [server] section of the configuration file (cf Chapter "Configuring CherryPy").

Some of these options obviously cannot be used together because they conflict:

See About this document... for information on suggesting changes.