diff --git a/etc/quantum/plugins/bigswitch/restproxy.ini b/etc/quantum/plugins/bigswitch/restproxy.ini index bb8524306c..957179795b 100644 --- a/etc/quantum/plugins/bigswitch/restproxy.ini +++ b/etc/quantum/plugins/bigswitch/restproxy.ini @@ -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]' diff --git a/etc/quantum/plugins/linuxbridge/linuxbridge_conf.ini b/etc/quantum/plugins/linuxbridge/linuxbridge_conf.ini index 37ad07c853..6b0bf58c44 100644 --- a/etc/quantum/plugins/linuxbridge/linuxbridge_conf.ini +++ b/etc/quantum/plugins/linuxbridge/linuxbridge_conf.ini @@ -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 diff --git a/etc/quantum/plugins/metaplugin/metaplugin.ini b/etc/quantum/plugins/metaplugin/metaplugin.ini index 5a8a65123f..bd5770fd96 100644 --- a/etc/quantum/plugins/metaplugin/metaplugin.ini +++ b/etc/quantum/plugins/metaplugin/metaplugin.ini @@ -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 diff --git a/etc/quantum/plugins/nec/nec.ini b/etc/quantum/plugins/nec/nec.ini index 9dc9f6cdc6..3de76e1159 100644 --- a/etc/quantum/plugins/nec/nec.ini +++ b/etc/quantum/plugins/nec/nec.ini @@ -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. diff --git a/etc/quantum/plugins/nicira/nvp.ini b/etc/quantum/plugins/nicira/nvp.ini index bf4cdb3287..506f486f96 100644 --- a/etc/quantum/plugins/nicira/nvp.ini +++ b/etc/quantum/plugins/nicira/nvp.ini @@ -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 diff --git a/etc/quantum/plugins/openvswitch/ovs_quantum_plugin.ini b/etc/quantum/plugins/openvswitch/ovs_quantum_plugin.ini index f8956a1c76..9b96f3f03a 100644 --- a/etc/quantum/plugins/openvswitch/ovs_quantum_plugin.ini +++ b/etc/quantum/plugins/openvswitch/ovs_quantum_plugin.ini @@ -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 diff --git a/etc/quantum/plugins/ryu/ryu.ini b/etc/quantum/plugins/ryu/ryu.ini index 34f6725ba6..2094ccb252 100644 --- a/etc/quantum/plugins/ryu/ryu.ini +++ b/etc/quantum/plugins/ryu/ryu.ini @@ -3,6 +3,15 @@ # Example: sql_connection = mysql://root:nova@127.0.0.1:3306/ryu_quantum #sql_connection = mysql://:@:/ 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 diff --git a/quantum/api/v2/base.py b/quantum/api/v2/base.py index 0b65b9a52d..7d0a9fc853 100644 --- a/quantum/api/v2/base.py +++ b/quantum/api/v2/base.py @@ -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""" diff --git a/quantum/db/api.py b/quantum/db/api.py index caba1a7200..a9e860a05d 100644 --- a/quantum/db/api.py +++ b/quantum/db/api.py @@ -19,6 +19,12 @@ 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) diff --git a/quantum/db/db_base_plugin_v2.py b/quantum/db/db_base_plugin_v2.py index c2608f634d..7538207e96 100644 --- a/quantum/db/db_base_plugin_v2.py +++ b/quantum/db/db_base_plugin_v2.py @@ -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): diff --git a/quantum/plugins/bigswitch/plugin.py b/quantum/plugins/bigswitch/plugin.py index 9d2593cb34..e7099acf68 100644 --- a/quantum/plugins/bigswitch/plugin.py +++ b/quantum/plugins/bigswitch/plugin.py @@ -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 diff --git a/quantum/plugins/linuxbridge/common/config.py b/quantum/plugins/linuxbridge/common/config.py index 45e86fa224..6abc2c353c 100644 --- a/quantum/plugins/linuxbridge/common/config.py +++ b/quantum/plugins/linuxbridge/common/config.py @@ -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 = [ diff --git a/quantum/plugins/linuxbridge/db/l2network_db_v2.py b/quantum/plugins/linuxbridge/db/l2network_db_v2.py index 354147f5aa..1c42c71dcd 100644 --- a/quantum/plugins/linuxbridge/db/l2network_db_v2.py +++ b/quantum/plugins/linuxbridge/db/l2network_db_v2.py @@ -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) diff --git a/quantum/plugins/metaplugin/common/config.py b/quantum/plugins/metaplugin/common/config.py index 9d212bcc40..1835ec2ff6 100644 --- a/quantum/plugins/metaplugin/common/config.py +++ b/quantum/plugins/metaplugin/common/config.py @@ -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 = [ diff --git a/quantum/plugins/metaplugin/meta_quantum_plugin.py b/quantum/plugins/metaplugin/meta_quantum_plugin.py index 1d3b4839fe..27029962fa 100644 --- a/quantum/plugins/metaplugin/meta_quantum_plugin.py +++ b/quantum/plugins/metaplugin/meta_quantum_plugin.py @@ -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'] diff --git a/quantum/plugins/nec/common/config.py b/quantum/plugins/nec/common/config.py index 925e8bf4be..52507b8dd0 100644 --- a/quantum/plugins/nec/common/config.py +++ b/quantum/plugins/nec/common/config.py @@ -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 = [ diff --git a/quantum/plugins/nec/db/api.py b/quantum/plugins/nec/db/api.py index b74e77dd40..17e741c661 100644 --- a/quantum/plugins/nec/db/api.py +++ b/quantum/plugins/nec/db/api.py @@ -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 diff --git a/quantum/plugins/nicira/nicira_nvp_plugin/QuantumPlugin.py b/quantum/plugins/nicira/nicira_nvp_plugin/QuantumPlugin.py index 7c53ca7c93..5dd8563256 100644 --- a/quantum/plugins/nicira/nicira_nvp_plugin/QuantumPlugin.py +++ b/quantum/plugins/nicira/nicira_nvp_plugin/QuantumPlugin.py @@ -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': diff --git a/quantum/plugins/nicira/nicira_nvp_plugin/common/config.py b/quantum/plugins/nicira/nicira_nvp_plugin/common/config.py index c9875dffae..d4a88875a1 100644 --- a/quantum/plugins/nicira/nicira_nvp_plugin/common/config.py +++ b/quantum/plugins/nicira/nicira_nvp_plugin/common/config.py @@ -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 = [ diff --git a/quantum/plugins/openvswitch/common/config.py b/quantum/plugins/openvswitch/common/config.py index 0a1af1dcca..13548c9948 100644 --- a/quantum/plugins/openvswitch/common/config.py +++ b/quantum/plugins/openvswitch/common/config.py @@ -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 = [ diff --git a/quantum/plugins/openvswitch/ovs_db_v2.py b/quantum/plugins/openvswitch/ovs_db_v2.py index 68a617b41e..dc004650f6 100644 --- a/quantum/plugins/openvswitch/ovs_db_v2.py +++ b/quantum/plugins/openvswitch/ovs_db_v2.py @@ -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) diff --git a/quantum/plugins/ryu/common/config.py b/quantum/plugins/ryu/common/config.py index 5020ac6053..1ef53d2de0 100644 --- a/quantum/plugins/ryu/common/config.py +++ b/quantum/plugins/ryu/common/config.py @@ -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 = [ diff --git a/quantum/plugins/ryu/ryu_quantum_plugin.py b/quantum/plugins/ryu/ryu_quantum_plugin.py index f3a6742267..1a11957ab6 100644 --- a/quantum/plugins/ryu/ryu_quantum_plugin.py +++ b/quantum/plugins/ryu/ryu_quantum_plugin.py @@ -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(