我正在創建一個應用程序來移動用戶收件箱中的郵件。目前我使用的是Gmail API,但我注意到向API發送請求比使用IMAP要慢得多。Gmail API messages.modify比IMAP慢40倍?
該方法非常簡單:我發送一批修改請求來更改一組電子郵件上的標籤,以便移動它們。我使用Gmail API的消息吞吐量爲每秒3.3個消息。爲了比較,IMAP吞吐量是130個消息/秒。
這裏是如何我目前使用BatchHttpRequests:
batch = BatchHttpRequest()
for gmailId in gmailIds:
batch.add(self.service.users().messages().modify(userId=self.user.email, id=gmailId, body=labels))
try:
batch.execute()
except errors.HttpError, error:
log_this_error(self.user.email, error.resp.status)
,這裏是我的IMAP的代碼,完成相同的任務:
# imap_conn is the user's authed connection
status, count = imap_conn.select(oldMailboxLabel)
if status == "OK":
count = int(count[0])
if count > 0:
messageNumbers = range(1, count + 1)
messageNumbers = ",".join(map(str, messageNumbers))
imap_conn.copy(messageNumbers, newMailboxLabel)
imap_conn.close()
imap_conn.delete(oldMailboxLabel)
else:
imap_conn.close()
else:
count = 0
我已經配料和gzip壓縮我的請求,並我試過使用字段來限制返回的信息量。所有這些都建議在他們的performance tips頁面上。我很難理解爲什麼這些請求需要很長時間才能完成。任何建議將不勝感激!
你能展示你的IMAP代碼進行比較嗎?另外,你在寫什麼語言?看起來它可能是Python? – Schwern
Hi @Schwern,我已經添加了IMAP代碼進行比較。是的,我正在用Python編寫 - 如果以前不清楚,我的錯誤!我發現IMAP比Gmail API有更好的消息吞吐量,這很奇怪 – frankjames