xref: /netbsd-src/external/ibm-public/postfix/dist/html/CONNECTION_CACHE_README.html (revision 627f7eb200a4419d89b531d55fccd2ee3ffdcde0)
1<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN"
2        "http://www.w3.org/TR/html4/loose.dtd">
3
4<html>
5
6<head>
7
8<title>Postfix Connection Cache </title>
9
10<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
11
12</head>
13
14<body>
15
16<h1><img src="postfix-logo.jpg" width="203" height="98" ALT="">Postfix Connection Cache </h1>
17
18<hr>
19
20<h2>Introduction</h2>
21
22<p> This document describes the Postfix connection cache implementation,
23which is available with Postfix version 2.2 and later. </p>
24
25<p> See <a href="TLS_README.html#client_tls_reuse">Client-side TLS
26connection reuse</a> for how this connection cache is used to
27implement multiple deliveries per TLS-encrypted connection. </p>
28
29<p> Topics covered in this document: </p>
30
31<ul>
32
33<li><a href="#summary"> What SMTP connection caching can do for you</a>
34
35<li><a href="#implementation"> Connection cache implementation</a>
36
37<li><a href="#configuration"> Connection cache configuration</a>
38
39<li><a href="#safety">Connection cache safety mechanisms </a>
40
41<li><a href="#limitations">Connection cache limitations</a>
42
43<li><a href="#statistics">Connection cache statistics</a>
44
45</ul>
46
47<h2><a name="summary">What SMTP connection caching can do for
48you</a></h2>
49
50<p> With SMTP connection caching, Postfix can deliver multiple
51messages over the same SMTP connection. By default, Postfix 2.2
52reuses an SMTP connection automatically when a destination has
53high volume of mail in the <a href="QSHAPE_README.html#active_queue">active queue</a>.  </p>
54
55<p> SMTP Connection caching is a performance feature. Whether or not
56it actually improves performance depends on the conditions: </p>
57
58<ul>
59
60<li> <p> SMTP Connection caching can greatly improve performance
61when delivering mail to a destination with multiple mail servers,
62because it can help Postfix to skip over a non-responding server.
63</p>
64
65<li> <p> Otherwise, the benefits of SMTP connection caching are
66minor: it eliminates the latency of the TCP handshake (SYN, SYN+ACK,
67ACK), plus the latency of the SMTP initial handshake (220 greeting,
68EHLO command, EHLO response).
69
70<li> <p> SMTP Connection caching gives no gains with respect to
71SMTP session tear-down.  The Postfix <a href="smtp.8.html">smtp(8)</a> client normally does
72not wait for the server's reply to the QUIT command, and it never
73waits for the TCP final handshake to complete.  </p>
74
75<li> <p> SMTP Connection caching introduces some overhead: the
76client needs to send an RSET command to find out if a connection
77is still usable, before it can send the next MAIL FROM command.
78This introduces one additional round-trip delay. </p>
79
80</ul>
81
82<p> For other potential issues with SMTP connection caching, see
83the discussion of <a href="#limitations">limitations</a> at the end
84of this document. </p>
85
86<h2><a name="implementation">Connection cache implementation</a></h2>
87
88<p> For an overview of how Postfix delivers mail, see the Postfix
89architecture <a href="OVERVIEW.html">OVERVIEW</a> document. </p>
90
91<p> The Postfix connection cache is shared among Postfix mail
92delivering processes.  This maximizes the opportunity to reuse an
93open connection.  Other MTAs such as Sendmail or exim have a
94non-shared connection cache. Here, a connection can be reused only
95by the mail delivering process that creates the connection.  To get
96the same performance improvement as with a shared connection cache,
97non-shared connections need to be kept open for a longer time. </p>
98
99<p> The <a href="scache.8.html">scache(8)</a> server, introduced with Postfix version 2.2,
100maintains the shared connection cache.  With Postfix version 2.2,
101only the <a href="smtp.8.html">smtp(8)</a> client has support to access this cache.  </p>
102
103<blockquote>
104
105<table>
106
107<tr> <td> </td> <td> <tt> /-- </tt> </td> <td align="center"
108colspan="3" bgcolor="#f0f0ff"> <a href="smtp.8.html">smtp(8)</a> </td> <td colspan="2"> <tt>
109--&gt; </tt> Internet </td> </tr>
110
111<tr> <td align="center" bgcolor="#f0f0ff"> <a href="qmgr.8.html">qmgr(8)</a> </td> <td> </td>
112<td align="center" rowspan="3"> &nbsp; </td> <td align="center"
113rowspan="3"><tt>|<br>|<br>|<br>|<br>v</tt></td> <td> &nbsp; </td>
114</tr>
115
116<tr> <td> </td> <td> <tt> \-- </tt> </td> <td align="center"
117colspan="2" bgcolor="#f0f0ff"> <a href="smtp.8.html">smtp(8)</a> </td> <td align="left"> <tt>
118--&gt; </tt> Internet </td> </tr>
119
120<tr> <td colspan="3"> </td> <td align="center"><tt>^<br>|</tt></td>
121<td> &nbsp; </td> </tr>
122
123<tr> <td colspan="3"> </td> <td align="center" colspan="3"
124bgcolor="#f0f0ff"> <a href="scache.8.html">scache(8)</a> </td> </tr>
125
126</table>
127
128</blockquote>
129
130<p> When SMTP connection caching is enabled (see next section), the
131<a href="smtp.8.html">smtp(8)</a> client does not disconnect after a mail transaction, but
132gives the connection to the <a href="scache.8.html">scache(8)</a> server which keeps the
133connection open for a limited amount of time. </p>
134
135<p> After handing over the open connection to the <a href="scache.8.html">scache(8)</a> server,
136the <a href="smtp.8.html">smtp(8)</a> client continues with some other mail delivery request.
137Meanwhile, any <a href="smtp.8.html">smtp(8)</a> client process can ask the <a href="scache.8.html">scache(8)</a> server
138for that cached connection and reuse it for mail delivery.  </p>
139
140<p> The connection cache can be searched by destination domain name
141(the right-hand side of the recipient address) and by the IP address
142of the host at the other end of the connection. This allows Postfix
143to reuse a connection even when the remote host is mail server for
144domains with different names.  </p>
145
146<h2><a name="configuration">Connection cache configuration </a></h2>
147
148<p> The Postfix <a href="smtp.8.html">smtp(8)</a> client supports two connection caching
149strategies: </p>
150
151<ul>
152
153<li> <p> On-demand connection caching. This is enabled by default,
154and is controlled with the <a href="postconf.5.html#smtp_connection_cache_on_demand">smtp_connection_cache_on_demand</a> configuration
155parameter.  When this feature is enabled, the Postfix <a href="smtp.8.html">smtp(8)</a> client
156automatically saves a connection to the connection cache when a
157destination has a high volume of mail in the <a href="QSHAPE_README.html#active_queue">active queue</a>.  </p>
158
159<p> Example: </p>
160
161<blockquote>
162
163<pre>
164/etc/postfix/<a href="postconf.5.html">main.cf</a>:
165    <a href="postconf.5.html#smtp_connection_cache_on_demand">smtp_connection_cache_on_demand</a> = yes
166</pre>
167
168</blockquote>
169
170<li> <p> Per-destination connection caching. This is enabled by
171explicitly listing specific destinations with the
172<a href="postconf.5.html#smtp_connection_cache_destinations">smtp_connection_cache_destinations</a> configuration parameter. After
173completing delivery to a selected destination, the Postfix <a href="smtp.8.html">smtp(8)</a>
174client <i>always</i> saves the connection to the connection cache.
175</p>
176
177<p> Specify a comma or white space separated list of destinations
178or pseudo-destinations: </p>
179
180<ul>
181
182<li> <p> if mail is sent without a <a href="postconf.5.html#relayhost">relay host</a>: a domain name (the
183right-hand side of an email address, without the [] around a numeric
184IP address), </p>
185
186<li> <p> if mail is sent via a <a href="postconf.5.html#relayhost">relay host</a>: a <a href="postconf.5.html#relayhost">relay host</a> name (without
187the [] or non-default TCP port), as specified in <a href="postconf.5.html">main.cf</a> or in the
188transport map, </p>
189
190<li> <p> a /file/name with domain names and/or <a href="postconf.5.html#relayhost">relay host</a> names as
191defined above, </p>
192
193<li> <p> a "<a href="DATABASE_README.html">type:table</a>" with domain names and/or <a href="postconf.5.html#relayhost">relay host</a> names
194on the left-hand side. The right-hand side result from "<a href="DATABASE_README.html">type:table</a>"
195lookups is ignored.  </p>
196
197</ul>
198
199<p> Examples: </p>
200
201<blockquote>
202
203<pre>
204/etc/postfix/<a href="postconf.5.html">main.cf</a>:
205    <a href="postconf.5.html#smtp_connection_cache_destinations">smtp_connection_cache_destinations</a> = $<a href="postconf.5.html#relayhost">relayhost</a>
206    <a href="postconf.5.html#smtp_connection_cache_destinations">smtp_connection_cache_destinations</a> = hotmail.com, ...
207    <a href="postconf.5.html#smtp_connection_cache_destinations">smtp_connection_cache_destinations</a> = <a href="DATABASE_README.html#types">static</a>:all (<i>not recommended</i>)
208</pre>
209
210</blockquote>
211
212</ul>
213
214<h2><a name="safety">Connection cache safety mechanisms </a></h2>
215
216<p> Connection caching must be used wisely. It is anti-social to
217keep an unused SMTP connection open for a significant amount of
218time, and it is unwise to send huge numbers of messages through
219the same connection. In order to avoid problems with SMTP connection
220caching, Postfix implements the following safety mechanisms: </p>
221
222<ul>
223
224<li> <p> The Postfix <a href="scache.8.html">scache(8)</a> server keeps a connection open for
225only a limited time. The time limit is specified with the
226<a href="postconf.5.html#smtp_connection_cache_time_limit">smtp_connection_cache_time_limit</a> and with the <a href="postconf.5.html#connection_cache_ttl_limit">connection_cache_ttl_limit</a>
227configuration parameters. This prevents anti-social behavior. </p>
228
229<li> <p> The Postfix <a href="smtp.8.html">smtp(8)</a> client reuses a session for only a
230limited number of times. This avoids triggering bugs in implementations
231that do not correctly handle multiple deliveries per session. </p>
232
233<p> As of Postfix 2.3 connection reuse is preferably limited with
234the <a href="postconf.5.html#smtp_connection_reuse_time_limit">smtp_connection_reuse_time_limit</a> parameter. In addition, Postfix
2352.11 provides <a href="postconf.5.html#smtp_connection_reuse_count_limit">smtp_connection_reuse_count_limit</a> to limit how many
236times a connection may be reused, but this feature is unsafe as it
237introduces a "fatal attractor" failure mode (when a destination has
238multiple inbound MTAs, the slowest inbound MTA will attract most
239connections from Postfix to that destination). </p>
240
241<p> Postfix 2.3 logs the use count of multiply-used connections,
242as shown in the following example: </p>
243
244<blockquote>
245<pre>
246Nov  3 16:04:31 myname postfix/smtp[30840]: 19B6B2900FE:
247to=&lt;wietse@test.example.com&gt;, orig_to=&lt;wietse@test&gt;,
248relay=mail.example.com[1.2.3.4], <b>conn_use=2</b>, delay=0.22,
249delays=0.04/0.01/0.05/0.1, dsn=2.0.0, status=sent (250 2.0.0 Ok)
250</pre>
251</blockquote>
252
253<li> <p> The connection cache explicitly labels each cached connection
254with destination domain and IP address information.  A connection
255cache lookup succeeds only when the correct information is specified.
256This prevents mis-delivery of mail. </p>
257
258</ul>
259
260<h2><a name="limitations">Connection cache limitations</a></h2>
261
262<p> Postfix SMTP connection caching conflicts with certain applications:
263</p>
264
265<ul>
266
267<li> <p> With Postfix versions &lt; 3.4, the Postfix shared connection
268cache cannot be used with TLS, because an open TLS connection can
269be reused only in the process that creates it.  For this reason,
270the Postfix <a href="smtp.8.html">smtp(8)</a> client historically always closed the connection
271after completing an attempt to deliver mail over TLS.</p>
272
273<li> <p> Postfix connection caching currently does not support
274multiple SASL accounts per mail server.  Specifically, Postfix
275connection caching assumes that a SASL credential is valid for all
276hostnames or domain names that deliver via the same mail server IP
277address and TCP port, and assumes that the SASL credential does not
278depend on the message originator.  </p>
279
280</ul>
281
282
283<h2><a name="statistics">Connection cache statistics </a></h2>
284
285<p> The <a href="scache.8.html">scache(8)</a> connection cache server logs statistics about the
286peak cache size and the cache hit rates. This information is logged
287every <a href="postconf.5.html#connection_cache_status_update_time">connection_cache_status_update_time</a> seconds, when the process
288terminates after the maximal idle time is exceeded, or when Postfix
289is reloaded. </p>
290
291<ul>
292
293<li> <p> Hit rates for connection cache lookups by domain will tell
294you how useful connection caching is. </p>
295
296<li> <p> Connection cache lookups by network address will always
297fail, unless you're sending mail to different domains that share
298the same MX hosts. </p>
299
300<li> <p> No statistics are logged when no attempts are made to
301access the connection cache. </p>
302
303</ul>
304
305
306</body>
307
308</html>
309