]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Add eventlet db_pool use for mysql
authorGary Kotton <gkotton@redhat.com>
Mon, 10 Dec 2012 12:39:22 +0000 (12:39 +0000)
committerGary Kotton <gkotton@redhat.com>
Sun, 23 Dec 2012 10:35:44 +0000 (10:35 +0000)
This adds the use of eventlet's db_pool module so that we can make mysql
calls without blocking the whole process.
New config options are introduced:

sql_dbpool_enable -- Enables the use of eventlet's db_pool
sql_min_pool_size -- Set the minimum number of SQL connections
sql_max_pool_size -- Set the maximum number of SQL connections
sql_idle_timeout  -- Timeout before idle sql connections are reaped

The default for sql_dbpool_enable is False for now, so there is
no forced behavior changes for those using mysql. sql_min_pool_size
is defaulted to 1 to match behavior if not using db_pool.

Fixes bug 1086173

Change-Id: Ied0aae33211585743fe955028a75c4e192a15d2f

23 files changed:
etc/quantum/plugins/bigswitch/restproxy.ini
etc/quantum/plugins/linuxbridge/linuxbridge_conf.ini
etc/quantum/plugins/metaplugin/metaplugin.ini
etc/quantum/plugins/nec/nec.ini
etc/quantum/plugins/nicira/nvp.ini
etc/quantum/plugins/openvswitch/ovs_quantum_plugin.ini
etc/quantum/plugins/ryu/ryu.ini
quantum/api/v2/base.py
quantum/db/api.py
quantum/db/db_base_plugin_v2.py
quantum/plugins/bigswitch/plugin.py
quantum/plugins/linuxbridge/common/config.py
quantum/plugins/linuxbridge/db/l2network_db_v2.py
quantum/plugins/metaplugin/common/config.py
quantum/plugins/metaplugin/meta_quantum_plugin.py
quantum/plugins/nec/common/config.py
quantum/plugins/nec/db/api.py
quantum/plugins/nicira/nicira_nvp_plugin/QuantumPlugin.py
quantum/plugins/nicira/nicira_nvp_plugin/common/config.py
quantum/plugins/openvswitch/common/config.py
quantum/plugins/openvswitch/ovs_db_v2.py
quantum/plugins/ryu/common/config.py
quantum/plugins/ryu/ryu_quantum_plugin.py

index bb8524306c2726e214dc672b79cc9b1b397bba53..957179795b2eb8a514ab7cec19b2dba999916414 100644 (file)
@@ -10,8 +10,18 @@ sql_connection = sqlite://
 # Database reconnection retry times - in event connectivity is lost
 # set to -1 implies an infinite retry count
 # sql_max_retries = 10
-# Database reconnection interval in seconds - in event connectivity is lost
+# Database reconnection interval in seconds - if the initial connection to the
+# database fails
 reconnect_interval = 2
+# Enable the use of eventlet's db_pool for MySQL. The flags sql_min_pool_size,
+# sql_max_pool_size and sql_idle_timeout are relevant only if this is enabled.
+# sql_dbpool_enable = False
+# Minimum number of SQL connections to keep open in a pool
+# sql_min_pool_size = 1
+# Maximum number of SQL connections to keep open in a pool
+# sql_max_pool_size = 5
+# Timeout in seconds before idle sql connections are reaped
+# sql_idle_timeout = 3600
 
 [RESTPROXY]
 # All configuration for this plugin is in section '[restproxy]'
index 37ad07c8537684b7a8a1ce4d3103f6ed4b704b24..6b0bf58c44f17c56cc5fb1fa318a17f38b2c11b2 100644 (file)
@@ -30,8 +30,18 @@ sql_connection = sqlite://
 # Database reconnection retry times - in event connectivity is lost
 # set to -1 implies an infinite retry count
 # sql_max_retries = 10
-# Database reconnection interval in seconds - in event connectivity is lost
+# Database reconnection interval in seconds - if the initial connection to the
+# database fails
 reconnect_interval = 2
+# Enable the use of eventlet's db_pool for MySQL. The flags sql_min_pool_size,
+# sql_max_pool_size and sql_idle_timeout are relevant only if this is enabled.
+# sql_dbpool_enable = False
+# Minimum number of SQL connections to keep open in a pool
+# sql_min_pool_size = 1
+# Maximum number of SQL connections to keep open in a pool
+# sql_max_pool_size = 5
+# Timeout in seconds before idle sql connections are reaped
+# sql_idle_timeout = 3600
 
 [LINUX_BRIDGE]
 # (ListOpt) Comma-separated list of
index 5a8a65123f6d3700ecc32dba47019515596f2839..bd5770fd9619e6593b4f28b5d0d485d4b00484e3 100644 (file)
@@ -9,9 +9,20 @@ sql_connection = mysql://root:password@localhost/quantum_metaplugin?charset=utf8
 # Database reconnection retry times - in event connectivity is lost
 # set to -1 implgies an infinite retry count
 # sql_max_retries = 10
-# Database reconnection interval in seconds - in event connectivity is lost
+# Database reconnection interval in seconds - if the initial connection to the
+# database fails
 reconnect_interval = 2
 
+# Enable the use of eventlet's db_pool for MySQL. The flags sql_min_pool_size,
+# sql_max_pool_size and sql_idle_timeout are relevant only if this is enabled.
+# sql_dbpool_enable = False
+# Minimum number of SQL connections to keep open in a pool
+# sql_min_pool_size = 1
+# Maximum number of SQL connections to keep open in a pool
+# sql_max_pool_size = 5
+# Timeout in seconds before idle sql connections are reaped
+# sql_idle_timeout = 3600
+
 [META]
 ## This is list of flavor:quantum_plugins
 # extension method is used in the order of this list
index 9dc9f6cdc67de2f5c51368072063bb775fa5cba8..3de76e11594c648d78b71756068bfe1c3ee6b7d9 100644 (file)
@@ -10,8 +10,18 @@ sql_connection = sqlite://
 # Database reconnection retry times - in event connectivity is lost
 # set to -1 implies an infinite retry count
 # sql_max_retries = 10
-# Database reconnection interval in seconds - in event connectivity is lost
+# Database reconnection interval in seconds - if the initial connection to the
+# database fails
 reconnect_interval = 2
+# Enable the use of eventlet's db_pool for MySQL. The flags sql_min_pool_size,
+# sql_max_pool_size and sql_idle_timeout are relevant only if this is enabled.
+# sql_dbpool_enable = False
+# Minimum number of SQL connections to keep open in a pool
+# sql_min_pool_size = 1
+# Maximum number of SQL connections to keep open in a pool
+# sql_max_pool_size = 5
+# Timeout in seconds before idle sql connections are reaped
+# sql_idle_timeout = 3600
 
 [OVS]
 # Do not change this parameter unless you have a good reason to.
index bf4cdb328753bad5de028b0e2968a18b211bc5c7..506f486f965abe8df591720cfa2f3e1e2e67ec25 100644 (file)
@@ -10,8 +10,18 @@ sql_connection = sqlite://
 # Database reconnection retry times - in event connectivity is lost
 # set to -1 implies an infinite retry count
 # sql_max_retries = 10
-# Database reconnection interval in seconds - in event connectivity is lost
+# Database reconnection interval in seconds - if the initial connection to the
+# database fails
 reconnect_interval = 2
+# Enable the use of eventlet's db_pool for MySQL. The flags sql_min_pool_size,
+# sql_max_pool_size and sql_idle_timeout are relevant only if this is enabled.
+# sql_dbpool_enable = False
+# Minimum number of SQL connections to keep open in a pool
+# sql_min_pool_size = 1
+# Maximum number of SQL connections to keep open in a pool
+# sql_max_pool_size = 5
+# Timeout in seconds before idle sql connections are reaped
+# sql_idle_timeout = 3600
 
 [NVP]
 # The number of logical ports to create per bridged logical switch
index f8956a1c7645e7ef56318b6d0a47469be58ae236..9b96f3f03abcbc34a7068d6eaf2cd82bbddc3f1e 100644 (file)
@@ -8,8 +8,18 @@ sql_connection = sqlite://
 # Database reconnection retry times - in event connectivity is lost
 # set to -1 implies an infinite retry count
 # sql_max_retries = 10
-# Database reconnection interval in seconds - in event connectivity is lost
+# Database reconnection interval in seconds - if the initial connection to the
+# database fails
 reconnect_interval = 2
+# Enable the use of eventlet's db_pool for MySQL. The flags sql_min_pool_size,
+# sql_max_pool_size and sql_idle_timeout are relevant only if this is enabled.
+# sql_dbpool_enable = False
+# Minimum number of SQL connections to keep open in a pool
+# sql_min_pool_size = 1
+# Maximum number of SQL connections to keep open in a pool
+# sql_max_pool_size = 5
+# Timeout in seconds before idle sql connections are reaped
+# sql_idle_timeout = 3600
 
 [OVS]
 # (StrOpt) Type of network to allocate for tenant networks. The
index 34f6725ba6d8593352a303f828d852af9e4aa28e..2094ccb2521e22bc6059cccb7b8408681867a59b 100644 (file)
@@ -3,6 +3,15 @@
 # Example: sql_connection = mysql://root:nova@127.0.0.1:3306/ryu_quantum
 #sql_connection = mysql://<user>:<pass>@<IP>:<port>/<dbname>
 sql_connection = sqlite://
+# Enable the use of eventlet's db_pool for MySQL. The flags sql_min_pool_size,
+# sql_max_pool_size and sql_idle_timeout are relevant only if this is enabled.
+# sql_dbpool_enable = False
+# Minimum number of SQL connections to keep open in a pool
+# sql_min_pool_size = 1
+# Maximum number of SQL connections to keep open in a pool
+# sql_max_pool_size = 5
+# Timeout in seconds before idle sql connections are reaped
+# sql_idle_timeout = 3600
 
 [OVS]
 integration_bridge = br-int
index 0b65b9a52d29218979a29242bc2b292d155aa564..7d0a9fc85328c1dc6ad5069afa7cc2c512f01ec4 100644 (file)
@@ -274,7 +274,7 @@ class Controller(object):
             # plugin raised might have been created or not in the db.
             # We need a way for ensuring that if it has been created,
             # it is then deleted
-            raise
+            raise ex
 
     def create(self, request, body=None, **kwargs):
         """Creates a new instance of the requested entity"""
index caba1a72002f419a03d7d703781b96f9ed86f2f2..a9e860a05d7fd6061a952ba9f8faeb6825284c73 100644 (file)
 
 import time
 
+from eventlet import db_pool
+from eventlet import greenthread
+try:
+    import MySQLdb
+except ImportError:
+    MySQLdb = None
 import sqlalchemy as sql
 from sqlalchemy import create_engine
 from sqlalchemy.exc import DisconnectionError
@@ -87,10 +93,31 @@ def configure_db(options):
 
         if 'mysql' in connection_dict.drivername:
             engine_args['listeners'] = [MySQLPingListener()]
+            if (MySQLdb is not None and
+                options['sql_dbpool_enable']):
+                pool_args = {
+                    'db': connection_dict.database,
+                    'passwd': connection_dict.password or '',
+                    'host': connection_dict.host,
+                    'user': connection_dict.username,
+                    'min_size': options['sql_min_pool_size'],
+                    'max_size': options['sql_max_pool_size'],
+                    'max_idle': options['sql_idle_timeout']
+                }
+                creator = db_pool.ConnectionPool(MySQLdb, **pool_args)
+                engine_args['creator'] = creator.create
+            if (MySQLdb is None and options['sql_dbpool_enable']):
+                LOG.warn(_("Eventlet connection pooling will not work without "
+                           "python-mysqldb!"))
         if 'sqlite' in connection_dict.drivername:
             engine_args['listeners'] = [SqliteForeignKeysListener()]
+            if options['sql_connection'] == "sqlite://":
+                engine_args["connect_args"] = {'check_same_thread': False}
 
         _ENGINE = create_engine(options['sql_connection'], **engine_args)
+
+        sql.event.listen(_ENGINE, 'checkin', greenthread_yield)
+
         base = options.get('base', BASE)
         if not register_models(base):
             if 'reconnect_interval' in options:
@@ -156,3 +183,13 @@ def unregister_models(base=BASE):
     global _ENGINE
     assert _ENGINE
     base.metadata.drop_all(_ENGINE)
+
+
+def greenthread_yield(dbapi_con, con_record):
+    """
+    Ensure other greenthreads get a chance to execute by forcing a context
+    switch. With common database backends (eg MySQLdb and sqlite), there is
+    no implicit yield caused by network I/O since they are implemented by
+    C libraries that eventlet cannot monkey patch.
+    """
+    greenthread.sleep(0)
index c2608f634d1e13161fbb82979d64ee81f5c64e07..7538207e96b8953ea3ab67e17343280a04e7c111 100644 (file)
@@ -910,11 +910,11 @@ class QuantumDbPluginV2(quantum_plugin_base_v2.QuantumPluginBaseV2):
                 obj_creator = getattr(self, 'create_%s' % resource)
                 objects.append(obj_creator(context, item))
             context.session.commit()
-        except Exception:
+        except Exception as e:
             LOG.exception(_("An exception occured while creating "
                             "the %(resource)s:%(item)s"), locals())
             context.session.rollback()
-            raise
+            raise e
         return objects
 
     def create_network_bulk(self, context, networks):
index 9d2593cb340dd02278d9555f10faffa6811af822..e7099acf68ca5232e22e6c08217b695fe37f1c57 100644 (file)
@@ -70,6 +70,21 @@ database_opts = [
     cfg.StrOpt('sql_connection', default='sqlite://'),
     cfg.IntOpt('sql_max_retries', default=-1),
     cfg.IntOpt('reconnect_interval', default=2),
+    cfg.IntOpt('sql_min_pool_size',
+               default=1,
+               help="Minimum number of SQL connections to keep open in a "
+                    "pool"),
+    cfg.IntOpt('sql_max_pool_size',
+               default=5,
+               help="Maximum number of SQL connections to keep open in a "
+                    "pool"),
+    cfg.IntOpt('sql_idle_timeout',
+               default=3600,
+               help="Timeout in seconds before idle sql connections are "
+                    "reaped"),
+    cfg.BoolOpt('sql_dbpool_enable',
+                default=False,
+                help="Enable the use of eventlet's db_pool for MySQL"),
 ]
 
 
@@ -265,7 +280,11 @@ class QuantumRestProxyV2(db_base_plugin_v2.QuantumDbPluginV2):
         options = {"sql_connection": "%s" % cfg.CONF.DATABASE.sql_connection,
                    "sql_max_retries": cfg.CONF.DATABASE.sql_max_retries,
                    "reconnect_interval": cfg.CONF.DATABASE.reconnect_interval,
-                   "base": models_v2.model_base.BASEV2}
+                   "base": models_v2.model_base.BASEV2,
+                   "sql_min_pool_size": cfg.CONF.DATABASE.sql_min_pool_size,
+                   "sql_max_pool_size": cfg.CONF.DATABASE.sql_max_pool_size,
+                   "sql_idle_timeout": cfg.CONF.DATABASE.sql_idle_timeout,
+                   "sql_dbpool_enable": cfg.CONF.DATABASE.sql_dbpool_enable}
         db.configure_db(options)
 
         # 'servers' is the list of network controller REST end-points
index 45e86fa224054a06e4288221cb847f82a4760263..6abc2c353c5702b6f5e89740629ff0351312555e 100644 (file)
@@ -37,6 +37,21 @@ database_opts = [
     cfg.StrOpt('sql_connection', default='sqlite://'),
     cfg.IntOpt('sql_max_retries', default=-1),
     cfg.IntOpt('reconnect_interval', default=2),
+    cfg.IntOpt('sql_min_pool_size',
+               default=1,
+               help="Minimum number of SQL connections to keep open in a "
+                    "pool"),
+    cfg.IntOpt('sql_max_pool_size',
+               default=5,
+               help="Maximum number of SQL connections to keep open in a "
+                    "pool"),
+    cfg.IntOpt('sql_idle_timeout',
+               default=3600,
+               help="Timeout in seconds before idle sql connections are "
+                    "reaped"),
+    cfg.BoolOpt('sql_dbpool_enable',
+                default=False,
+                help="Enable the use of eventlet's db_pool for MySQL"),
 ]
 
 bridge_opts = [
index 354147f5aab58b94b984d7057934f5528510c778..1c42c71dcd0b4dfc26300ce8edbd4fdb16d6b80f 100644 (file)
@@ -29,11 +29,16 @@ LOG = logging.getLogger(__name__)
 
 
 def initialize():
-    options = {"sql_connection": "%s" % cfg.CONF.DATABASE.sql_connection}
-    options.update({"sql_max_retries": cfg.CONF.DATABASE.sql_max_retries})
-    options.update({"reconnect_interval":
-                   cfg.CONF.DATABASE.reconnect_interval})
-    options.update({"base": models_v2.model_base.BASEV2})
+    options = {
+        "sql_connection": cfg.CONF.DATABASE.sql_connection,
+        "sql_max_retries": cfg.CONF.DATABASE.sql_max_retries,
+        "reconnect_interval": cfg.CONF.DATABASE.reconnect_interval,
+        "base": models_v2.model_base.BASEV2,
+        "sql_min_pool_size": cfg.CONF.DATABASE.sql_min_pool_size,
+        "sql_max_pool_size": cfg.CONF.DATABASE.sql_max_pool_size,
+        "sql_idle_timeout": cfg.CONF.DATABASE.sql_idle_timeout,
+        "sql_dbpool_enable": cfg.CONF.DATABASE.sql_dbpool_enable
+    }
     db.configure_db(options)
 
 
index 9d212bcc405cf499531e3beb9c2357cf50b1a2f8..1835ec2ff69e52abd97cba7d0db3b399d7877c3f 100644 (file)
@@ -22,6 +22,21 @@ database_opts = [
     cfg.StrOpt('sql_connection', default='sqlite://'),
     cfg.IntOpt('sql_max_retries', default=-1),
     cfg.IntOpt('reconnect_interval', default=2),
+    cfg.IntOpt('sql_min_pool_size',
+               default=1,
+               help="Minimum number of SQL connections to keep open in a "
+                    "pool"),
+    cfg.IntOpt('sql_max_pool_size',
+               default=5,
+               help="Maximum number of SQL connections to keep open in a "
+                    "pool"),
+    cfg.IntOpt('sql_idle_timeout',
+               default=3600,
+               help="Timeout in seconds before idle sql connections are "
+                    "reaped"),
+    cfg.BoolOpt('sql_dbpool_enable',
+                default=False,
+                help="Enable the use of eventlet's db_pool for MySQL"),
 ]
 
 meta_plugin_opts = [
index 1d3b4839fec597bcec60c3282f0fa0e3f4bc200a..27029962fa4657890004d95ca0d76098219e2a79 100644 (file)
@@ -50,12 +50,16 @@ class MetaPluginV2(db_base_plugin_v2.QuantumDbPluginV2,
 
     def __init__(self, configfile=None):
         LOG.debug(_("Start initializing metaplugin"))
-        options = {"sql_connection": cfg.CONF.DATABASE.sql_connection}
-        options.update({'base': models_v2.model_base.BASEV2})
-        sql_max_retries = cfg.CONF.DATABASE.sql_max_retries
-        options.update({"sql_max_retries": sql_max_retries})
-        reconnect_interval = cfg.CONF.DATABASE.reconnect_interval
-        options.update({"reconnect_interval": reconnect_interval})
+        options = {
+            "sql_connection": "%s" % cfg.CONF.DATABASE.sql_connection,
+            "sql_max_retries": cfg.CONF.DATABASE.sql_max_retries,
+            "reconnect_interval": cfg.CONF.DATABASE.reconnect_interval,
+            "base": models_v2.model_base.BASEV2,
+            "sql_min_pool_size": cfg.CONF.DATABASE.sql_min_pool_size,
+            "sql_max_pool_size": cfg.CONF.DATABASE.sql_max_pool_size,
+            "sql_idle_timeout": cfg.CONF.DATABASE.sql_idle_timeout,
+            "sql_dbpool_enable": cfg.CONF.DATABASE.sql_dbpool_enable
+        }
         self.supported_extension_aliases = \
             cfg.CONF.META.supported_extension_aliases.split(',')
         self.supported_extension_aliases += ['flavor', 'router']
index 925e8bf4be6d0e03a6810901436735a2a29eac52..52507b8dd0f0d0ac7983aa5d41a4b18b101f3927 100644 (file)
@@ -24,6 +24,21 @@ database_opts = [
     cfg.StrOpt('sql_connection', default='sqlite://'),
     cfg.IntOpt('sql_max_retries', default=-1),
     cfg.IntOpt('reconnect_interval', default=2),
+    cfg.IntOpt('sql_min_pool_size',
+               default=1,
+               help="Minimum number of SQL connections to keep open in a "
+                    "pool"),
+    cfg.IntOpt('sql_max_pool_size',
+               default=5,
+               help="Maximum number of SQL connections to keep open in a "
+                    "pool"),
+    cfg.IntOpt('sql_idle_timeout',
+               default=3600,
+               help="Timeout in seconds before idle sql connections are "
+                    "reaped"),
+    cfg.BoolOpt('sql_dbpool_enable',
+                default=False,
+                help="Enable the use of eventlet's db_pool for MySQL"),
 ]
 
 ovs_opts = [
index b74e77dd408d9a6ecdbd73074fd60b77f07e40fb..17e741c661c2d952a125b90e88fc6099e61fa113 100644 (file)
@@ -33,7 +33,11 @@ def initialize():
     options = {"sql_connection": "%s" % config.DATABASE.sql_connection,
                "sql_max_retries": config.DATABASE.sql_max_retries,
                "reconnect_interval": config.DATABASE.reconnect_interval,
-               "base": model_base.BASEV2}
+               "base": model_base.BASEV2,
+               "sql_min_pool_size": config.CONF.DATABASE.sql_min_pool_size,
+               "sql_max_pool_size": config.CONF.DATABASE.sql_max_pool_size,
+               "sql_idle_timeout": config.CONF.DATABASE.sql_idle_timeout,
+               "sql_dbpool_enable": config.CONF.DATABASE.sql_dbpool_enable}
     db.configure_db(options)
 
 
@@ -67,7 +71,7 @@ def add_ofc_item(model, id, quantum_id):
         item = model(id=id, quantum_id=quantum_id)
         session.add(item)
         session.flush()
-    except sa.exc.IntegrityError as exc:
+    except Exception as exc:
         LOG.exception(exc)
         raise nexc.NECDBException
     return item
@@ -103,7 +107,7 @@ def add_portinfo(id, datapath_id='', port_no=0, vlan_id=OFP_VLAN_NONE, mac=''):
                                     port_no=port_no, vlan_id=vlan_id, mac=mac)
         session.add(portinfo)
         session.flush()
-    except sa.exc.IntegrityError as exc:
+    except Exception as exc:
         LOG.exception(exc)
         raise nexc.NECDBException
     return portinfo
index 7c53ca7c935c67d45c376c5584503d1fe036900c..5dd85632560da8f93a44932ad8024844f145b363 100644 (file)
@@ -67,12 +67,16 @@ def parse_config():
         NVPCluster objects, 'plugin_config' is a dictionary with plugin
         parameters (currently only 'max_lp_per_bridged_ls').
     """
-    db_options = {"sql_connection": cfg.CONF.DATABASE.sql_connection}
-    db_options.update({'base': models_v2.model_base.BASEV2})
-    sql_max_retries = cfg.CONF.DATABASE.sql_max_retries
-    db_options.update({"sql_max_retries": sql_max_retries})
-    reconnect_interval = cfg.CONF.DATABASE.reconnect_interval
-    db_options.update({"reconnect_interval": reconnect_interval})
+    db_options = {
+        "sql_connection": "%s" % cfg.CONF.DATABASE.sql_connection,
+        "sql_max_retries": cfg.CONF.DATABASE.sql_max_retries,
+        "reconnect_interval": cfg.CONF.DATABASE.reconnect_interval,
+        "base": models_v2.model_base.BASEV2,
+        "sql_min_pool_size": cfg.CONF.DATABASE.sql_min_pool_size,
+        "sql_max_pool_size": cfg.CONF.DATABASE.sql_max_pool_size,
+        "sql_idle_timeout": cfg.CONF.DATABASE.sql_idle_timeout,
+        "sql_dbpool_enable": cfg.CONF.DATABASE.sql_dbpool_enable
+    }
     nvp_options = {'max_lp_per_bridged_ls': cfg.CONF.NVP.max_lp_per_bridged_ls}
     nvp_options.update({'failover_time': cfg.CONF.NVP.failover_time})
     nvp_options.update({'concurrent_connections':
index c9875dffae2b2db0b3f96d9c1c17a5365f7d1ea1..d4a88875a162794c1c8fa3fdf11df3aaf69b914d 100644 (file)
@@ -21,6 +21,21 @@ database_opts = [
     cfg.StrOpt('sql_connection', default='sqlite://'),
     cfg.IntOpt('sql_max_retries', default=-1),
     cfg.IntOpt('reconnect_interval', default=2),
+    cfg.IntOpt('sql_min_pool_size',
+               default=1,
+               help="Minimum number of SQL connections to keep open in a "
+                    "pool"),
+    cfg.IntOpt('sql_max_pool_size',
+               default=5,
+               help="Maximum number of SQL connections to keep open in a "
+                    "pool"),
+    cfg.IntOpt('sql_idle_timeout',
+               default=3600,
+               help="Timeout in seconds before idle sql connections are "
+                    "reaped"),
+    cfg.BoolOpt('sql_dbpool_enable',
+                default=False,
+                help="Enable the use of eventlet's db_pool for MySQL"),
 ]
 
 nvp_opts = [
index 0a1af1dcca4a28475786b3b2df64bcc432ff5299..13548c99485dbb787c2255a20db4dff41719cbcc 100644 (file)
@@ -25,6 +25,21 @@ database_opts = [
     cfg.StrOpt('sql_connection', default='sqlite://'),
     cfg.IntOpt('sql_max_retries', default=-1),
     cfg.IntOpt('reconnect_interval', default=2),
+    cfg.IntOpt('sql_min_pool_size',
+               default=1,
+               help="Minimum number of SQL connections to keep open in a "
+                    "pool"),
+    cfg.IntOpt('sql_max_pool_size',
+               default=5,
+               help="Maximum number of SQL connections to keep open in a "
+                    "pool"),
+    cfg.IntOpt('sql_idle_timeout',
+               default=3600,
+               help="Timeout in seconds before idle sql connections are "
+                    "reaped"),
+    cfg.BoolOpt('sql_dbpool_enable',
+                default=False,
+                help="Enable the use of eventlet's db_pool for MySQL"),
 ]
 
 ovs_opts = [
index 68a617b41e9da29c958f5f2d4de6e0926ad4b764..dc004650f662c3966f1ae08081799f232499ff1a 100644 (file)
@@ -30,11 +30,16 @@ LOG = logging.getLogger(__name__)
 
 
 def initialize():
-    options = {"sql_connection": "%s" % cfg.CONF.DATABASE.sql_connection}
-    options.update({"sql_max_retries": cfg.CONF.DATABASE.sql_max_retries})
-    options.update({"reconnect_interval":
-                   cfg.CONF.DATABASE.reconnect_interval})
-    options.update({"base": models_v2.model_base.BASEV2})
+    options = {
+        "sql_connection": cfg.CONF.DATABASE.sql_connection,
+        "sql_max_retries": cfg.CONF.DATABASE.sql_max_retries,
+        "reconnect_interval": cfg.CONF.DATABASE.reconnect_interval,
+        "base": models_v2.model_base.BASEV2,
+        "sql_min_pool_size": cfg.CONF.DATABASE.sql_min_pool_size,
+        "sql_max_pool_size": cfg.CONF.DATABASE.sql_max_pool_size,
+        "sql_idle_timeout": cfg.CONF.DATABASE.sql_idle_timeout,
+        "sql_dbpool_enable": cfg.CONF.DATABASE.sql_dbpool_enable
+    }
     db.configure_db(options)
 
 
index 5020ac6053fed3bc94da8d8b9ad4a2e1aeafdb6b..1ef53d2de07153dbe984de01253c7256b037eee4 100644 (file)
@@ -21,6 +21,21 @@ database_opts = [
     cfg.StrOpt('sql_connection', default='sqlite://'),
     cfg.IntOpt('sql_max_retries', default=-1),
     cfg.IntOpt('reconnect_interval', default=2),
+    cfg.IntOpt('sql_min_pool_size',
+               default=1,
+               help="Minimum number of SQL connections to keep open in a "
+                    "pool"),
+    cfg.IntOpt('sql_max_pool_size',
+               default=5,
+               help="Maximum number of SQL connections to keep open in a "
+                    "pool"),
+    cfg.IntOpt('sql_idle_timeout',
+               default=3600,
+               help="Timeout in seconds before idle sql connections are "
+                    "reaped"),
+    cfg.BoolOpt('sql_dbpool_enable',
+                default=False,
+                help="Enable the use of eventlet's db_pool for MySQL"),
 ]
 
 ovs_opts = [
index f3a6742267a621397a26e3ce9c4d5ea6c71f066b..1a11957ab6571ba7b7fdb7eafe1b9a7063f7fc88 100644 (file)
@@ -55,10 +55,16 @@ class RyuQuantumPluginV2(db_base_plugin_v2.QuantumDbPluginV2,
     supported_extension_aliases = ["router"]
 
     def __init__(self, configfile=None):
-        options = {"sql_connection": cfg.CONF.DATABASE.sql_connection}
-        options.update({'base': models_v2.model_base.BASEV2})
-        reconnect_interval = cfg.CONF.DATABASE.reconnect_interval
-        options.update({"reconnect_interval": reconnect_interval})
+        options = {
+            "sql_connection": "%s" % cfg.CONF.DATABASE.sql_connection,
+            "sql_max_retries": cfg.CONF.DATABASE.sql_max_retries,
+            "reconnect_interval": cfg.CONF.DATABASE.reconnect_interval,
+            "base": models_v2.model_base.BASEV2,
+            "sql_min_pool_size": cfg.CONF.DATABASE.sql_min_pool_size,
+            "sql_max_pool_size": cfg.CONF.DATABASE.sql_max_pool_size,
+            "sql_idle_timeout": cfg.CONF.DATABASE.sql_idle_timeout,
+            "sql_dbpool_enable": cfg.CONF.DATABASE.sql_dbpool_enable
+        }
         db.configure_db(options)
 
         self.tunnel_key = db_api_v2.TunnelKey(