简体   繁体   English

关于 MimeMessage.Load 的 MimeKit 性能问题

[英]MimeKit Performance Question about MimeMessage.Load

I'm currently working on implementing support in printing for larger MIME files, from a 50MB threshold to 2000MB and i was doing some performance tests, and i noticed the MimeMessage.Load(stream) (this is the Load(Stream, CancellationToken) method) is having a filling my RAM memory really fast, and for some platforms the printer will run on, this will crash it.我目前正在实现对更大 MIME 文件的打印支持,从 50MB 阈值到 2000MB,我正在做一些性能测试,我注意到 MimeMessage.Load(stream)(这是Load(Stream, CancellationToken)方法) 正在非常快地填充我的 RAM 内存,并且对于打印机将运行的某些平台,这会使它崩溃。

Right now i am feeding to my Load method a NetworkStream and I read that using Load(Stream, Boolean, CancellationToken) could help me with my performance issue.现在我正在向我的 Load 方法提供一个 NetworkStream 并且我读到使用Load(Stream, Boolean, CancellationToken)可以帮助我解决我的性能问题。

Did anyone experienced the same and can maybe explain how does Load with persistent work and how i can avoid using too much memory?有没有人经历过同样的事情,也许可以解释一下 Load 是如何持久工作的,以及我如何避免使用太多内存?

Thank you in advanced!先谢谢了!

The Load(Stream stream, bool persistent, CancellationToken cancellationToken) method will avoid loading the content of each message into RAM unless the stream is not seekable. Load(Stream stream, bool persistent, CancellationToken cancellationToken)方法将避免将每条消息的内容加载到 RAM 中,除非该流不可查找。

NetworkStream is not seekable. NetworkStream不可查找。

If you are going to be loading messages that are 2GB in size, you need to copy the contents from the NetworkStream to a FileStream and then load the message using persistent: true .如果要加载 2GB 大小的消息,则需要将内容从NetworkStream复制到FileStream然后使用persistent: true加载消息。

In MimeKit, the persistent argument is telling the MimeParser that the stream will continue to exist and be readable after the parser has finished parsing the message.在 MimeKit 中, persistent参数告诉MimeParser ,在解析器完成消息解析,流将继续存在并可读。 When the MimeParser is told this, instead of loading the contents of the message into memory, it instead keeps track of the stream offsets and creates a proxy Stream object that can be used to read the content between the beginning and ending stream offsets of the original stream at a later point in time and sets that on the MimeMessage rather than a MemoryStream .MimeParser被告知这一点时,它不是将消息的内容加载到内存中,而是跟踪流偏移量并创建一个代理Stream对象,该对象可用于读取原始流的开始和结束流偏移量之间的内容流在稍后的时间点,并设置MimeMessage ,而不是一个MemoryStream

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM