Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Restrict download file bandwidth/speed in Servlet

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

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.

  • Read bunch of bytes
  • Sleep thread
  • Repeat

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.

Could it be an issue for servlet container ?

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

I prefer to use pure java solution.

Any help will be highly appreciated.

like image 925
user12384512 Avatar asked Feb 20 '11 22:02

user12384512


People also ask

How do I limit the amount of bandwidth used for downloads?

Choose Advanced options. Select Limit how much bandwidth is used for downloading updates in the background. Then use the slider to set the percentage of available bandwidth used for background downloads. Lower values use less bandwidth but cause updates to be delivered more slowly.

How do I limit the download or upload speed?

To limit an application’s download or upload speed, just check the appropriate box under DL Limit or UL Limit. To set a custom speed, click the “5 KB/s” in the DL Limit or UL Limit column and type in your desired speed. When you want to remove the limit, just uncheck the box. Option Three: Download TMeter Free

How to limit Internet download speed for particular file using Wget?

In this short article, we will show you how to limit internet download speed for particular file using wget command in Linux. When using wget, you can limit the file retrieval rate with the --limit-rate switch. The value can be expressed in bytes, kilobytes with the k suffix, or megabytes with the m suffix.

Can I restrict download speed on Windows 10?

You can restrict Windows Update’s download speed on Windows 10. Some applications also let you limit their bandwidth. But, for applications that don’t have that built in, you’ll need third-party software. Limiting bandwidth can be useful in different circumstances.


1 Answers

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

EDIT: 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!

like image 93
Tomasz Nurkiewicz Avatar answered Sep 29 '22 23:09

Tomasz Nurkiewicz