1 P
\bPo
\bos
\bst
\btf
\bfi
\bix
\bx B
\bBo
\bot
\btt
\btl
\ble
\ben
\bne
\bec
\bck
\bk A
\bAn
\bna
\bal
\bly
\bys
\bsi
\bis
\bs
3 -------------------------------------------------------------------------------
5 P
\bPu
\bur
\brp
\bpo
\bos
\bse
\be o
\bof
\bf t
\bth
\bhi
\bis
\bs d
\bdo
\boc
\bcu
\bum
\bme
\ben
\bnt
\bt
7 This document is an introduction to Postfix queue congestion analysis. It
8 explains how the qshape(1) program can help to track down the reason for queue
9 congestion. qshape(1) is bundled with Postfix 2.1 and later source code, under
10 the "auxiliary" directory. This document describes qshape(1) as bundled with
13 This document covers the following topics:
15 * Introducing the qshape tool
16 * Trouble shooting with qshape
17 * Example 1: Healthy queue
18 * Example 2: Deferred queue full of dictionary attack bounces
19 * Example 3: Congestion in the active queue
20 * Example 4: High volume destination backlog
21 * Postfix queue directories
23 o The "maildrop" queue
25 o The "incoming" queue
27 o The "deferred" queue
31 I
\bIn
\bnt
\btr
\bro
\bod
\bdu
\buc
\bci
\bin
\bng
\bg t
\bth
\bhe
\be q
\bqs
\bsh
\bha
\bap
\bpe
\be t
\bto
\boo
\bol
\bl
33 When mail is draining slowly or the queue is unexpectedly large, run qshape(1)
34 as the super-user (root) to help zero in on the problem. The qshape(1) program
35 displays a tabular view of the Postfix queue contents.
37 * On the horizontal axis, it displays the queue age with fine granularity for
38 recent messages and (geometrically) less fine granularity for older
41 * The vertical axis displays the destination (or with the "-s" switch the
42 sender) domain. Domains with the most messages are listed first.
44 For example, in the output below we see the top 10 lines of the (mostly forged)
45 sender domain distribution for captured spam in the "hold" queue:
47 $ qshape -s hold | head
48 T 5 10 20 40 80 160 320 640 1280 1280+
49 TOTAL 486 0 0 1 0 0 2 4 20 40 419
50 yahoo.com 14 0 0 1 0 0 0 0 1 0 12
51 extremepricecuts.net 13 0 0 0 0 0 0 0 2 0 11
52 ms35.hinet.net 12 0 0 0 0 0 0 0 0 1 11
53 winnersdaily.net 12 0 0 0 0 0 0 0 2 0 10
54 hotmail.com 11 0 0 0 0 0 0 0 0 1 10
55 worldnet.fr 6 0 0 0 0 0 0 0 0 0 6
56 ms41.hinet.net 6 0 0 0 0 0 0 0 0 0 6
57 osn.de 5 0 0 0 0 0 1 0 0 0 4
59 * The "T" column shows the total (in this case sender) count for each domain.
60 The columns with numbers above them, show counts for messages aged fewer
61 than that many minutes, but not younger than the age limit for the previous
62 column. The row labeled "TOTAL" shows the total count for all domains.
64 * In this example, there are 14 messages allegedly from yahoo.com, 1 between
65 10 and 20 minutes old, 1 between 320 and 640 minutes old and 12 older than
66 1280 minutes (1440 minutes in a day).
68 When the output is a terminal intermediate results showing the top 20 domains
69 (-n option) are displayed after every 1000 messages (-N option) and the final
70 output also shows only the top 20 domains. This makes qshape useful even when
71 the deferred queue is very large and it may otherwise take prohibitively long
72 to read the entire deferred queue.
74 By default, qshape shows statistics for the union of both the incoming and
75 active queues which are the most relevant queues to look at when analyzing
78 One can request an alternate list of queues:
81 $ qshape incoming active deferred
83 this will show the age distribution of the deferred queue or the union of the
84 incoming active and deferred queues.
86 Command line options control the number of display "buckets", the age limit for
87 the smallest bucket, display of parent domain counts and so on. The "-h" option
88 outputs a summary of the available switches.
90 T
\bTr
\bro
\bou
\bub
\bbl
\ble
\be s
\bsh
\bho
\boo
\bot
\bti
\bin
\bng
\bg w
\bwi
\bit
\bth
\bh q
\bqs
\bsh
\bha
\bap
\bpe
\be
92 Large numbers in the qshape output represent a large number of messages that
93 are destined to (or alleged to come from) a particular domain. It should be
94 possible to tell at a glance which domains dominate the queue sender or
95 recipient counts, approximately when a burst of mail started, and when it
98 The problem destinations or sender domains appear near the top left corner of
99 the output table. Remember that the active queue can accommodate up to 20000
100 ($qmgr_message_active_limit) messages. To check whether this limit has been
103 $ qshape -s active (show sender statistics)
105 If the total sender count is below 20000 the active queue is not yet saturated,
106 any high volume sender domains show near the top of the output.
108 With oqmgr(8) the active queue is also limited to at most 20000 recipient
109 addresses ($qmgr_message_recipient_limit). To check for exhaustion of this
112 $ qshape active (show recipient statistics)
114 Having found the high volume domains, it is often useful to search the logs for
115 recent messages pertaining to the domains in question.
117 # Find deliveries to example.com
119 $ tail -10000 /var/log/maillog |
120 egrep -i ': to=<.*@example\.com>,' |
123 # Find messages from example.com
125 $ tail -10000 /var/log/maillog |
126 egrep -i ': from=<.*@example\.com>,' |
129 You may want to drill in on some specific queue ids:
131 # Find all messages for a specific queue id.
133 $ tail -10000 /var/log/maillog | egrep ': 2B2173FF68: '
135 Also look for queue manager warning messages in the log. These warnings can
136 suggest strategies to reduce congestion.
138 $ egrep 'qmgr.*(panic|fatal|error|warning):' /var/log/maillog
140 When all else fails try the Postfix mailing list for help, but please don't
141 forget to include the top 10 or 20 lines of qshape(1) output.
143 E
\bEx
\bxa
\bam
\bmp
\bpl
\ble
\be 1
\b1:
\b: H
\bHe
\bea
\bal
\blt
\bth
\bhy
\by q
\bqu
\bue
\beu
\bue
\be
145 When looking at just the incoming and active queues, under normal conditions
146 (no congestion) the incoming and active queues are nearly empty. Mail leaves
147 the system almost as quickly as it comes in or is deferred without congestion
150 $ qshape (show incoming and active queue status)
152 T 5 10 20 40 80 160 320 640 1280 1280+
153 TOTAL 5 0 0 0 1 0 0 0 1 1 2
154 meri.uwasa.fi 5 0 0 0 1 0 0 0 1 1 2
156 If one looks at the two queues separately, the incoming queue is empty or
157 perhaps briefly has one or two messages, while the active queue holds more
158 messages and for a somewhat longer time:
162 T 5 10 20 40 80 160 320 640 1280 1280+
163 TOTAL 0 0 0 0 0 0 0 0 0 0 0
167 T 5 10 20 40 80 160 320 640 1280 1280+
168 TOTAL 5 0 0 0 1 0 0 0 1 1 2
169 meri.uwasa.fi 5 0 0 0 1 0 0 0 1 1 2
171 E
\bEx
\bxa
\bam
\bmp
\bpl
\ble
\be 2
\b2:
\b: D
\bDe
\bef
\bfe
\ber
\brr
\bre
\bed
\bd q
\bqu
\bue
\beu
\bue
\be f
\bfu
\bul
\bll
\bl o
\bof
\bf d
\bdi
\bic
\bct
\bti
\bio
\bon
\bna
\bar
\bry
\by a
\bat
\btt
\bta
\bac
\bck
\bk b
\bbo
\bou
\bun
\bnc
\bce
\bes
\bs
173 This is from a server where recipient validation is not yet available for some
174 of the hosted domains. Dictionary attacks on the unvalidated domains result in
175 bounce backscatter. The bounces dominate the queue, but with proper tuning they
176 do not saturate the incoming or active queues. The high volume of deferred mail
177 is not a direct cause for alarm.
179 $ qshape deferred | head
181 T 5 10 20 40 80 160 320 640 1280 1280+
182 TOTAL 2234 4 2 5 9 31 57 108 201 464 1353
183 heyhihellothere.com 207 0 0 1 1 6 6 8 25 68 92
184 pleazerzoneprod.com 105 0 0 0 0 0 0 0 5 44 56
185 groups.msn.com 63 2 1 2 4 4 14 14 14 8 0
186 orion.toppoint.de 49 0 0 0 1 0 2 4 3 16 23
187 kali.com.cn 46 0 0 0 0 1 0 2 6 12 25
188 meri.uwasa.fi 44 0 0 0 0 1 0 2 8 11 22
189 gjr.paknet.com.pk 43 1 0 0 1 1 3 3 6 12 16
190 aristotle.algonet.se 41 0 0 0 0 0 1 2 11 12 15
192 The domains shown are mostly bulk-mailers and all the volume is the tail end of
193 the time distribution, showing that short term arrival rates are moderate.
194 Larger numbers and lower message ages are more indicative of current trouble.
195 Old mail still going nowhere is largely harmless so long as the active and
196 incoming queues are short. We can also see that the groups.msn.com
197 undeliverables are low rate steady stream rather than a concentrated dictionary
198 attack that is now over.
200 $ qshape -s deferred | head
202 T 5 10 20 40 80 160 320 640 1280 1280+
203 TOTAL 2193 4 4 5 8 33 56 104 205 465 1309
204 MAILER-DAEMON 1709 4 4 5 8 33 55 101 198 452 849
205 example.com 263 0 0 0 0 0 0 0 0 2 261
206 example.org 209 0 0 0 0 0 1 3 6 11 188
207 example.net 6 0 0 0 0 0 0 0 0 0 6
208 example.edu 3 0 0 0 0 0 0 0 0 0 3
209 example.gov 2 0 0 0 0 0 0 0 1 0 1
210 example.mil 1 0 0 0 0 0 0 0 0 0 1
212 Looking at the sender distribution, we see that as expected most of the
213 messages are bounces.
215 E
\bEx
\bxa
\bam
\bmp
\bpl
\ble
\be 3
\b3:
\b: C
\bCo
\bon
\bng
\bge
\bes
\bst
\bti
\bio
\bon
\bn i
\bin
\bn t
\bth
\bhe
\be a
\bac
\bct
\bti
\biv
\bve
\be q
\bqu
\bue
\beu
\bue
\be
217 This example is taken from a Feb 2004 discussion on the Postfix Users list.
218 Congestion was reported with the active and incoming queues large and not
219 shrinking despite very large delivery agent process limits. The thread is
220 archived at: http://groups.google.com/groups?th=636626c645f5bbde
222 Using an older version of qshape(1) it was quickly determined that all the
223 messages were for just a few destinations:
225 $ qshape (show incoming and active queue status)
227 T A 5 10 20 40 80 160 320 320+
228 TOTAL 11775 9996 0 0 1 1 42 94 221 1420
229 user.sourceforge.net 7678 7678 0 0 0 0 0 0 0 0
230 lists.sourceforge.net 2313 2313 0 0 0 0 0 0 0 0
231 gzd.gotdns.com 102 0 0 0 0 0 0 0 2 100
233 The "A" column showed the count of messages in the active queue, and the
234 numbered columns showed totals for the deferred queue. At 10000 messages
235 (Postfix 1.x active queue size limit) the active queue is full. The incoming
238 With the trouble destinations clearly identified, the administrator quickly
239 found and fixed the problem. It is substantially harder to glean the same
240 information from the logs. While a careful reading of mailq(1) output should
241 yield similar results, it is much harder to gauge the magnitude of the problem
242 by looking at the queue one message at a time.
244 E
\bEx
\bxa
\bam
\bmp
\bpl
\ble
\be 4
\b4:
\b: H
\bHi
\big
\bgh
\bh v
\bvo
\bol
\blu
\bum
\bme
\be d
\bde
\bes
\bst
\bti
\bin
\bna
\bat
\bti
\bio
\bon
\bn b
\bba
\bac
\bck
\bkl
\blo
\bog
\bg
246 When a site you send a lot of email to is down or slow, mail messages will
247 rapidly build up in the deferred queue, or worse, in the active queue. The
248 qshape output will show large numbers for the destination domain in all age
249 buckets that overlap the starting time of the problem:
251 $ qshape deferred | head
253 T 5 10 20 40 80 160 320 640 1280 1280+
254 TOTAL 5000 200 200 400 800 1600 1000 200 200 200 200
255 highvolume.com 4000 160 160 320 640 1280 1440 0 0 0 0
258 Here the "highvolume.com" destination is continuing to accumulate deferred
259 mail. The incoming and active queues are fine, but the deferred queue started
260 growing some time between 1 and 2 hours ago and continues to grow.
262 If the high volume destination is not down, but is instead slow, one might see
263 similar congestion in the active queue. Active queue congestion is a greater
264 cause for alarm; one might need to take measures to ensure that the mail is
265 deferred instead or even add an access(5) rule asking the sender to try again
268 If a high volume destination exhibits frequent bursts of consecutive
269 connections refused by all MX hosts or "421 Server busy errors", it is possible
270 for the queue manager to mark the destination as "dead" despite the transient
271 nature of the errors. The destination will be retried again after the
272 expiration of a $minimal_backoff_time timer. If the error bursts are frequent
273 enough it may be that only a small quantity of email is delivered before the
274 destination is again marked "dead". In some cases enabling static (not on
275 demand) connection caching by listing the appropriate nexthop domain in a table
276 included in "smtp_connection_cache_destinations" may help to reduce the error
277 rate, because most messages will re-use existing connections.
279 The MTA that has been observed most frequently to exhibit such bursts of errors
280 is Microsoft Exchange, which refuses connections under load. Some proxy virus
281 scanners in front of the Exchange server propagate the refused connection to
282 the client as a "421" error.
284 Note that it is now possible to configure Postfix to exhibit similarly erratic
285 behavior by misconfiguring the anvil(8) service. Do not use anvil(8) for
286 steady-state rate limiting, its purpose is (unintentional) DoS prevention and
287 the rate limits set should be very generous!
289 If one finds oneself needing to deliver a high volume of mail to a destination
290 that exhibits frequent brief bursts of errors and connection caching does not
291 solve the problem, there is a subtle workaround.
293 * Postfix version 2.5 and later:
295 o In master.cf set up a dedicated clone of the "smtp" transport for the
296 destination in question. In the example below we will call it
299 o In master.cf configure a reasonable process limit for the cloned smtp
300 transport (a number in the 10-20 range is typical).
302 o IMPORTANT!!! In main.cf configure a large per-destination pseudo-cohort
303 failure limit for the cloned smtp transport.
305 /etc/postfix/main.cf:
306 transport_maps = hash:/etc/postfix/transport
307 fragile_destination_concurrency_failed_cohort_limit = 100
308 fragile_destination_concurrency_limit = 20
310 /etc/postfix/transport:
313 /etc/postfix/master.cf:
314 # service type private unpriv chroot wakeup maxproc command
315 fragile unix - - n - 20 smtp
317 See also the documentation for
318 default_destination_concurrency_failed_cohort_limit and
319 default_destination_concurrency_limit.
321 * Earlier Postfix versions:
323 o In master.cf set up a dedicated clone of the "smtp" transport for the
324 destination in question. In the example below we will call it
327 o In master.cf configure a reasonable process limit for the transport (a
328 number in the 10-20 range is typical).
330 o IMPORTANT!!! In main.cf configure a very large initial and destination
331 concurrency limit for this transport (say 2000).
333 /etc/postfix/main.cf:
334 transport_maps = hash:/etc/postfix/transport
335 initial_destination_concurrency = 2000
336 fragile_destination_concurrency_limit = 2000
338 /etc/postfix/transport:
341 /etc/postfix/master.cf:
342 # service type private unpriv chroot wakeup maxproc command
343 fragile unix - - n - 20 smtp
345 See also the documentation for default_destination_concurrency_limit.
347 The effect of this configuration is that up to 2000 consecutive errors are
348 tolerated without marking the destination dead, while the total concurrency
349 remains reasonable (10-20 processes). This trick is only for a very specialized
350 situation: high volume delivery into a channel with multi-error bursts that is
351 capable of high throughput, but is repeatedly throttled by the bursts of
354 When a destination is unable to handle the load even after the Postfix process
355 limit is reduced to 1, a desperate measure is to insert brief delays between
358 * Postfix version 2.5 and later:
360 o In master.cf set up a dedicated clone of the "smtp" transport for the
361 problem destination. In the example below we call it "slow".
363 o In main.cf configure a short delay between deliveries to the same
366 /etc/postfix/main.cf:
367 transport_maps = hash:/etc/postfix/transport
368 slow_destination_rate_delay = 1
370 /etc/postfix/transport:
373 /etc/postfix/master.cf:
374 # service type private unpriv chroot wakeup maxproc command
375 slow unix - - n - - smtp
377 See also the documentation for default_destination_rate_delay.
379 This solution forces the Postfix smtp(8) client to wait for
380 $slow_destination_rate_delay seconds between deliveries to the same
383 * Earlier Postfix versions:
385 o In the transport map entry for the problem destination, specify a dead
386 host as the primary nexthop.
388 o In the master.cf entry for the transport specify the problem
389 destination as the fallback_relay and specify a small
390 smtp_connect_timeout value.
392 /etc/postfix/main.cf:
393 transport_maps = hash:/etc/postfix/transport
395 /etc/postfix/transport:
396 example.com slow:[dead.host]
398 /etc/postfix/master.cf:
399 # service type private unpriv chroot wakeup maxproc command
400 slow unix - - n - 1 smtp
401 -o fallback_relay=problem.example.com
402 -o smtp_connect_timeout=1
403 -o smtp_connection_cache_on_demand=no
405 This solution forces the Postfix smtp(8) client to wait for
406 $smtp_connect_timeout seconds between deliveries. The connection caching
407 feature is disabled to prevent the client from skipping over the dead host.
409 P
\bPo
\bos
\bst
\btf
\bfi
\bix
\bx q
\bqu
\bue
\beu
\bue
\be d
\bdi
\bir
\bre
\bec
\bct
\bto
\bor
\bri
\bie
\bes
\bs
411 The following sections describe Postfix queues: their purpose, what normal
412 behavior looks like, and how to diagnose abnormal behavior.
414 T
\bTh
\bhe
\be "
\b"m
\bma
\bai
\bil
\bld
\bdr
\bro
\bop
\bp"
\b" q
\bqu
\bue
\beu
\bue
\be
416 Messages that have been submitted via the Postfix sendmail(1) command, but not
417 yet brought into the main Postfix queue by the pickup(8) service, await
418 processing in the "maildrop" queue. Messages can be added to the "maildrop"
419 queue even when the Postfix system is not running. They will begin to be
420 processed once Postfix is started.
422 The "maildrop" queue is drained by the single threaded pickup(8) service
423 scanning the queue directory periodically or when notified of new message
424 arrival by the postdrop(1) program. The postdrop(1) program is a setgid helper
425 that allows the unprivileged Postfix sendmail(1) program to inject mail into
426 the "maildrop" queue and to notify the pickup(8) service of its arrival.
428 All mail that enters the main Postfix queue does so via the cleanup(8) service.
429 The cleanup service is responsible for envelope and header rewriting, header
430 and body regular expression checks, automatic bcc recipient processing, milter
431 content processing, and reliable insertion of the message into the Postfix
434 In the absence of excessive CPU consumption in cleanup(8) header or body
435 regular expression checks or other software consuming all available CPU
436 resources, Postfix performance is disk I/O bound. The rate at which the pickup
437 (8) service can inject messages into the queue is largely determined by disk
438 access times, since the cleanup(8) service must commit the message to stable
439 storage before returning success. The same is true of the postdrop(1) program
440 writing the message to the "maildrop" directory.
442 As the pickup service is single threaded, it can only deliver one message at a
443 time at a rate that does not exceed the reciprocal disk I/O latency (+ CPU if
444 not negligible) of the cleanup service.
446 Congestion in this queue is indicative of an excessive local message submission
447 rate or perhaps excessive CPU consumption in the cleanup(8) service due to
448 excessive body_checks, or (Postfix >= 2.3) high latency milters.
450 Note, that once the active queue is full, the cleanup service will attempt to
451 slow down message injection by pausing $in_flow_delay for each message. In this
452 case "maildrop" queue congestion may be a consequence of congestion downstream,
453 rather than a problem in its own right.
455 Note, you should not attempt to deliver large volumes of mail via the pickup(8)
456 service. High volume sites should avoid using "simple" content filters that re-
457 inject scanned mail via Postfix sendmail(1) and postdrop(1).
459 A high arrival rate of locally submitted mail may be an indication of an
460 uncaught forwarding loop, or a run-away notification program. Try to keep the
461 volume of local mail injection to a moderate level.
463 The "postsuper -r" command can place selected messages into the "maildrop"
464 queue for reprocessing. This is most useful for resetting any stale
465 content_filter settings. Requeuing a large number of messages using "postsuper
466 -r" can clearly cause a spike in the size of the "maildrop" queue.
468 T
\bTh
\bhe
\be "
\b"h
\bho
\bol
\bld
\bd"
\b" q
\bqu
\bue
\beu
\bue
\be
470 The administrator can define "smtpd" access(5) policies, or cleanup(8) header/
471 body checks that cause messages to be automatically diverted from normal
472 processing and placed indefinitely in the "hold" queue. Messages placed in the
473 "hold" queue stay there until the administrator intervenes. No periodic
474 delivery attempts are made for messages in the "hold" queue. The postsuper(1)
475 command can be used to manually release messages into the "deferred" queue.
477 Messages can potentially stay in the "hold" queue longer than
478 $maximal_queue_lifetime. If such "old" messages need to be released from the
479 "hold" queue, they should typically be moved into the "maildrop" queue using
480 "postsuper -r", so that the message gets a new timestamp and is given more than
481 one opportunity to be delivered. Messages that are "young" can be moved
482 directly into the "deferred" queue using "postsuper -H".
484 The "hold" queue plays little role in Postfix performance, and monitoring of
485 the "hold" queue is typically more closely motivated by tracking spam and
486 malware, than by performance issues.
488 T
\bTh
\bhe
\be "
\b"i
\bin
\bnc
\bco
\bom
\bmi
\bin
\bng
\bg"
\b" q
\bqu
\bue
\beu
\bue
\be
490 All new mail entering the Postfix queue is written by the cleanup(8) service
491 into the "incoming" queue. New queue files are created owned by the "postfix"
492 user with an access bitmask (or mode) of 0600. Once a queue file is ready for
493 further processing the cleanup(8) service changes the queue file mode to 0700
494 and notifies the queue manager of new mail arrival. The queue manager ignores
495 incomplete queue files whose mode is 0600, as these are still being written by
498 The queue manager scans the incoming queue bringing any new mail into the
499 "active" queue if the active queue resource limits have not been exceeded. By
500 default, the active queue accommodates at most 20000 messages. Once the active
501 queue message limit is reached, the queue manager stops scanning the incoming
502 (and deferred, see below) queue.
504 Under normal conditions the incoming queue is nearly empty (has only mode 0600
505 files), with the queue manager able to import new messages into the active
506 queue as soon as they become available.
508 The incoming queue grows when the message input rate spikes above the rate at
509 which the queue manager can import messages into the active queue. The main
510 factors slowing down the queue manager are disk I/O and lookup queries to the
511 trivial-rewrite service. If the queue manager is routinely not keeping up,
512 consider not using "slow" lookup services (MySQL, LDAP, ...) for transport
513 lookups or speeding up the hosts that provide the lookup service. If the
514 problem is I/O starvation, consider striping the queue over more disks, faster
515 controllers with a battery write cache, or other hardware improvements. At the
516 very least, make sure that the queue directory is mounted with the "noatime"
517 option if applicable to the underlying filesystem.
519 The in_flow_delay parameter is used to clamp the input rate when the queue
520 manager starts to fall behind. The cleanup(8) service will pause for
521 $in_flow_delay seconds before creating a new queue file if it cannot obtain a
522 "token" from the queue manager.
524 Since the number of cleanup(8) processes is limited in most cases by the SMTP
525 server concurrency, the input rate can exceed the output rate by at most "SMTP
526 connection count" / $in_flow_delay messages per second.
528 With a default process limit of 100, and an in_flow_delay of 1s, the coupling
529 is strong enough to limit a single run-away injector to 1 message per second,
530 but is not strong enough to deflect an excessive input rate from many sources
533 If a server is being hammered from multiple directions, consider raising the
534 in_flow_delay to 10 seconds, but only if the incoming queue is growing even
535 while the active queue is not full and the trivial-rewrite service is using a
536 fast transport lookup mechanism.
538 T
\bTh
\bhe
\be "
\b"a
\bac
\bct
\bti
\biv
\bve
\be"
\b" q
\bqu
\bue
\beu
\bue
\be
540 The queue manager is a delivery agent scheduler; it works to ensure fast and
541 fair delivery of mail to all destinations within designated resource limits.
543 The active queue is somewhat analogous to an operating system's process run
544 queue. Messages in the active queue are ready to be sent (runnable), but are
545 not necessarily in the process of being sent (running).
547 While most Postfix administrators think of the "active" queue as a directory on
548 disk, the real "active" queue is a set of data structures in the memory of the
549 queue manager process.
551 Messages in the "maildrop", "hold", "incoming" and "deferred" queues (see
552 below) do not occupy memory; they are safely stored on disk waiting for their
553 turn to be processed. The envelope information for messages in the "active"
554 queue is managed in memory, allowing the queue manager to do global scheduling,
555 allocating available delivery agent processes to an appropriate message in the
558 Within the active queue, (multi-recipient) messages are broken up into groups
559 of recipients that share the same transport/nexthop combination; the group size
560 is capped by the transport's recipient concurrency limit.
562 Multiple recipient groups (from one or more messages) are queued for delivery
563 grouped by transport/nexthop combination. The d
\bde
\bes
\bst
\bti
\bin
\bna
\bat
\bti
\bio
\bon
\bn concurrency limit for
564 the transports caps the number of simultaneous delivery attempts for each
565 nexthop. Transports with a r
\bre
\bec
\bci
\bip
\bpi
\bie
\ben
\bnt
\bt concurrency limit of 1 are special: these
566 are grouped by the actual recipient address rather than the nexthop, yielding
567 per-recipient concurrency limits rather than per-domain concurrency limits.
568 Per-recipient limits are appropriate when performing final delivery to
569 mailboxes rather than when relaying to a remote server.
571 Congestion occurs in the active queue when one or more destinations drain
572 slower than the corresponding message input rate.
574 Input into the active queue comes both from new mail in the "incoming" queue,
575 and retries of mail in the "deferred" queue. Should the "deferred" queue get
576 really large, retries of old mail can dominate the arrival rate of new mail.
577 Systems with more CPU, faster disks and more network bandwidth can deal with
578 larger deferred queues, but as a rule of thumb the deferred queue scales to
579 somewhere between 100,000 and 1,000,000 messages with good performance unlikely
580 above that "limit". Systems with queues this large should typically stop
581 accepting new mail, or put the backlog "on hold" until the underlying issue is
582 fixed (provided that there is enough capacity to handle just the new mail).
584 When a destination is down for some time, the queue manager will mark it dead,
585 and immediately defer all mail for the destination without trying to assign it
586 to a delivery agent. In this case the messages will quickly leave the active
587 queue and end up in the deferred queue (with Postfix < 2.4, this is done
588 directly by the queue manager, with Postfix >= 2.4 this is done via the "retry"
591 When the destination is instead simply slow, or there is a problem causing an
592 excessive arrival rate the active queue will grow and will become dominated by
593 mail to the congested destination.
595 The only way to reduce congestion is to either reduce the input rate or
596 increase the throughput. Increasing the throughput requires either increasing
597 the concurrency or reducing the latency of deliveries.
599 For high volume sites a key tuning parameter is the number of "smtp" delivery
600 agents allocated to the "smtp" and "relay" transports. High volume sites tend
601 to send to many different destinations, many of which may be down or slow, so a
602 good fraction of the available delivery agents will be blocked waiting for slow
603 sites. Also mail destined across the globe will incur large SMTP command-
604 response latencies, so high message throughput can only be achieved with more
605 concurrent delivery agents.
607 The default "smtp" process limit of 100 is good enough for most sites, and may
608 even need to be lowered for sites with low bandwidth connections (no use
609 increasing concurrency once the network pipe is full). When one finds that the
610 queue is growing on an "idle" system (CPU, disk I/O and network not exhausted)
611 the remaining reason for congestion is insufficient concurrency in the face of
612 a high average latency. If the number of outbound SMTP connections (either
613 ESTABLISHED or SYN_SENT) reaches the process limit, mail is draining slowly and
614 the system and network are not loaded, raise the "smtp" and/or "relay" process
617 When a high volume destination is served by multiple MX hosts with typically
618 low delivery latency, performance can suffer dramatically when one of the MX
619 hosts is unresponsive and SMTP connections to that host timeout. For example,
620 if there are 2 equal weight MX hosts, the SMTP connection timeout is 30 seconds
621 and one of the MX hosts is down, the average SMTP connection will take
622 approximately 15 seconds to complete. With a default per-destination
623 concurrency limit of 20 connections, throughput falls to just over 1 message
626 The best way to avoid bottlenecks when one or more MX hosts is non-responsive
627 is to use connection caching. Connection caching was introduced with Postfix
628 2.2 and is by default enabled on demand for destinations with a backlog of mail
629 in the active queue. When connection caching is in effect for a particular
630 destination, established connections are re-used to send additional messages,
631 this reduces the number of connections made per message delivery and maintains
632 good throughput even in the face of partial unavailability of the destination's
635 If connection caching is not available (Postfix < 2.2) or does not provide a
636 sufficient latency reduction, especially for the "relay" transport used to
637 forward mail to "your own" domains, consider setting lower than default SMTP
638 connection timeouts (1-5 seconds) and higher than default destination
639 concurrency limits. This will further reduce latency and provide more
640 concurrency to maintain throughput should latency rise.
642 Setting high concurrency limits to domains that are not your own may be viewed
643 as hostile by the receiving system, and steps may be taken to prevent you from
644 monopolizing the destination system's resources. The defensive measures may
645 substantially reduce your throughput or block access entirely. Do not set
646 aggressive concurrency limits to remote domains without coordinating with the
647 administrators of the target domain.
649 If necessary, dedicate and tune custom transports for selected high volume
650 destinations. The "relay" transport is provided for forwarding mail to domains
651 for which your server is a primary or backup MX host. These can make up a
652 substantial fraction of your email traffic. Use the "relay" and not the "smtp"
653 transport to send email to these domains. Using the "relay" transport allocates
654 a separate delivery agent pool to these destinations and allows separate tuning
655 of timeouts and concurrency limits.
657 Another common cause of congestion is unwarranted flushing of the entire
658 deferred queue. The deferred queue holds messages that are likely to fail to be
659 delivered and are also likely to be slow to fail delivery (time out). As a
660 result the most common reaction to a large deferred queue (flush it!) is more
661 than likely counter-productive, and typically makes the congestion worse. Do
662 not flush the deferred queue unless you expect that most of its content has
663 recently become deliverable (e.g. relayhost back up after an outage)!
665 Note that whenever the queue manager is restarted, there may already be
666 messages in the active queue directory, but the "real" active queue in memory
667 is empty. In order to recover the in-memory state, the queue manager moves all
668 the active queue messages back into the incoming queue, and then uses its
669 normal incoming queue scan to refill the active queue. The process of moving
670 all the messages back and forth, redoing transport table (trivial-rewrite(8)
671 resolve service) lookups, and re-importing the messages back into memory is
672 expensive. At all costs, avoid frequent restarts of the queue manager (e.g. via
673 frequent execution of "postfix reload").
675 T
\bTh
\bhe
\be "
\b"d
\bde
\bef
\bfe
\ber
\brr
\bre
\bed
\bd"
\b" q
\bqu
\bue
\beu
\bue
\be
677 When all the deliverable recipients for a message are delivered, and for some
678 recipients delivery failed for a transient reason (it might succeed later), the
679 message is placed in the deferred queue.
681 The queue manager scans the deferred queue periodically. The scan interval is
682 controlled by the queue_run_delay parameter. While a deferred queue scan is in
683 progress, if an incoming queue scan is also in progress (ideally these are
684 brief since the incoming queue should be short), the queue manager alternates
685 between looking for messages in the "incoming" queue and in the "deferred"
686 queue. This "round-robin" strategy prevents starvation of either the incoming
687 or the deferred queues.
689 Each deferred queue scan only brings a fraction of the deferred queue back into
690 the active queue for a retry. This is because each message in the deferred
691 queue is assigned a "cool-off" time when it is deferred. This is done by time-
692 warping the modification time of the queue file into the future. The queue file
693 is not eligible for a retry if its modification time is not yet reached.
695 The "cool-off" time is at least $minimal_backoff_time and at most
696 $maximal_backoff_time. The next retry time is set by doubling the message's age
697 in the queue, and adjusting up or down to lie within the limits. This means
698 that young messages are initially retried more often than old messages.
700 If a high volume site routinely has large deferred queues, it may be useful to
701 adjust the queue_run_delay, minimal_backoff_time and maximal_backoff_time to
702 provide short enough delays on first failure (Postfix >= 2.4 has a sensibly low
703 minimal backoff time by default), with perhaps longer delays after multiple
704 failures, to reduce the retransmission rate of old messages and thereby reduce
705 the quantity of previously deferred mail in the active queue. If you want a
706 really low minimal_backoff_time, you may also want to lower queue_run_delay,
707 but understand that more frequent scans will increase the demand for disk I/O.
709 One common cause of large deferred queues is failure to validate recipients at
710 the SMTP input stage. Since spammers routinely launch dictionary attacks from
711 unrepliable sender addresses, the bounces for invalid recipient addresses clog
712 the deferred queue (and at high volumes proportionally clog the active queue).
713 Recipient validation is strongly recommended through use of the
714 local_recipient_maps and relay_recipient_maps parameters. Even when bounces
715 drain quickly they inundate innocent victims of forgery with unwanted email. To
716 avoid this, do not accept mail for invalid recipients.
718 When a host with lots of deferred mail is down for some time, it is possible
719 for the entire deferred queue to reach its retry time simultaneously. This can
720 lead to a very full active queue once the host comes back up. The phenomenon
721 can repeat approximately every maximal_backoff_time seconds if the messages are
722 again deferred after a brief burst of congestion. Perhaps, a future Postfix
723 release will add a random offset to the retry time (or use a combination of
724 strategies) to reduce the odds of repeated complete deferred queue flushes.
726 C
\bCr
\bre
\bed
\bdi
\bit
\bts
\bs
728 The qshape(1) program was developed by Victor Duchovni of Morgan Stanley, who
729 also wrote the initial version of this document.