How to fine-tune your server’s performance¶

In the Divio Cloud Control Panel for your project, you can easily change the resources (instances,RAM, storage, transfer) allocated to your project to adjust for its needs.

In most cases, having chosen suitable values for these, you won’t need to make further changes.

If however your project has unusual demands or sees unusual traffic, you can also fine-tune somesettings to match its needs even better.

Optimising the settings for a high-traffic site isn’t just a case of allocating more resourcesindiscriminately on the basis that “more is better”.

For example, a site that sees large numbers of requests that each represent a low load willbenefit from being allowed to serve more concurrent requests, but that could make things worse fora site that sees a smaller number of requests each representing a heavier load.

Monitoring and profiling¶

Our Control Panel’s metrics will give you a basic idea of RAM usage. However, there are moresophisticated tools available that can give you much more, and more finely-grained, information.

These range from Python libraries (such as memory-profiler or line_profiler) to third-party monitoring/profiling services.

Aldryn Django settings¶

The Aldryn Django addon is responsible for ensuring that uWSGI (theapplication gateway server) starts up with appropriate parameters.

These parameters can be controlled by environment variables.

Note

These environment variables represent uWSGI run-time options. It’s also possible to configureother uWSGI settings, but we don’t recommend doing so unless youare familiar with them already and understand their implications.

Increase DJANGO_WEB_WORKERS¶

The default number of uWSGI web workers (which determines the number of concurrent web processes)per instance is three (note that your plan may include multiple instances).

Increasing the number of web workers will allow you to serve more concurrent requests. Note thatthis will increase the RAM consumption of each instance, so make sure you monitor the results overtime (briefly exceeding your hosting plan’s RAM limits will not matter, but if this is sustained,you will need to upgrade to a higher plan).

You are likely to find that you can safely double the number of web workers. You are unlikely tosee any benefit from lowering it below the default.

Increase or decrease DJANGO_WEB_MAX_REQUESTS¶

If you see more RAM use than expected, try lowering DJANGO_WEB_MAX_REQUESTS. This controls thenumber of requests each worker serves before it is recycled (replaced by a fresh one).

There is a small overhead in replacing the worker. Typically - unless you are seeing excessive RAMusage - increasing this number can improve performance. A value of 3000 is a reasonablestarting-point for experimenting with different values.

Lowering this number can help when requests are memory-hungry, because recycling the workerreleases the RAM.

Decrease DJANGO_WEB_TIMEOUT¶

The default allowable lifetime of a web process is 120 seconds. After this period, the workerhandling it will be recycled.

You can lower this, if you know that no request served by your site should expect to take longerunder normal circumstances. It means that the process that is slow or held up will be dropped,but will allow the site to try again, or serve other requests.

Taking this as low as 10 seconds may have benefits with no adverse effects. If your siteoccasionally needs to serve views that entail long processes (for example, applying a filter on ahuge admin list) then you will need to adjust it upwards appropriately.

原文: http://docs.divio.com/en/latest/how-to/fine-tune-server-performance.html