使用IMAP COMPRESS(DEFLATE)是否值得? [英] Is it worthwhile using IMAP COMPRESS (DEFLATE)?

查看:130
本文介绍了使用IMAP COMPRESS(DEFLATE)是否值得?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Gmail支持IMAP COMPRESS扩展( RFC4978 ),特别是 RFC1951 ),又名zlib/gzip.

Gmail supports the IMAP COMPRESS Extension (RFC4978), specifically the DEFLATE algorithm (RFC1951) aka zlib/gzip.

我通常不是Python程序员,但我使用 Piers一起编写了快速测试脚本Lauder的imaplib2 用于确定启用或不启用压缩的性能.

I'm not normally a Python programmer but I threw a quick test script together using Piers Lauder's imaplib2 to determine performance with or without compression enabled.

from time import time
import imaplib2, string

def cb((response, cb_arg, error)):
        typ, data = response
        #print 'Message %s\n%s\n' % (cb_arg, data[0][5])

IMAP_SERVER='imap.gmail.com'
IMAP_PORT=993
IMAP_USERNAME='*********'
IMAP_PASSWORD='*********'

def gogmail(compress):
    start = time()
    M = imaplib2.IMAP4_SSL(IMAP_SERVER, IMAP_PORT, debug=0)
    M.login(IMAP_USERNAME, IMAP_PASSWORD)
    if(compress):
        M.enable_compression()
    M.SELECT(readonly=True)
    typ, data = M.SEARCH(None, 'ALL')
    fetch_list = string.split(data[0])[-100:]
    for num in fetch_list:
        M.FETCH(num, '(RFC822)', callback=cb, cb_arg=num)   
    M.LOGOUT()
    end = time()
    print end - start

print 'Compressed  '
print '------------'

for x in range(0, 50):
    gogmail(1)

print 'Uncompressed'
print '------------'

for x in range(0, 50):
    gogmail(0)

如果我在Python代码中犯了一个明显的新手错误,请纠正我.

我已经运行了几次这个测试脚本.有时,压缩访问的平均平均值更快,有时则不是.平均平均值绝不会有太大差异,访问时间也不会有很大的变化(一次收件箱内100条消息的访问可能需要4到17秒之间的任何时间).一致的结果将使我的决定更加容易!访问是通过SSL进行的,我当时在想,其中可能存在一些固有的压缩(我不知道).

I've run this test script a couple of times. Sometimes the mean average of compressed accesses is faster, sometimes not. There is never very much difference in mean average and a great deal of variation in access times (a single inbox access of 100 messages can take anywhere between 4 and 17 seconds). Consistent results would make my decision easier! Access is via SSL I was thinking that maybe there is some inherent compression in that (I don't know).

您认为在访问Gmail IMAP时值得使用压缩功能吗?

顺便说一句,我想使用JavaMail(而不是Python),但是我知道我需要对JavaMail进行大量自定义以支持压缩(也许使用杰西).有人做过吗?会值得吗?

Incidentally, I would like to use JavaMail (rather than Python) but I understand I would need to customise JavaMail significantly to support compression (maybe using Jessie). Has somebody done this already? Would it be worthwhile?

我感谢您的反馈.非常感谢.

I appreciate the feedback. Many Thanks.

推荐答案

我认为启用压缩不会带来很大的不同,仅仅是因为100条消息是微小数据量.假设一封邮件为1KB(长纯文本邮件),则您的收件箱为100KB.假设压缩率为5:1(最好是不太可能),那么压缩后的下载量现在为20KB.

I don't think enabling compression will make a great difference, simply because 100 messages is a tiny amount of data. Suppose one message is 1KB (a long plaintext message), so that your inbox is 100KB. Let's assume a compression ratio of 5:1 (which is unlikely at best), so that the compressed download is now 20KB.

这些天,任何合理的Internet连接都至少以1Mbps或125KB/s的速度运行.因此,在这些被高估的假设下,您可以节省不到一秒钟的数据传输成本.连接滞后和gmail端的处理使这一点相形见

Any sane internet connection these days runs at least at 1Mbps, or 125KB/s. So under these way-overestimated assumptions, you'd save somewhere under a second of data transmission costs. This is being dwarfed by the connection lag and the processing on gmail's side.

另一方面,启用压缩会给您带来什么损失?

On the other hand, what do you lose by enabling compression?

这篇关于使用IMAP COMPRESS(DEFLATE)是否值得?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆