views:

200

answers:

2

A lot of PDFs are stored inside MySQL as a BLOB field for each PDF file. The average file size is 500K each.

The Rails app will stream the :binary data as file downloads, where there is a user click on the download link.

Assume there is a maximum of 5 users downloading 5 PDFs concurrently, what kind of deployment setup parameters I should be aware of? e.g. for the case of thin:

thin start --servers 3

whether --servers 3 is good enough (or 5 or more is needed) for the above example?

The 2nd question is whether 'thin' a capable solution?

Thanks!

A: 

You can define one or two thin dedicated to your download. In your webserver you can made a different proxy distribution in your Rails Application and in your download url

shingara
+1  A: 

Firstly I don't think you should be storing files in a database. A better place would be in the file system, or alternatively in cloud storage like S3. If you were to use an attachment plugin like paperclip this is a very easy to setup.

However, lets assume you want to store your files in your database.

The problem with your current set up is that when you're sending your file your thin instance is blocking while your client downloads the data. This means if you have 3 thin instances and 3 people downloading pdfs then you're site will not respond to any requests.

Thankfully there is a solution to this problem which involves the x-sendfile header. The way this works is your thin instance sends the file to your webserver, for example nginx, which then serves the file directly.

Here's a great post on stackoverflow on how to set this up with nginx.

Which web server are you using?

jonnii
now thin is the server itself (not deployed yet):thin start -e test -p 8000 -s 5 -d
ohho