Iris: i want to write a http download service,is there a method to limit download speed?

Created on 26 Apr 2020  ·  11Comments  ·  Source: kataras/iris

for example:
http://127.0.0.1/file/xxx is used to download file names 'xxx',i want to use a middleware to dynamically limit network speed.
Can you help me? QAQ

implemented idea

Most helpful comment

Hello @CulionBEAR the next release will contain the SendFileWithRate which limits the dl speed. Thanks for opening this issue.

https://github.com/kataras/iris/blob/d36741b77944963e5f0c86032bcfec274901e21b/_examples/file-server/send-files/main.go#L22-L31

All 11 comments

Hello @CulionBEAR, any 3rd-party rate limiter/throttler should do the job. Please search on google or anywhere else for a suitable for your case and post it down so I can provide you an example with that and iris integration.

Hell @CulionBEAR again. I did a research and there is literally not enough information on how to do that correctly with Go, so your question has a meaning, you couldn't find something too but you need it, and here we are. I am preparing a new feature, limit requests and limit download (maybe upload too) speed, while keeping the support of Content-Range and Accept-Ranges too. This is marked as an idea for the upcoming Iris release. I'll keep you posted guys.

Hello @CulionBEAR the next release will contain the SendFileWithRate which limits the dl speed. Thanks for opening this issue.

https://github.com/kataras/iris/blob/d36741b77944963e5f0c86032bcfec274901e21b/_examples/file-server/send-files/main.go#L22-L31

Hello @CulionBEAR the next release will contain the SendFileWithRate which limits the dl speed. Thanks for opening this issue.

https://github.com/kataras/iris/blob/d36741b77944963e5f0c86032bcfec274901e21b/_examples/file-server/send-files/main.go#L22-L31

I think it would be more appropriate if the src be a reader instead of string

@kataras @axetroy thank you for your answer!!!Due to my personal reasons, I'm sorry that I didn't reply in time!I'm looking forward to the next version!

Hello @CulionBEAR the next release will contain the SendFileWithRate which limits the dl speed. Thanks for opening this issue.

https://github.com/kataras/iris/blob/d36741b77944963e5f0c86032bcfec274901e21b/_examples/file-server/send-files/main.go#L22-L31

I think it would be more appropriate if the src be a reader instead of string

Hello, for io.ReadSeeker we have the ServeContentWithRate.

@kataras @axetroy thank you for your answer!!!Due to my personal reasons, I'm sorry that I didn't reply in time!I'm looking forward to the next version!

Hey, no worries! Hope you are fine. Next version will be released the next week, however u can already use and try it with go get github.com/kataras/iris/v12@master inside ur project dir. Head over to the master/readme.md for changes/new features.

@kataras @axetroy thank you for your answer!!!Due to my personal reasons, I'm sorry that I didn't reply in time!I'm looking forward to the next version!

Hey, no worries! Hope you are fine. Next version will be released the next week, however u can already use and try it with go get github.com/kataras/iris/v12@master inside ur project dir. Head over to the master/readme.md for changes/new features.

Thank you for your hard work!
But I still have some questions.
Can multi-thread downloads break through this speed limit?
Can SendFileWithRate replace Nginx+X-Accel's download station solution to be used in a production environment?

Hello @toadzhou

Can SendFileWithRate replace Nginx+X-Accel's download station solution to be used in a production environment?

Nginx's X-Sendfile (or X-Accel) has nothing to do with Rate limiting (as far as I know), it's just a nginx light feature that you can also integrate with Iris to able to give access (after permission checks and e.t.c. inside your iris handler) to "private" files through a custom nginx's header.

Can multi-thread downloads break through this speed limit?

SendFile and SendFileWithRate both support seeking and range (Accept-Ranges, partial content). So I assume yes. You can test it by downloading master branch: go get github.com/kataras/iris/v12@master.

Hi,@kataras

X-Sendfile (X-Accel) has nothing to do with the speed limit, he is only a back-end logic control, X-Accel-Limit-Rate is also implemented with the limit_rate in NGINX.

Does it add an option to support the total traffic speed limit? It means that no matter how many threads you open, the total speed of downloading them is the same.

For example, I want to limit the speed of 500k, but I don't want to limit the number of his connections, because there will be certain problems. I need him to keep the speed at 500k during single-thread or multi-thread download. There are some problems with existing native nginx modules. Someone made a third-party module for this, but it seems to have stopped updating. https://github.com/bigplum/Nginx-limit-traffic-rate-module

This may not be the scope of iris. After all, most of the front-end static processing should be left to NGINX processing. I am just considering the possibility of using iris or golang instead of NGINX..

Yes...did you check the caddy server? It is nginx alternative written in Go, try open or link this issue there and ask for help, lets see what the solution may be.

Was this page helpful?
0 / 5 - 0 ratings