1. 程式人生 > >django 短鏈接改成長連接

django 短鏈接改成長連接

應用 max _for ati and return python ict for

 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 短鏈接改成長連接