英文:
Downloading MIME content in Outlook Rest API is too slow
问题
我需要从Microsoft Graph的Outlook API中下载MIME内容。所有其他请求都没有问题,但有时获取MIME消息的终结点需要太长时间。
文档
https://learn.microsoft.com/en-us/graph/outlook-get-mime-message
我使用的终结点
https://graph.microsoft.com/v1.0/me/messages/{messageId}/$value
我调用它的方式
await _graphClient.Me.Messages["MailIdGoesHere"].Content.Request().GetAsync()
与它们的大小相比,下载时间异常长的消息的日志
- 8347字节,在4.2139115秒内下载
- 8566字节,在5.1931696秒内下载
- 5891字节,在8.2277588秒内下载
但并不是所有消息都很慢。较大的消息与这些异常消息相比,下载时间较短
- 83614字节,在0.2658916秒内下载
- 154325字节,在0.3164563秒内下载
我尝试批量处理这些请求,最多允许的API数量(目前为20个),结果没有改变。最终解析响应消息需要太长时间,最终总持续时间不受影响。
是否有其他方法可以获取Outlook API中邮件的原始MIME内容,或者这是否是已知问题?
英文:
I need to download MIME contents from Outlook API in Microsoft Graph. All other requests are completely fine, but endpoint for fetching the MIME message sometimes takes too much time.
Documentation
https://learn.microsoft.com/en-us/graph/outlook-get-mime-message
Endpoint I use
https://graph.microsoft.com/v1.0/me/messages/{messageId}/$value
Way I call it
await _graphClient.Me.Messages["MailIdGoesHere"].Content.Request().GetAsync()
Logs for messages that take unusual time to download compared to their sizes
- 8347 bytes, downloaded in 4.2139115 seconds
- 8566 bytes, downloaded in 5.1931696 seconds
- 5891 bytes, downloaded in 8.2277588 seconds
But not all messages are slow. Bigger messages are downloaded in less time compared to these unusual ones
- 83614 bytes, downloaded in 0.2658916 seconds
- 154325 bytes, downloaded in 0.3164563 seconds
I tried to batch these requests by maximum allowed number in API (20 at the moment), and result didn't change. Parsing the response messages take too much time in the end and eventually total duration is not affected.
Is there some other way to get raw MIME content of the mails in Outlook API or is it a known issue?
答案1
得分: 0
明白。
我当时同时进行了数十个请求。尽管它们被批处理并且请求是并行完成的,但发送20个MIME获取请求有点使Outlook API崩溃,甚至较小的消息也需要很长时间才能返回。
我使用了SemaphoreSlim,每次同时执行3个并发任务,并限制了所有这些请求以解决这个问题。
英文:
Got it.
I was doing tens of requests at the same time. Even though they are batched and requests are done in parallel, sending 20 MIME get requests kind of breaks the Outlook API and even smaller messages take long time to return.
I used SemaphoreSlim with 3 concurrent tasks at a time and throttled all these requests to fix this issue.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论