Today in the deployment of Python code to the pre-production environment, the Web site is always the Redis link is not initialized, unable to connect to the service prompt, compared to the development environment and test environment code, exactly the same, and then look at the various logs, troubleshooting for half a day and did not find out what caused the cause.
There is no way to directly log on to the server, from Uwsgi and Nginx uninstall the Web service, and then the brute force under the command operator input Python main.py, perform access discovery and normal ... Mad Blood Vomit 400CC ... Then is a variety of suspected uwsgi and Nginx, view configuration and other services are normal, after elimination can only return to the check code.
Calm down to see the optimized code, found that in order to maintain a redis only a long link, when the Web service main program starts the Redis module is initialized, in the code with the Redis link is set to a static global variable, Redis link only need to initial
#initializing Redis Cache linksR =NonedefSet_redis_config (_redis):"""setting Redis configuration parameters:p Aram _redis:redis configuration Parameters""" GlobalR#initializing Redis Cache links Try: if notR:r= Redis. Redis (Host=_redis.get ('Server',"'), Port=_redis.get ('Post',"'), Db=_redis.get ('DB',"'), Password=_redis.get ('pwd',"'), Socket_timeout=1, Socket_connect_timeout=1) Log_helper.info ('initializing Redis Cache links') except: Pass
Then change the initialization code place, put in the hook, again enable UWSGI and Nginx service, run finally normal.
Find a friend asked to know that the original Uwsgi is a multi-process service, listen to the heart is more worried, will not because of the multi-process relationship to the global failure, resulting in a long chain after the transformation of the Redis service crashes, immediately use JMeter to carry out a pressure test, pressure 300 concurrent run for a period of time, Connect to the Redis service enter the client List command, view the linked lists of clients, find a few, open the log found that in high concurrency, initialization code does not do much, that is, using UWSGI, although the use of the Redis long link needs to be created frequently, But global still played a role and did not produce very bad results.
Since Redis is often re-creating links, fearing that it will affect performance so one of the interfaces is transformed, one uses Redis to read the data, the other reads the PostgreSQL database directly, and then accesses the two interfaces repeatedly by manually refreshing the page to see how long the interface log takes , when the refresh is slow, the use of Redis means more time, and access is very frequent, repeated calls to a long link more opportunities, less impact, two ways to access the same effect.
Of course, compared to a development environment that does not use UWSGI and a test environment, Redis often creates new links that consume some overhead and affect some of the performance. Not yet think of a good solution, first record, and then have time to try to test the results in other ways.
Copyright Notice:
This article by Allempty original and published in the blog Park, welcome reprint, without my consent must retain this paragraph statement, and in the article page obvious location to the original link, otherwise reserves the right to pursue legal responsibility . If you have any questions, you can contact me by [email protected] , thank you very much.
published this part of the content, the Lord is to work together with everyone to learn common progress, interested friends can gaga Q Group: 327360708, we discuss together.
For more information, please note the blog:http://www.cnblogs.com/EmptyFS/
PYTHON+UWSGI results in a performance degradation record caused by redis not having long links