forked from npgsql/npgsql
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclass-connpool.html
More file actions
97 lines (61 loc) · 3.86 KB
/
class-connpool.html
File metadata and controls
97 lines (61 loc) · 3.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<html><head>
<title>Npgsql: Connector Pool Class</title>
<meta http-equiv="content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="content-Style-Type" content="text/css">
<meta http-equiv="expires" content="">
<meta name="category" content="IT/Database/PostgreSQL/Npgsql/Docs/Internal">
<meta name="filename" content="class-connpool.htm">
<meta name="date" content="2002-06-17">
<meta name="author" content="Ulrich Sprick">
<meta name="robots" content="nofollow">
<meta name="keywords" content="IT; Database; PostgreSQL; Npgsql; Communication; Documentation; Class; Connector Pool;">
<meta name="description" content="This document describes the connector pool class">
<link rel="stylesheet" href="global.css">
<script language="JavaScript" src="global.js"></script>
<!-- Table Layout Stylesheet -->
</style>
</head><body>
<h1 align=center>Npgsql: Connector Class</h1><hr>
<table width=100%>
<tr>
<td width=40% align=left>← <a href="dev-connpool-ovw.htm">Connector Pooling Overview</a></td>
<td width=20% align=center><a href="index.htm">Up</a></td>
<td width=40% align=right><a href="class-connector.htm">Connector</a> →</td>
</tr>
</table><hr>
<p> </p>
<p class=pgstats>Last update: 2002-06-21 19:00:00 by usp •
Category: Internal documentation •
Intended Audience: Npgsql Developers</p>
<p>This document describes the Npgsql Connector Pool class.</p>
<p>The connector pool manager is a unique, static instance of the Npgsql.ConnectionPool class named <em>ConnectionPoolMgr</em>. It controls requesting and release of connector objects and maintains internal lists of shared and pooled connectors.</p>
<h2>Interface</h2>
<p>The ConnectionPool class interface consist of the following method:</p>
<dl>
<dt><b>RequestConnection()</b></dt>
<dd>Returns a Connector object with an open physical connection and the Pooled property set.
<br />Parameters: Connection string, Shared flag.
</dd>
</dl>
<h2>Internal Structure</h2>
<p>There is not much to tell about the internal structure. The connector pool consist primarily of 2 lists: The pooled connectors, currently not in use by the application, and the shared connectors. Note that connectors in the shared connectors list are in use, referenced by one or more Connection objects and thus are not avaliable for requests <em>other than shared</em>. </p>
<img src="connection-pooling-1.png">
<h2>Under the Hood</h2>
<h3>Requesting a Connector</h3>
<table>
<tr style="vertical-align:top;">
<td></td>
<td><img style="float:right;" src="connection-pooling-3.png">
<p>The algorithm for requesting a connector is quit simple.</p>
<p>If a shared connector is requested the pool manager starts with searching the SharedConnectors list for a connector with a matching connect string.</p>
<p>If a suitable connector is found, its ShareCounter gets incremented to reflect the number of Connections working on this connector. Then the connector object is returned to the calling connection object.</p>
<p>If a non-shared connector is requested or a shared connector was not found, the pooled connectors are beeing searched for a suitable connector. If a connector was found, it is removed from the pooled connectors list.</p>
<p>If the search fails, then an new connector is created and the physical connection is opened instead.</p>
<p>For a non-shared connector the work is done now. A shared connector request is treated different at this point: It's Shared property is set, and the connector is inserted in the shared connectors list, before it is returned to the calling connection object.</p>
</td></tr></table>
<h3>See also</h3>
<p>Further insight into a connector object and its interaction with the connector pool manager gives the <a href="class-connector.htm">Connector</a> class documentation.</p>
<h3>The Code</h3>
<p>... can be inspected <a href="javascript:popUp('../src/npgsql/NpgsqlConnectorPool.cs')">here</a></p>
</body>
</html>