Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How bottle return binary files

I want to make bottle python web service to serve binary files like pdf, picture and exe with authentication.

Is it possible to serve all this files using bottle? I have hard time finding a tutorial for that.

How about the performance? Does bottle python handle hundreds of thousands downloads simultaneously?

I am planning to use it with nginx uwsgi.

like image 759
Alvin Avatar asked Oct 21 '22 15:10

Alvin


2 Answers

It is definately possible to serve these files using bottle. You simply serve them as static files. As far as authentication goes, I do not believe bottle comes with authentication support ( as far as I know ). When it comes to performance though, this is an area when it really depends on how you deploy it. In a regular threaded environment, where each request gets it's own regular thread, I highly doubt your server will be able to comfortably serve hundreds of thousands of requests at the same time. However, it is noted in the documentation, that greenlets may be able to let you overcome this issue.

Resources:

Bottle static file serving: http://bottlepy.org/docs/dev/tutorial.html#routing-static-files

Bottle greenlets: http://bottlepy.org/docs/dev/async.html#greenlets-to-the-rescue

like image 185
IT Ninja Avatar answered Oct 31 '22 14:10

IT Ninja


If you are not in a hurry i suggest you to try uWSGI 1.9 (it is still in development but the first stable release will be in 10 days) and use offload-threads = n (set it to the number of cpus). In that way when you send a file from your app it will be asynced (and non blocking) served by a different thread, suddenly freeing your worker. Offloading is available in 1.4 too but it is not automatic for apps as in 1.9

like image 40
roberto Avatar answered Oct 31 '22 16:10

roberto