如何使用Delphi 2010优化上传例程? [英] How to optimize upload routine using Delphi 2010?

查看:241
本文介绍了如何使用Delphi 2010优化上传例程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的尚未发布:Delphi 2010应用程序允许用户将其文件上传到我的服务器。现在我使用HTTPS POST发送文件,(简化)算法基本上是:


  1. 将文件拆分为片(对于每个切片,将其POST到服务器

ie。对于1MB的文件:

   - >获取片#1(256KB)
- >使用TidHTTP.Post()上传Slice#1

- >获取切片#2(256KB)
- >使用TidHTTP.Post()上传Slice#2

- >获取片#3(256KB)
- >使用TidHTTP.Post()上传Slice#3

- >获取片#4(256KB)
- >上传Slice#4使用TidHTTP.Post()

我使用 Indy 10 <强>。我(ab)一遍又一遍地使用我的分析器,除了更改上传程序本身之外,还没有太多的优化。



我也使用线程,即使我尽力优化我的代码,但我的基准仍然告诉我我可以做得更好(还有其他优化最好的软件可以实现更好的时机..我的上传程序的速度是我的两倍!)



我知道这不是我的服务器的错误...这里是我仍然需要探索的想法:


  1. 我尝试在单个POST中分组切片,这自然导致性能提升(20-35%),但恢复能力现在已经减少


  2. 我也考虑过使用SFTP / SSH,但不知道是否快速。


  3. 使用网络套接字实现可恢复上传(例如此组件),我不知道速度。


现在我的问题是:我可以做些什么来加快我的上传速度吗?我可以使用我可以实现的任何建议,包括命令行工具(如果许可证允许我将其发送到我的应用程序),条件是:


  1. 支持可恢复上传

  2. 快速!

  3. 内存使用合理

  4. 安全&允许登录/用户认证

此外,由于主要的安全性问题,FTP不是我想要实现的。 p>

非常感谢!

解决方案

我建议做一个 TIdHTTP.Post()为整个文件,而无需重新整理。您可以使用 TIdHTTP.OnWork ... 事件来跟踪发送到服务器的字节数,以便您知道从哪里恢复。恢复时,您可以使用 TIdHTTP.Request.CustomHeaders 属性来包含一个自定义标头,该标头告诉服务器您正在恢复的位置,因此可以将其以前的文件回滚到在接受新数据之前指定的偏移量。


My yet to be released Delphi 2010 application allows users to upload their files to my servers. Right now I'm using HTTPS POST to send the files, the (simplified) algorithm is basically:

  1. Split File into "slices" (256KB each)
  2. For each slice, POST it to server

ie. for a 1MB file:

--> 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. I (ab)used my profiler over and over and there are not much left to optimize except changing the upload routine itself.

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.

  2. I also thought about using SFTP / SSH, but I'm not sure if it's fast.

  3. Use web sockets to implement resumable upload (like this component), I'm not sure about speed either.

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.

Thanks a lot!

解决方案

I would suggest doing a single TIdHTTP.Post() for the entire file without chunking it at all. 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. 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.

这篇关于如何使用Delphi 2010优化上传例程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆