1 P
\bPo
\bos
\bst
\btf
\bfi
\bix
\bx P
\bPe
\ber
\brf
\bfo
\bor
\brm
\bma
\ban
\bnc
\bce
\be T
\bTu
\bun
\bni
\bin
\bng
\bg
3 -------------------------------------------------------------------------------
5 P
\bPu
\bur
\brp
\bpo
\bos
\bse
\be o
\bof
\bf P
\bPo
\bos
\bst
\btf
\bfi
\bix
\bx p
\bpe
\ber
\brf
\bfo
\bor
\brm
\bma
\ban
\bnc
\bce
\be t
\btu
\bun
\bni
\bin
\bng
\bg
7 The hints and tips in this document help you improve the performance of Postfix
8 systems that already work. If your Postfix system is unable to receive or
9 deliver mail, then you need to solve those problems first, using the
10 DEBUG_README document as guidance.
12 For tuning external content filter performance, first read the respective
13 information in the FILTER_README and SMTPD_PROXY_README documents. Then make
14 sure to avoid latency in the content filter code. As much as possible avoid
15 performing queries against external data sources with a high or highly variable
16 delay. Your content filter will run with a small concurrency to avoid CPU/
17 memory starvation, and if any latency creeps in, content filter throughput will
18 suffer. High volume environments should avoid RBL lookups, complex database
21 Topics on mail receiving performance:
23 * General mail receiving performance tips
24 * Doing more work with your SMTP server processes
25 * Slowing down SMTP clients that make many errors
26 * Measures against clients that make too many connections
28 Topics on mail delivery performance:
30 * General mail delivery performance tips
31 * Tuning the frequency of deferred mail delivery attempts
32 * Tuning the number of simultaneous deliveries
33 * Tuning the number of recipients per delivery
35 Other Postfix performance tuning topics:
37 * Tuning the number of Postfix processes
38 * Tuning the number of processes on the system
39 * Tuning the number of open files or sockets
41 The following tools can be used to measure mail system performance under
42 artificial loads. They are normally not installed with Postfix.
44 * smtp-source, SMTP/LMTP message generator
45 * smtp-sink, SMTP/LMTP message dump
46 * qmqp-source, QMQP message generator
47 * qmqp-sink, QMQP message dump
49 G
\bGe
\ben
\bne
\ber
\bra
\bal
\bl m
\bma
\bai
\bil
\bl r
\bre
\bec
\bce
\bei
\biv
\bvi
\bin
\bng
\bg p
\bpe
\ber
\brf
\bfo
\bor
\brm
\bma
\ban
\bnc
\bce
\be t
\bti
\bip
\bps
\bs
51 * Read and understand the maildrop queue, incoming queue, and active queue
52 discussions in the QSHAPE_README document.
54 * Run a local name server to reduce slow-down due to DNS lookups. If you run
55 multiple Postfix systems, point each local name server to a shared
56 forwarding server to reduce the number of lookups across the upstream
59 * Eliminate unnecessary LDAP lookups, by specifying a domain filter. This
60 eliminates lookups for addresses in remote domains, and eliminates lookups
61 of partial addresses. See ldap_table(5) for details.
63 When Postfix responds slowly to SMTP clients:
65 * Look for obvious signs of trouble as described in the DEBUG_README
66 document, and eliminate those problems first.
68 * Turn off your header_checks and body_checks patterns and see if the problem
71 * Turn off chroot operation as described in the DEBUG_README document and see
72 if the problem goes away.
74 * If Postfix logs the SMTP client as "unknown" then you have a name service
75 problem: the name server is bad, or the resolv.conf file contains bad
76 information, or some packet filter is blocking the DNS requests or replies.
78 * If the number of smtpd(8) processes has reached the process limit as
79 specified in master.cf, new SMTP clients must wait until a process becomes
80 available. Increase the number of processes if memory permits. See the
81 instructions given under "Tuning the number of Postfix processes".
83 D
\bDo
\boi
\bin
\bng
\bg m
\bmo
\bor
\bre
\be w
\bwo
\bor
\brk
\bk w
\bwi
\bit
\bth
\bh y
\byo
\bou
\bur
\br S
\bSM
\bMT
\bTP
\bP s
\bse
\ber
\brv
\bve
\ber
\br p
\bpr
\bro
\boc
\bce
\bes
\bss
\bse
\bes
\bs
85 With Postfix versions 2.0 and earlier, the smtpd(8) server pauses before
86 reporting an error to an SMTP client. The idea is called tar pitting. However,
87 these delays also slow down Postfix. When the smtpd(8) server replies slowly,
88 sessions take more time, so that more smtpd(8) server processes are needed to
89 handle the load. When your Postfix smtpd(8) server process limit is reached,
90 new clients must wait until a server process becomes available. This means that
91 all clients experience poor performance.
93 You can speed up the handling of smtpd(8) server error replies by turning off
97 # Not needed with Postfix 2.1
98 smtpd_error_sleep_time = 0
100 With the above setting, Postfix 2.0 and earlier can serve more SMTP clients
101 with the same number SMTP server processes. The next section describes how
102 Postfix deals with clients that make a large number of errors.
104 S
\bSl
\blo
\bow
\bwi
\bin
\bng
\bg d
\bdo
\bow
\bwn
\bn S
\bSM
\bMT
\bTP
\bP c
\bcl
\bli
\bie
\ben
\bnt
\bts
\bs t
\bth
\bha
\bat
\bt m
\bma
\bak
\bke
\be m
\bma
\ban
\bny
\by e
\ber
\brr
\bro
\bor
\brs
\bs
106 The Postfix smtpd(8) server maintains a per-session error count. The error
107 count is reset when a message is transferred successfully, and is incremented
108 when a client request is unrecognized or unimplemented, when a client request
109 violates access restrictions, or when some other error happens.
111 As the per-session error count increases, the smtpd(8) server changes behavior
112 and begins to insert delays into the responses. The idea is to slow down a run-
113 away client in order to limit resource usage. The behavior is Postfix version
116 IMPORTANT: These delays slow down Postfix, too. When too much delay is
117 configured, the number of simultaneous SMTP sessions will increase until it
118 reaches the smtpd(8) server process limit, and new SMTP clients must wait until
119 an smtpd(8) server process becomes available.
121 Postfix version 2.1 and later:
123 * When the error count reaches $smtpd_soft_error_limit (default: 10), the
124 Postfix smtpd(8) server delays all non-error and error responses by
125 $smtpd_error_sleep_time seconds (default: 1 second).
127 * When the error count reaches $smtpd_hard_error_limit (default: 20) the
128 Postfix smtpd(8) server breaks the connection.
130 Postfix version 2.0 and earlier:
132 * When the error count is less than $smtpd_soft_error_limit (default: 10) the
133 Postfix smtpd(8) server delays all error replies by $smtpd_error_sleep_time
134 (1 second with Postfix 2.0, 5 seconds with Postfix 1.1 and earlier).
136 * When the error count reaches $smtpd_soft_error_limit, the Postfix smtpd(8)
137 server delays all responses by "error count" seconds or
138 $smtpd_error_sleep_time, whichever is more.
140 * When the error count reaches $smtpd_hard_error_limit (default: 20) the
141 Postfix smtpd(8) server breaks the connection.
143 M
\bMe
\bea
\bas
\bsu
\bur
\bre
\bes
\bs a
\bag
\bga
\bai
\bin
\bns
\bst
\bt c
\bcl
\bli
\bie
\ben
\bnt
\bts
\bs t
\bth
\bha
\bat
\bt m
\bma
\bak
\bke
\be t
\bto
\boo
\bo m
\bma
\ban
\bny
\by c
\bco
\bon
\bnn
\bne
\bec
\bct
\bti
\bio
\bon
\bns
\bs
145 Note: these features use the Postfix anvil(8) service, introduced with Postfix
148 The Postfix smtpd(8) server can limit the number of simultaneous connections
149 from the same SMTP client, as well as the connection rate and the rate of
150 certain SMTP commands from the same client. These statistics are maintained by
151 the anvil(8) server (translation: if anvil(8) breaks, then connection limits
154 IMPORTANT: These limits must not be used to regulate legitimate traffic: mail
155 will suffer grotesque delays if you do so. The limits are designed to protect
156 the smtpd(8) server against abuse by out-of-control clients.
158 smtpd_client_connection_count_limit (default: 50)
159 The maximum number of connections that an SMTP client may make
161 smtpd_client_connection_rate_limit (default: no limit)
162 The maximum number of connections that an SMTP client may make in the
163 time interval specified with anvil_rate_time_unit (default: 60s).
164 smtpd_client_message_rate_limit (default: no limit)
165 The maximum number of message delivery requests that an SMTP client may
166 make in the time interval specified with anvil_rate_time_unit (default:
168 smtpd_client_recipient_rate_limit (default: no limit)
169 The maximum number of recipient addresses that an SMTP client may
170 specify in the time interval specified with anvil_rate_time_unit
172 smtpd_client_new_tls_session_rate_limit (default: no limit)
173 The maximum number of new TLS sessions (without using the TLS session
174 cache) that an SMTP client may negotiate in the time interval specified
175 with anvil_rate_time_unit (default: 60s).
176 smtpd_client_event_limit_exceptions (default: $mynetworks)
177 SMTP clients that are excluded from connection and rate limits
180 G
\bGe
\ben
\bne
\ber
\bra
\bal
\bl m
\bma
\bai
\bil
\bl d
\bde
\bel
\bli
\biv
\bve
\ber
\bry
\by p
\bpe
\ber
\brf
\bfo
\bor
\brm
\bma
\ban
\bnc
\bce
\be t
\bti
\bip
\bps
\bs
182 * Read and understand the maildrop queue, incoming queue, active queue and
183 deferred queue discussions in the QSHAPE_README document.
185 * In case of slow delivery, run the qshape tool as described in the
186 QSHAPE_README document.
188 * Submit multiple recipients per message instead of submitting messages with
189 only a few recipients.
191 * Submit mail via SMTP instead of /usr/sbin/sendmail. You may have to adjust
192 the smtpd_recipient_limit parameter setting.
194 * Don't overwhelm the disk with mail submissions. Optimize the mail
195 submission rate by tuning the number of parallel submissions and/or by
196 tuning the Postfix in_flow_delay parameter setting.
198 * Run a local name server to reduce slow-down due to DNS lookups. If you run
199 multiple Postfix systems, point each local name server to a shared
200 forwarding server to reduce the number of lookups across the upstream
203 * Reduce the smtp_connect_timeout and smtp_helo_timeout values so that
204 Postfix does not waste lots of time connecting to non-responding remote
207 * Use a dedicated mail delivery transport for problematic destinations, with
208 reduced timeouts and with adjusted concurrency. See "Tuning the number of
209 simultaneous deliveries" below.
211 * Use a fallback_relay host for mail that cannot be delivered upon the first
212 attempt. This "graveyard" machine can use shorter retry times for difficult
213 to reach destinations. See "Tuning the frequency of deferred mail delivery
216 * Speed up disk updates with a large (64MB) persistent write cache. This
217 allows disk updates to be sorted for optimal access speed without
218 compromising file system integrity when the system crashes.
220 * Use a solid-state disk (a persistent RAM disk). This is an expensive
221 solution that should be used in combination with short SMTP timeouts and a
222 fallback_relay "graveyard" machine that delivers mail for problem
225 T
\bTu
\bun
\bni
\bin
\bng
\bg t
\bth
\bhe
\be n
\bnu
\bum
\bmb
\bbe
\ber
\br o
\bof
\bf s
\bsi
\bim
\bmu
\bul
\blt
\bta
\ban
\bne
\beo
\bou
\bus
\bs d
\bde
\bel
\bli
\biv
\bve
\ber
\bri
\bie
\bes
\bs
227 Although Postfix can be configured to run 1000 SMTP client processes at the
228 same time, it is rarely desirable that it makes 1000 simultaneous connections
229 to the same remote system. For this reason, Postfix has safety mechanisms in
230 place to avoid this so-called "thundering herd" problem.
232 The Postfix queue manager implements the analog of the TCP slow start flow
233 control strategy: when delivering to a site, send a small number of messages
234 first, then increase the concurrency as long as all goes well; reduce
235 concurrency in the face of congestion.
237 * The initial_destination_concurrency parameter (default: 5) controls how
238 many messages are initially sent to the same destination before adapting
239 delivery concurrency. Of course, this setting is effective only as long as
240 it does not exceed the process limit and the destination concurrency limit
241 for the specific mail transport channel.
243 * The default_destination_concurrency_limit parameter (default: 20) controls
244 how many messages may be sent to the same destination simultaneously. You
245 can override this setting for specific message delivery transports by
246 taking the name of the master.cf entry and appending
247 "_destination_concurrency_limit".
249 Examples of transport specific concurrency limits are:
251 * The local_destination_concurrency_limit parameter (default: 2) controls how
252 many messages are delivered simultaneously to the same local recipient. The
253 recommended limit is low because delivery to the same mailbox must happen
254 sequentially, so massive parallelism is not useful. Another good reason to
255 limit delivery concurrency to the same recipient: if the recipient has an
256 expensive shell command in her .forward file, or if the recipient is a
257 mailing list manager, you don't want to run too many instances of those
258 processes at the same time.
260 * The default smtp_destination_concurrency_limit of 20 seems enough to
261 noticeably load a system without bringing it to its knees. Be careful when
262 changing this to a much larger number.
264 The above default values of the concurrency limits work well in a broad range
265 of situations. Knee-jerk changes to these parameters in the face of congestion
266 can actually make problems worse. Specifically, large destination concurrencies
267 should never be the default. They should be used only for transports that
268 deliver mail to a small number of high volume domains.
270 A common situation where high concurrency is called for is on gateways relaying
271 a high volume of mail from between the Internet and an intranet mail
272 environment. Approximately half the mail (assuming equal volumes inbound and
273 outbound) will be destined for the internal mail hubs. Since the internal mail
274 hubs will be receiving all external mail exclusively from the gateway, it is
275 reasonable to configure the gateway to make greater demands on the capacity of
276 the internal SMTP servers.
278 The tuning of the inbound concurrency limits need not be trial and error. A
279 high volume capable mailhub should be able to easily handle 50 or 100 (rather
280 than the default 20) simultaneous connections, especially if the gateway
281 forwards to multiple MX hosts. When all MX hosts are up and accepting
282 connections in a timely fashion, throughput will be high. If any MX host is
283 down and completely unresponsive, the average connection latency rises to at
284 least 1/N * $smtp_connection_timeout, if there are N MX hosts. This limits
285 throughput to at most the destination concurrency * N /
286 $smtp_connection_timeout.
288 For example, with a destination concurrency of 100 and 2 MX hosts, each host
289 will handle up to 50 simultaneous connections. If one MX host is down and the
290 default SMTP connection timeout is 30s, the throughput limit is 100 * 2 / 30 ~=
291 6 messages per second. This suggests that high volume destinations with good
292 connectivity and multiple MX hosts need a lower connection timeout, values as
293 low as 5s or even 1s can be used to prevent congestion when one or more, but
294 not all MX hosts are down.
296 If necessary, set a higher transport_destination_concurrency_limit (in main.cf
297 since this is a queue manager parameter) and a lower smtp_connection_timeout
298 (with a "-o" override in master.cf since this parameter has no per-transport
299 name) for the relay transport and any transports dedicated for specific high
302 T
\bTu
\bun
\bni
\bin
\bng
\bg t
\bth
\bhe
\be n
\bnu
\bum
\bmb
\bbe
\ber
\br o
\bof
\bf r
\bre
\bec
\bci
\bip
\bpi
\bie
\ben
\bnt
\bts
\bs p
\bpe
\ber
\br d
\bde
\bel
\bli
\biv
\bve
\ber
\bry
\by
304 The default_destination_recipient_limit parameter (default: 50) controls how
305 many recipients a Postfix delivery agent will send with each copy of an email
306 message. You can override this setting for specific Postfix delivery agents.
307 For example, "uucp_destination_recipient_limit = 100" would limit the number of
308 recipients per UUCP delivery to 100.
310 If an email message exceeds the recipient limit for some destination, the
311 Postfix queue manager breaks up the list of recipients into smaller lists.
312 Postfix will attempt to send multiple copies of the message in parallel.
314 IMPORTANT: Be careful when increasing the recipient limit per message delivery;
315 some smtpd(8) servers abort the connection when they run out of memory or when
316 a hard recipient limit is reached, so that the message will never be delivered.
318 The smtpd_recipient_limit parameter (default: 1000) controls how many
319 recipients the Postfix smtpd(8) server will take per delivery. The default
320 limit is more than any reasonable SMTP client would send. The limit exists to
321 protect the local mail system against a run-away client.
323 T
\bTu
\bun
\bni
\bin
\bng
\bg t
\bth
\bhe
\be f
\bfr
\bre
\beq
\bqu
\bue
\ben
\bnc
\bcy
\by o
\bof
\bf d
\bde
\bef
\bfe
\ber
\brr
\bre
\bed
\bd m
\bma
\bai
\bil
\bl d
\bde
\bel
\bli
\biv
\bve
\ber
\bry
\by a
\bat
\btt
\bte
\bem
\bmp
\bpt
\bts
\bs
325 When a Postfix delivery agent (smtp(8), local(8), etc.) is unable to deliver a
326 message it may blame the message itself, or it may blame the receiving party.
328 * When the delivery agent blames the message, the queue manager gives the
329 queue file a time stamp into the future, so it won't be looked at for a
330 while. By default, the amount of time to cool down is the amount of time
331 that has passed since the message arrived. This results in so-called
332 exponential backoff behavior.
334 * When the delivery agent blames the receiving party (for example a local
335 recipient user, or a remote host), the queue manager not only advances the
336 queue file time stamp, but also puts the receiving party on a "dead" list
337 so that it will be skipped for some amount of time.
339 This process is governed by a bunch of little parameters.
341 queue_run_delay (default: 300 seconds; before Postfix 2.4: 1000s)
342 How often the queue manager scans the queue for deferred mail.
343 minimal_backoff_time (default: 300 seconds; before Postfix 2.4: 1000s)
344 The minimal amount of time a message won't be looked at, and the
345 minimal amount of time to stay away from a "dead" destination.
346 maximal_backoff_time (default: 4000 seconds)
347 The maximal amount of time a message won't be looked at after a
349 maximal_queue_lifetime (default: 5 days)
350 How long a message stays in the queue before it is sent back as
351 undeliverable. Specify 0 for mail that should be returned immediately
352 after the first unsuccessful delivery attempt.
353 bounce_queue_lifetime (default: 5 days, available with Postfix version 2.1
355 How long a MAILER-DAEMON message stays in the queue before it is
356 considered undeliverable. Specify 0 for mail that should be tried only
358 qmgr_message_recipient_limit (default: 20000)
359 The size of many in-memory queue manager data structures. Among others,
360 this parameter limits the size of the short-term, in-memory list of
361 "dead" destinations. Destinations that don't fit the list are not
364 IMPORTANT: If you increase the frequency of deferred mail delivery attempts, or
365 if you flush the deferred mail queue frequently, then you may find that Postfix
366 mail delivery performance actually becomes worse. The symptoms are as follows:
368 * The active queue becomes saturated with mail that has delivery problems.
369 New mail enters the active queue only when an old message is deferred. This
370 is a slow process that usually requires timing out one or more SMTP
373 * All available Postfix delivery agents become occupied trying to connect to
374 unreachable sites etc. New mail has to wait until a delivery agent becomes
375 available. This is a slow process that usually requires timing out one or
376 more SMTP connections.
378 When mail is being deferred frequently, fixing the problem is always better
379 than increasing the frequency of delivery attempts. However, if you can control
380 only the delivery attempt frequency, consider using a dedicated fallback_relay
381 "graveyard" machine for bad destinations, so that these destinations do not
382 ruin the performance of normal mail deliveries.
384 T
\bTu
\bun
\bni
\bin
\bng
\bg t
\bth
\bhe
\be n
\bnu
\bum
\bmb
\bbe
\ber
\br o
\bof
\bf P
\bPo
\bos
\bst
\btf
\bfi
\bix
\bx p
\bpr
\bro
\boc
\bce
\bes
\bss
\bse
\bes
\bs
386 The default_process_limit configuration parameter gives direct control over how
387 many daemon processes Postfix will run. As of Postfix 2.0 the default limit is
388 100 smtp client processes, 100 smtp server processes, and so on. This may
389 overwhelm systems with little memory, as well as networks with low bandwidth.
391 You can change the global process limit by specifying a non-default
392 default_process_limit in the main.cf file. For example, to run up to 10 smtp
393 client processes, 10 smtp server processes, and so on:
395 /etc/postfix/main.cf:
396 default_process_limit = 10
398 You need to execute "postfix reload" to make the change effective. The limits
399 are enforced by the Postfix master(8) daemon which does not automatically read
400 main.cf when it changes.
402 You can override the process limit for specific Postfix daemons by editing the
403 master.cf file. For example, if you do not wish to receive 100 SMTP messages at
404 the same time, but do not want to change the process limits for local mail
405 deliveries, you could specify:
407 /etc/postfix/master.cf:
408 # ====================================================================
409 # service type private unpriv chroot wakeup maxproc command + args
410 # (yes) (yes) (yes) (never) (100)
411 # ====================================================================
413 smtp inet n - - - 10 smtpd
416 T
\bTu
\bun
\bni
\bin
\bng
\bg t
\bth
\bhe
\be n
\bnu
\bum
\bmb
\bbe
\ber
\br o
\bof
\bf p
\bpr
\bro
\boc
\bce
\bes
\bss
\bse
\bes
\bs o
\bon
\bn t
\bth
\bhe
\be s
\bsy
\bys
\bst
\bte
\bem
\bm
418 * MacOS X will run out of process slots when you increase Postfix process
419 limits. The following works with OSX 10.4 and OSX 10.5.
421 MacOS X kernel parameters can be specified in /etc/sysctl.conf.
425 kern.maxprocperuid=2048
427 Unfortunately these can't simply be set on the fly with "sysctl -w". You
428 also have to set the following in /etc/launchd.conf so that the root user
429 after boot will have the right process limit (2048). Otherwise you have to
430 always run ulimit -u 2048 as root, then start a user shell, and then start
431 processes for things to take effect.
436 Once these are in place, reboot the system. After that, the limits will
439 T
\bTu
\bun
\bni
\bin
\bng
\bg t
\bth
\bhe
\be n
\bnu
\bum
\bmb
\bbe
\ber
\br o
\bof
\bf o
\bop
\bpe
\ben
\bn f
\bfi
\bil
\ble
\bes
\bs o
\bor
\br s
\bso
\boc
\bck
\bke
\bet
\bts
\bs
441 When Postfix opens too many files or sockets, processes will abort with fatal
442 errors, and the system may log "file table full" errors.
444 * Depending on your Postfix and operating system versions you may need to
445 recompile Postfix if you need more than 1024 file descriptors per process:
447 o No recompilation is needed for Postfix version 2.4 and later, when it
448 was compiled for systems that support BSD kqueue(2) (FreeBSD 4.1,
449 NetBSD 2.0, OpenBSD 2.9), Solaris 8 /dev/poll, or Linux 2.6 epoll(4).
451 o Otherwise, Postfix needs to be recompiled to override the default
454 * Reduce the number of processes as described under "Tuning the number of
455 Postfix processes" above. Fewer processes need fewer open files and
458 * Configure the kernel for more open files and sockets. The details are
459 extremely system dependent and change with the operating system version. Be
460 sure to verify the following information with your system tuning guide:
462 o Some FreeBSD kernel parameters can be specified in /boot/loader.conf,
463 and some can be specified in /etc/sysctl.conf or changed with sysctl
464 commands. Which is which depends on the version.
466 kern.ipc.maxsockets="5000"
467 kern.ipc.nmbclusters="65536"
469 kern.maxfiles="16384"
470 kern.maxfilesperproc="16384"
472 o Linux kernel parameters can be specified in /etc/sysctl.conf or changed
473 with sysctl commands:
476 kernel.threads-max=2048
478 o Solaris kernel parameters can be specified in /etc/system, as described
479 in the Solaris FAQ entry titled "How can I increase the number of file
480 descriptors per process?"
482 * set hard limit on file descriptors
483 set rlim_fd_max = 4096
484 * set soft limit on file descriptors
485 set rlim_fd_cur = 1024