如何实现FTP/HTTP的客户端带宽限制? [英] How do I implement client-side bandwidth throttling for FTP/HTTP?

查看:150
本文介绍了如何实现FTP/HTTP的客户端带宽限制?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的任务是编写一个客户端数据下载系统(在Linux上),该系统使用FTP或HTTP从外部合作伙伴向我们的本地站点下载TB级的数据.我们公司的网络管理员告诉我,我不能超过一定的带宽.对我来说,实现这种系统的最佳方法是什么?现有的图书馆是否存在?

I am tasked with writing a client-side data download system (on Linux) that uses FTP or HTTP to download terabyte-sized data from external partners to our local site. Our company's network admin tells me that I cannot exceed a certain bandwidth. What is the best way for me to implement such a system? Do existing libraries exist?

我愿意编写自己的FTP和HTTP客户端(在Linux上为C或Java),但希望不使用内核.我知道我可以限制我的FTP/HTTP客户端调用套接字read()的速率,但是如果服务器端调用write()的速度比我的限制快怎么办?

I am open to writing my own FTP and HTTP clients (in either C or Java on Linux) but would prefer to stay out of the kernel. I know that I can limit the rate at which my FTP/HTTP client calls a socket read(), but what happens if the server-side calls write() faster than my limit?

推荐答案

您可以在InputStream之上构建另一层:在read方法中,您可以算出到目前为止的字节数.如果字节数/秒超过特定限制,请让下载线程休眠一会儿. TCP的流控制负责其余的工作.

You could build another layer on top of an InputStream: In the read method, you can count the bytes so far. If the number of bytes/second exceed a certain limit, let the download thread sleep for a while. TCP's flow control does the rest.

这篇关于如何实现FTP/HTTP的客户端带宽限制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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