“带有附件的服务”中的MIME附件解析
我们有一个网络服务(所谓的“带附件的服务”),用户可以在其中发送带有请求的文件。用户最多可以上传 256 MB 的文件。我们有一个可行的解决方案,可以解析请求并保存文件,但速度很慢。有时,当发送大附件时,服务器返回超时。
我们按字节读取请求并查找边界标签(--b5a8d09eeeb161be29def84633d6f6fc
)。如果找到标签,则解析标头并读取附件文件的 Base64 编码数据。还有一个换行符的检查。
在我看来,这段代码中有很多循环,可以做得更好并提高性能。
是否有一些很好的例子是如何完成的,也许解析字符串(而不是字节数组)是更快的解决方案?或者也许还有其他方法?您建议采取什么措施来提高性能?
问候, 邪恶的
We have a webservice (so called "service with attachment") where users can send files with their requests. Users can upload up to 256 MB of files. We have a working solution that parses the request and saves the files, but it's slow. Sometimes when sending big attachments - server returns timeouts.
We read the request by bytes and looking for a boundary tags (--b5a8d09eeeb161be29def84633d6f6fc
). If tag is found then parse the header and read the attachments file base64 encoded data. Also there's a check for a newline characters.
In my opinion there's a lot of cycles in this code and it can be done better and improve the performance.
Is there some great examples how is this done and maybe parsing a string (not a byte array) is faster solution? Or maybe there's other approaches? What do you suggest to do to improve the performance?
Regards,
evilone
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好吧,我自己找到了答案。使用
Streamreader
和ReadLine()
函数比迭代byte[]
数组中的单个字节快约 40%。如果像 Pareen 建议的那样将压缩添加到请求中,那么速度会更快。Ok, found the answer myself. Using
Streamreader
andReadLine()
function is about 40% faster than iterating over single bytes inbyte[]
array. If compression is added to requests too like Pareen suggested then it can be more faster.也许您尝试使用 LZMA 压缩来压缩附件。
你可以从http://www.7-zip.org/sdk.html
May be you try compressing your attachments using LZMA compression.
U can download it from http://www.7-zip.org/sdk.html