限制 Servlet 中的下载文件带宽/速度 [英] Restrict download file bandwidth/speed in Servlet

查看:27
本文介绍了限制 Servlet 中的下载文件带宽/速度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们得到了在集群模式下工作的高负载 Java 应用程序.

we got high-load java application which works in clustered mode.

我需要为我们的客户添加下载和上传文件的功能.为了存储文件,我要去用户 gridFs,不确定,这是最好的选择,但 mongo 可以集群,mongo 可以在差异节点之间复制数据.这正是我需要的.

I need to add ability to download and upload files for our customers. For storing files i'm going to user gridFs, not sure, it's best choice, but mongo can be clustered and mongo can replicate data between diff nodes. That's exactly what i need.

不同的用户组应该限制不同的带宽.基于某些业务规则,我应该限制某些用户的下载速度.我看到了几个解决方案

Different group of users should be limited with different bandwidth. Based of some business rules i should restrict download speed for some users. I saw few solutions for this

它们中的大多数都以相同的方式工作.

Most of them works same way.

  • 读取一堆字节
  • 睡眠线程
  • 重复

Mongo 只是为我提供 InputStrem,我可以从该流中读取并写入 servlet 输出流.我不确定这是有效的方法.另外我担心,用户可能会在下载过程中创建大量并发线程,这会影响性能.

Mongo simply provide me InputStrem and i can read from that stream and write to servlet output stream. I'm not sure it is valid approach. Also I'm afraid, that users can create a lot of concurent threads during download and it can hurt performance.

会不会是 servlet 容器的问题?

Could it be an issue for servlet container ?

如果这可能是一个问题,如何避免?可能使用 nio ?

If it could be an issue, how can it be avoided ? probably using nio ?

我更喜欢使用纯 java 解决方案.

I prefer to use pure java solution.

任何帮助将不胜感激.

推荐答案

漏桶令牌桶 算法可用于控制网络带宽.

Leaky bucket or token bucket algorithms can be used to control the network bandwidth.

我做了一些快速原型设计并实现了利用 Servlet 3.0 异步处理的算法.结果相当不错.可以在 GitHub 上找到完整的源代码.玩得开心!

I did some quick prototyping and implemented the algorithm leveraging Servlet 3.0 asynchronous processing. Results are pretty good. Full source code can be found on GitHub. Have fun!

这篇关于限制 Servlet 中的下载文件带宽/速度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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