From f8c22252686e5f53cc0cae26d990eb89aef09f72 Mon Sep 17 00:00:00 2001 From: epriestley Date: Tue, 20 Sep 2016 07:30:42 -0700 Subject: [PATCH] Use persistent database connections from web contexts Summary: Ref T11672. Depends on D16577. When establishing a connection from a webserver context, try to use persistent connections. The hope is that this will fix outbound port exhaustion issues experienced on repository hosts handling large queue volumes. Test Plan: Added this to a page: ```lang=php $tables = array( new PhabricatorUser(), new ManiphestTask(), new DifferentialRevision(), new PhabricatorRepository(), new PhabricatorPaste(), ); $ids = array(); foreach ($tables as $table) { $conn = $table->establishConnection('r'); $cid = queryfx_one( $conn, 'SELECT CONNECTION_ID() cid'); $ids[get_class($table)] = $cid['cid']; } var_dump($ids); ``` Reloaded the page a bunch of times and saw no reissued connections (the pool seems to keep a particular connection bound to a particular database), but did see connection reuse across requests. That is, across reloads the same connection IDs appeared, but the same connection ID never appeared twice in the same request. This is what we want. Also googled for issues with persistent connections, but everything I found was unconcerning and obscure (local variables and other very complex state that we don't use), and a bunch of the docs are reassuring (transactions, etc., get reset properly). Reviewers: chad Reviewed By: chad Maniphest Tasks: T11672 Differential Revision: https://secure.phabricator.com/D16578 --- src/infrastructure/storage/lisk/PhabricatorLiskDAO.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/infrastructure/storage/lisk/PhabricatorLiskDAO.php b/src/infrastructure/storage/lisk/PhabricatorLiskDAO.php index 2fbabf037a..feae254095 100644 --- a/src/infrastructure/storage/lisk/PhabricatorLiskDAO.php +++ b/src/infrastructure/storage/lisk/PhabricatorLiskDAO.php @@ -75,10 +75,13 @@ abstract class PhabricatorLiskDAO extends LiskDAO { $connection->setReadOnly(true); } - // Unless this is a script running from the CLI, prevent any query from - // running for more than 30 seconds. See T10849 for discussion. + // Unless this is a script running from the CLI: + // - (T10849) Prevent any query from running for more than 30 seconds. + // - (T11672) Use persistent connections. if (php_sapi_name() != 'cli') { - $connection->setQueryTimeout(30); + $connection + ->setQueryTimeout(30) + ->setPersistent(true); } return $connection;