浏览代码

[HUE-5959] Enable Persistent connections using CONN_MAX_AGE

Enable CONN_MAX_AGE parameter. Django does not offer connection pooling or
singleton object for database connection pool. Also Django opens
a connection to the database when it first makes a database query.
It keeps this connection open and reuses it in subsequent requests.
Django closes the connection once it exceeds the maximum age defined by
CONN_MAX_AGE or when it isn’t usable any longer.
Till now HUE Django code was not using CONN_MAX_AGE configuration value.
By default CONN_MAX_AGE value is 600 seconds but anyone can change.

Tested:
Perform testing on Oracle, MySQL and SQLite.

(cherry picked from commit a1f9f60419ba2cc8540338dcafd7a619af807135)
Prakash Ranade 8 年之前
父节点
当前提交
7ad8d11abe

+ 3 - 0
desktop/conf.dist/hue.ini

@@ -561,6 +561,9 @@
     ## port=
     ## user=
     ## password=
+    # conn_max_age option to make database connection persistent value in seconds
+    # https://docs.djangoproject.com/en/1.9/ref/databases/#persistent-connections
+    ## conn_max_age=0
     # Execute this script to produce the database password. This will be used when 'password' is not set.
     ## password_script=/path/script
     ## name=desktop/desktop.db

+ 3 - 0
desktop/conf/pseudo-distributed.ini.tmpl

@@ -565,6 +565,9 @@
     ## port=
     ## user=
     ## password=
+    # conn_max_age option to make database connection persistent value in seconds
+    # https://docs.djangoproject.com/en/1.9/ref/databases/#persistent-connections
+    ## conn_max_age=0
     # Execute this script to produce the database password. This will be used when 'password' is not set.
     ## password_script=/path/script
     ## name=desktop/desktop.db

+ 6 - 0
desktop/core/src/desktop/conf.py

@@ -637,6 +637,12 @@ DATABASE = ConfigSection(
       help=_('Database options to send to the server when connecting.'),
       type=coerce_json_dict,
       dynamic_default=default_database_options
+    ),
+    CONN_MAX_AGE=Config(
+      key='conn_max_age',
+      help=_('The CONN_MAX_AGE parameter controls db connections persistency in seconds.'),
+      type=coerce_positive_integer,
+      default=0,
     )
   )
 )

+ 1 - 0
desktop/core/src/desktop/settings.py

@@ -331,6 +331,7 @@ else:
     "TEST_USER" : test_user,
     # Wrap each request in a transaction.
     "ATOMIC_REQUESTS" : True,
+    "CONN_MAX_AGE" : desktop.conf.DATABASE.CONN_MAX_AGE.get(),
   }
 
 DATABASES = {