Page MenuHomePhabricator

Use persistent database connections from web contexts
ClosedPublic

Authored by epriestley on Sep 20 2016, 2:34 PM.
Tags
None
Referenced Files
Unknown Object (File)
Fri, Apr 12, 10:48 AM
Unknown Object (File)
Thu, Apr 11, 3:29 PM
Unknown Object (File)
Mon, Apr 8, 2:57 AM
Unknown Object (File)
Sat, Mar 30, 2:42 AM
Unknown Object (File)
Mar 2 2024, 1:48 AM
Unknown Object (File)
Feb 16 2024, 2:54 PM
Unknown Object (File)
Feb 3 2024, 11:59 AM
Unknown Object (File)
Feb 2 2024, 5:43 PM
Subscribers
None

Details

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).

Diff Detail

Repository
rP Phabricator
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

epriestley retitled this revision from to Use persistent database connections from web contexts.
epriestley updated this object.
epriestley edited the test plan for this revision. (Show Details)
epriestley added a reviewer: chad.
chad edited edge metadata.
This revision is now accepted and ready to land.Sep 20 2016, 2:43 PM
This revision was automatically updated to reflect the committed changes.