Uwsgi + Flask + MongoDB encounters those pits

Source: Internet
Author: User
Tags mongodb mongodb client

1.MongoDB after the introduction of read and write separation, restart service time is longer, you can see the following printing:
Your mercy for graceful operations on workers are seconds
Search related data discovery can reduce the service restart time by setting the maximum timeout time, uwsgi default reload time-out is 60s, can be changed by setting Worker-reload-mercy, let's take a look at Uwsgi Official document Description:
Reload-mercy
Argument:required_argument

Parser:uwsgi_opt_set_int

Help:set the maximum time (in seconds) we wait for workers and other processes to die during Reload/shutdown

Worker-reload-mercy
Argument:required_argument

Parser:uwsgi_opt_set_int

Help:set the maximum time (in seconds) a worker can take to Reload/shutdown (default is 60)
Reload-mercy is the timeout that controls the entire UWSGI instance
Worker-reload-mercy is a timeout that controls a single worker
So add the UWSGI boot configuration file:
Worker-reload-mercy = 1
Although the service restart time has been shortened, some workers will not be able to boot when the service is deployed, or the process will be dead as the worker cannot restart over time. Later through the analysis of UWSGI configuration parameters, find Lazy-apps This parameter, look at the Official document description:
Lazy-apps

Argument:no_argument

Parser:uwsgi_opt_true

Help:load apps in each worker instead of the master
When loading apps, each worker is responsible for loading, not the Master fork, and after adding this parameter, the service restart time is gone, the service can be restarted quickly, and the worker will not die. So far also did not understand the specific why, have a clear classmate tell a sound.

2.MongoDB replica set when the official document description only needs to fill in a MongoDB instance address, but the actual measurement found that there is a problem, if the completed MongoDB instance is not available, restart the service at this time, the service can not connect to the MONGODB replication cluster, therefore, Recommended to connect the replication cluster, write a few MongoDB instance address, as far as possible to write the whole, so that even if there is an instance is not available, but also through other instances to get the entire cluster of information

Note: MongoDB client is using the pymongo2.7 version

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.