简体   繁体   English

如何使用Delphi 2010优化上传例程?

[英]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发送文件,(简化)算法基本上是:

  1. Split File into "slices" (256KB each) 将文件拆分为“切片”(每个256KB)
  2. For each slice, POST it to server 对于每个切片,将其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: 我知道这不是我的服务器的错...这是我仍然需要探索的想法:

  1. 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%),但现在可以降低恢复能力。

  2. I also thought about using SFTP / SSH, but I'm not sure if it's fast. 我也考虑过使用SFTP / SSH,但我不确定它是否很快。

  3. 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: 我愿意接受我可以实施的任何建议,包括命令行工具(如果许可证允许我将其与我的应用程序一起发货),前提是:

  1. Resumable upload is supported 支持可恢复上传
  2. Fast! 快速!
  3. Reasonable memory usage 合理的内存使用情况
  4. Secure & allow login/user authentication 安全并允许登录/用户身份验证

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.

相关问题 如何使用大文件I / O(读取,写入)和计算来优化例程? - How to optimize routine with large file I/O (read, writes) and computation? 如何使用子查询优化更新语句? - how to optimize update statement using subquery? 当使用CGContextDrawLinearGradient时,如何优化UITableViewCell渲染 - How to optimize UITableViewCell rendering, when using CGContextDrawLinearGradient 如何使用Excel Interop在与单元有关的方面优化工作簿创建的性能? - How to optimize the performance of a Workbook creation in concerns with the cells using the Excel Interop? 如何使用ARC优化Objective-C单例? - How can I optimize Objective-C singletons using ARC? 如何提高FORALL插入例程的性能? - How to improve performance of FORALL insert routine? 如何使用联接优化mysql表中的大量数据 - How to optimize massive amounts of data in mysql tables using a join 如何提高使用Delphi从表中加载Treeview节点的速度 - how to increase speed of loading treeview nodes from a table using delphi 如何使用Delphi从远程计算机获取性能数据 - How to get performance data from a remote computer using Delphi 如何优化mysql查询 - how to optimize the mysql Query
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM