Restrict download file bandwidth/speed in Servlet

后端 未结 2 982
小鲜肉
小鲜肉 2020-12-15 12:27

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

相关标签:
2条回答
  • 2020-12-15 12:54

    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 ?

    Yes, it could.

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

    NIO won't help per se. It certainly won't prevent the low-bandwidth responses tying up threads for long periods of time.

    I think what you would need to do is to implement downloads in a special web container. I'm not sure, but I think that Servlet 3.0 with async mode might do the trick.

    0 讨论(0)
  • 2020-12-15 12:58

    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!

    0 讨论(0)
提交回复
热议问题