[英]How to optimize upload routine using Delphi 2010?
My yet to be released Delphi 2010 application allows users to upload their files to my servers. 我尚未发布的 Delphi 2010应用程序允许用户将他们的文件上传到我的服务器。 Right now I'm using HTTPS POST to send the files, the (simplified) algorithm is basically:
现在我正在使用HTTPS POST发送文件,(简化)算法基本上是:
ie. 即。 for a 1MB file:
对于1MB文件:
--> Get Slice #1 (256KB)
--> Upload Slice #1 using TidHTTP.Post()
--> Get Slice #2 (256KB)
--> Upload Slice #2 using TidHTTP.Post()
--> Get Slice #3 (256KB)
--> Upload Slice #3 using TidHTTP.Post()
--> Get Slice #4 (256KB)
--> Upload Slice #4 using TidHTTP.Post()
I'm using Indy 10 . 我正在使用Indy 10 。 I (ab)used my profiler over and over and there are not much left to optimize except changing the upload routine itself.
我(ab)一遍又一遍地使用我的探查器,除了更改上传例程本身之外,没有太多要优化。
I'm also using multi-threading , and even though I did my best to optimize my code, my benchmarks still tell me I can do better (there are other well optimized software that do achieve a much better timing...almost twice as fast as my upload routine!) 我还使用多线程 ,尽管我尽了最大努力来优化我的代码,我的基准仍然告诉我,我可以做的更好(也有其他很好的优化软件,实现做一个更好的时机......几乎两倍快速上传例程!)
I know it's not my server's fault...here are the ideas that I still need to explore: 我知道这不是我的服务器的错...这是我仍然需要探索的想法:
I tried grouping slices in a single POST, naturally this resulted in a performance boost (20-35%) but resuming capability is now reduced. 我尝试在单个POST中对切片进行分组,这自然会导致性能提升(20-35%),但现在可以降低恢复能力。
I also thought about using SFTP / SSH, but I'm not sure if it's fast. 我也考虑过使用SFTP / SSH,但我不确定它是否很快。
Use web sockets to implement resumable upload (like this component ), I'm not sure about speed either. 使用Web套接字实现可恢复上传( 如此组件 ),我也不确定速度。
Now my question is: is there something I can do to speed up my upload? 现在我的问题是:我有什么办法可以加快上传速度吗? I'm open to any suggestion that I can implement, including commandline tools (if license allows me to ship it with my application), provided that:
我愿意接受我可以实施的任何建议,包括命令行工具(如果许可证允许我将其与我的应用程序一起发货),前提是:
Also, because of major security concerns, FTP is a not something I'd want to implement. 此外,由于主要的安全问题,FTP不是我想要实现的东西。
Thanks a lot! 非常感谢!
I would suggest doing a single TIdHTTP.Post()
for the entire file without chunking it at all. 我建议为整个文件做一个单独的
TIdHTTP.Post()
,而不需要对它进行分块。 You can use the TIdHTTP.OnWork...
events to keep track of how many bytes were sent to the server so you know where to resume from if needed. 您可以使用
TIdHTTP.OnWork...
事件来跟踪发送到服务器的字节数,以便您知道在需要时从何处继续。 When resuming, you can use the TIdHTTP.Request.CustomHeaders
property to include a custom header that tells the server where you are resuming from, so it can roll back its previous file to the specfiied offset before accepting the new data. 恢复时,您可以使用
TIdHTTP.Request.CustomHeaders
属性来包含一个自定义标头,告诉服务器您要从哪里恢复,因此它可以在接受新数据之前将其先前的文件回滚到指定的偏移量。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.