码迷,mamicode.com
首页 > 其他好文 > 详细

django 短链接改成长连接

时间:2018-05-09 19:44:29      阅读:654      评论:0      收藏:0      [点我收藏+]

标签:max   bin   word   自带   线程   服务配置   back   unicorn   http服务   

 1 from django.conf import settings
 2 from django.core.wsgi import get_wsgi_application
 3 from gunicorn.app.base import Application
 4 # gunicorn 一个Python WSGI UNIX的HTTP服务器,按我的理解,它的作用可能就是用来代替django自带server的。
 5 # 有了它就不用自带的runserver了,自带的server只能单线程运行,而这个能并发多线程。
 6 
 7 class Server(Application):
 8     """
 9     服务器实现类
10     """
11 
12     def __init__(self, ready_hook=None, fork_hook=None):
13         """
14         初始化
15         """
16 
17         # 服务配置
18         self.config = dict(
19             worker_class="gthread",
20             worker_connections=5000,
21             backlog=2048,
22             threads=1,
23             daemon=True,
24             keyfile=settings.SERVER_SSL_KEY,
25             certfile=settings.SERVER_SSL_CERT,
26 
27             post_worker_init=ready_hook,
28             post_fork=fork_hook,
29 
30             user=settings.SERVER_USER,
31             group=settings.SERVER_GROUP,
32             bind=settings.SERVER_BIND,
33             workers=settings.SERVER_WORKERS,
34             pidfile=settings.SERVER_PID
35         )
36 
37         self.application = get_wsgi_application()
38 
39         super().__init__()
40 
41     def load_config(self):
42         """
43         加载配置
44         """
45         config = dict([(key, value) for key, value in self.config.items()
46                        if key in self.cfg.settings and value is not None])
47 
48         for key, value in config.items():
49             self.cfg.set(key.lower(), value)
50 
51     def load(self):
52         """
53         加载应用
54         """
55         return self.application
settings.py
DATABASES = {
    "default": {
        "ENGINE": "django.db.backends.mysql",
        "NAME": "",
        "USER": "",
        "PASSWORD": "",
        "HOST": "",
        "PORT": "",
        "CONN_MAX_AGE":3600
    }
}

参考:https://zhuanlan.zhihu.com/p/27467118

django 短链接改成长连接

标签:max   bin   word   自带   线程   服务配置   back   unicorn   http服务   

原文地址:https://www.cnblogs.com/morgana/p/9015667.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!