Which is Better ? Saving Files in Database or in File System
5 stars based on
I came across this gem on DZone this morning. What really bugs me, is how it fails to mention that this is a very bad idea. A relational database is not a filesystem. Files go on a filesystem. Repeat that a couple of times. The most compelling argument for this, is performance. I did a quick test. I did a google image search on stupidity and downloaded the first when is it bad idea to store binary files in the database images. I then wrote PHP scripts to serve them up when is it bad idea to store binary files in the database two ways:.
The results are the average of running Apache Benchmark 10 times: The best way to store your images or other binary files is on the filesystem. Every modern web server does a good or excellent job of serving up static content. Storing them in a database is by far the worst possible solution. You could have images in the database and use output cache on the web server.
I agree, having tried this a long time ago. My research came to the same conclusions that large images should be left out of BLOB fields. I did notice that if the imagery was small, say around an icon size that most databases handle this amount fairly well.
However, my stance parallels yours. Leave image data out of it. You gain advantages to having path data to images as well like being able to search the file name etc. When I have the time I might have a look at the effect of large blobs on overal database performance under load. Might make for interesting results.
Maybe you want to link data from an existing database with some files that you can access and update through a filesystem interface. IIRC there was a large company playing up how wonderful life could be when filesystem queries could be performed using SQL. Do I understand the results correctly? According to your benchmark on your server, you can only serve 50 images per second from a db?
That is very slow indeed. What sizes were the trading and long term equity appreciation option Did the difference increase with the image size? The three main problems with using a filesystem are:.
This is hard to implement. Any web app concerned with performance will have a cache of some sort. Your email address will not be published. Skip to content I came across this gem on DZone this morning. I then wrote PHP scripts to serve them up in two ways: So please, be sensible.
Store your files on a filesystem. The three main problems with using a filesystem are: Leave a Reply Cancel reply Your email address will not be published. Previous Post Previous Java 7 Performance. Next Post Next Character sets, time zones and hashes.