简体   繁体   中英

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.

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.

Did anyone experienced the same and can maybe explain how does Load with persistent work and how i can avoid using too much memory?

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.

NetworkStream is not seekable.

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 .

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. 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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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