Homec4science

Use persistent database connections from web contexts

Authored by epriestley <git@epriestley.com> on Sep 20 2016, 16:30.

Description

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:

$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

Details

Committed
epriestley <git@epriestley.com>Sep 21 2016, 23:46
Pushed
aubortJan 31 2017, 17:16
Parents
rPH0817eb14a94b: Update Phurl to use EditEngine
Branches
Unknown
Tags
Unknown

Event Timeline

epriestley <git@epriestley.com> committed rPHf8c22252686e: Use persistent database connections from web contexts (authored by epriestley <git@epriestley.com>).Sep 21 2016, 23:46