Um de nossos servidores SMTP está aceitando e-mails com lentidão, eis a saída típica (tempo de resposta 30+ segundos) de um script de cliente smtp:
2014-02-26 11:44:11 +0800 BEGIN
2014-02-26 11:44:11 +0800 LOGGED IN
2014-02-26 11:44:11 +0800 BEFORE SEND
2014-02-26 11:44:59 +0800 AFTER SEND
2014-02-26 11:44:59 +0800 END
O script ruby:
message = <<MESSAGE_END
From: One <[email protected]>
To: Two <[email protected]>
Subject: SMTP e-mail test
Testing 123
MESSAGE_END
def timelog(msg)
puts "#{Time.now} #{msg}"
end
timelog("BEGIN")
Net::SMTP.start(host, 25, 'localhost', username, password, :plain) do |smtp|
timelog("LOGGED IN")
timelog("BEFORE SEND")
smtp.send_message message, '[email protected]', ['[email protected]']
timelog("AFTER SEND")
end
timelog("END")
Como posso melhorar o desempenho?
UPDATE (com informações de tempo DNS, carregando):
# time dig yahoo.com mx
; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.17.rc1.el6_4.5 <<>> yahoo.com mx
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 57858
;; flags: qr rd ra; QUERY: 1, ANSWER: 3, AUTHORITY: 0, ADDITIONAL: 0
;; QUESTION SECTION:
;yahoo.com. IN MX
;; ANSWER SECTION:
yahoo.com. 528 IN MX 1 mta7.am0.yahoodns.net.
yahoo.com. 528 IN MX 1 mta5.am0.yahoodns.net.
yahoo.com. 528 IN MX 1 mta6.am0.yahoodns.net.
;; Query time: 5 msec
;; SERVER: 8.8.8.8#53(8.8.8.8)
;; WHEN: Fri Mar 21 12:26:09 2014
;; MSG SIZE rcvd: 106
real 0m1.013s
user 0m0.004s
sys 0m0.004s
top
, é um novo servidor, por isso quase não há carregamento:
Cpu(s): 0.2%us, 0.0%sy, 0.0%ni, 99.5%id, 0.3%wa, 0.0%hi, 0.0%si, 0.0%st
Mem: 1903696k total, 1310776k used, 592920k free, 311492k buffers
Swap: 4095992k total, 0k used, 4095992k free, 822692k cached
UPDATE (telnet):
# telnet 127.0.0.1 25
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
220 m1.example.com ESMTP Sendmail 8.14.4/8.14.4; Tue, 25 Mar 2014 14:47:04 +0800
HELO 127.0.0.1
250 m1.example.com Hello localhost [127.0.0.1], pleased to meet you
AUTH LOGIN
334 VXNlcm5hbWU6
bWUuY29t
334 UGFzc3dvcmQ6
cGFzc3dvcmQ=
235 2.0.0 OK Authenticated
MAIL FROM: [email protected]
250 2.1.0 [email protected]... Sender ok
RCPT TO: [email protected]
250 2.1.5 [email protected]... Recipient ok
DATA
354 Enter mail, end with "." on a line by itself
Testing 12345
.
250 2.0.0 s2P6l4Dj012326 Message accepted for delivery
QUIT
221 2.0.0 m1.example.com closing connection
Connection closed by foreign host.
Observe que MAIL FROM
e RCPT TO
levam cerca de 20 segundos até que OK
seja retornado. Os outros comandos respondem instantaneamente.
UPDATE, FEATURE ('delay_checks') :
Ativar FEATURE('delay_checks')
melhora muito o tempo de resposta de 30 segundos para aproximadamente 10 segundos. O atraso de cerca de 10 segundos é entre MAIL FROM:
e Sender ok
:
MAIL FROM: [email protected]
(- 10 second delay -)
250 2.1.0 [email protected]... Sender ok
ATUALIZAR novamente, parece que o atraso é muito semelhante ao descrito no livro Sendmail por Bryan Costales, página 258 :
NãoéumproblemadeDNS,poisdig
enslookup
respondemrapidamente:
#timenslookupmta5.am0.yahoodns.netServer:8.8.8.8Address:8.8.8.8#53Non-authoritativeanswer:Name:mta5.am0.yahoodns.netAddress:66.196.118.240Name:mta5.am0.yahoodns.netAddress:98.138.112.34Name:mta5.am0.yahoodns.netAddress:66.196.118.37Name:mta5.am0.yahoodns.netAddress:98.138.112.32Name:mta5.am0.yahoodns.netAddress:98.136.217.203Name:mta5.am0.yahoodns.netAddress:98.138.112.33Name:mta5.am0.yahoodns.netAddress:98.138.112.38Name:mta5.am0.yahoodns.netAddress:63.250.192.46real0m1.016suser0m0.001ssys0m0.006s
UPDATEcomosendmail.mc:
#cat/etc/mail/sendmail.mc|grep-v"^dnl"
divert(-1)dnl
include('/usr/share/sendmail-cf/m4/cf.m4')dnl
VERSIONID('setup for linux')dnl
OSTYPE('linux')dnl
define('confLOG_LEVEL', '14')dnl
define('SMART_HOST', 'mail03.example.com')dnl
define('confDEF_USER_ID', ''8:12'')dnl
define('confTO_CONNECT', '1m')dnl
define('confTRY_NULL_MX_LIST', 'True')dnl
define('confDONT_PROBE_INTERFACES', 'True')dnl
define('PROCMAIL_MAILER_PATH', '/usr/bin/procmail')dnl
define('ALIAS_FILE', '/etc/aliases')dnl
define('STATUS_FILE', '/var/log/mail/statistics')dnl
define('UUCP_MAILER_MAX', '2000000')dnl
define('confUSERDB_SPEC', '/etc/mail/userdb.db')dnl
define('confPRIVACY_FLAGS', 'authwarnings,novrfy,noexpn,restrictqrun')dnl
define('confAUTH_OPTIONS', 'A y')dnl
define('confCW_FILE', '/etc/mail/local-host-names')dnl
define('confDOMAIN_NAME', 'domain.example.com')dnl
define('confMAX_MESSAGE_SIZE','23271520')dnl
TRUST_AUTH_MECH('LOGIN PLAIN DIGEST-MD5 CRAM-MD5')dnl
define('confAUTH_MECHANISMS', 'LOGIN PLAIN DIGEST-MD5 CRAM-MD5')dnl
define('confTO_QUEUERETURN', '1d')dnl
define('confTO_IDENT', '0')dnl
FEATURE('delay_checks')dnl
FEATURE('no_default_msa', 'dnl')dnl
FEATURE('smrsh', '/usr/sbin/smrsh')dnl
FEATURE('mailertable', 'hash -o /etc/mail/mailertable.db')dnl
FEATURE('virtusertable', 'hash -o /etc/mail/virtusertable.db')dnl
FEATURE(redirect)dnl
FEATURE(always_add_domain)dnl
FEATURE(use_cw_file)dnl
FEATURE(use_ct_file)dnl
FEATURE(local_procmail, '', 'procmail -t -Y -a $h -d $u')dnl
FEATURE('access_db', 'hash -T<TMPF> -o /etc/mail/access.db')dnl
FEATURE('blacklist_recipients')dnl
EXPOSED_USER('root')dnl
DAEMON_OPTIONS('Port=smtp,Addr=0.0.0.0, Name=MTA M=a')dnl
FEATURE('accept_unresolvable_domains')dnl
LOCAL_DOMAIN('localhost.localdomain')dnl
MASQUERADE_AS('example.com')dnl
FEATURE(masquerade_entire_domain)dnl
MAILER(smtp)dnl
MAILER(procmail)dnl