Merge "Recycle stale SQL connections" into feature/zuulv3

This commit is contained in:
Zuul 2017-08-16 14:44:37 +00:00 committed by Gerrit Code Review
commit a851200165
1 changed files with 9 additions and 1 deletions

View File

@ -17,6 +17,7 @@ import logging
import alembic import alembic
import alembic.config import alembic.config
import sqlalchemy as sa import sqlalchemy as sa
import sqlalchemy.pool
import voluptuous as v import voluptuous as v
from zuul.connection import BaseConnection from zuul.connection import BaseConnection
@ -40,7 +41,14 @@ class SQLConnection(BaseConnection):
self.tables_established = False self.tables_established = False
try: try:
self.dburi = self.connection_config.get('dburi') self.dburi = self.connection_config.get('dburi')
self.engine = sa.create_engine(self.dburi) # Recycle connections if they've been idle for more than 1 second.
# MySQL connections are lightweight and thus keeping long-lived
# connections around is not valuable.
# TODO(mordred) Add a config paramter
self.engine = sa.create_engine(
self.dburi,
poolclass=sqlalchemy.pool.QueuePool,
pool_recycle=1)
self._migrate() self._migrate()
self._setup_tables() self._setup_tables()
self.zuul_buildset_table, self.zuul_build_table \ self.zuul_buildset_table, self.zuul_build_table \