My specific situation
我的具体情况
Property management web site where users can upload photos and lease documents. For every apartment unit, there might be 4 photos, so there won't be an overwhelming number of photo in the system.
物业管理网站,用户可以上传照片和租赁文件。对于每个公寓单元,可能有4张照片,因此系统中不会有大量照片。
For photos, there will be thumbnails of each.
对于照片,每个都会有缩略图。
My question
My #1 priority is performance. For the end user, I want to load pages and show the image as fast as possible.
我的首要任务是表现。对于最终用户,我想加载页面并尽快显示图像。
Should I store the images inside the database, or file system, or doesn't matter? Do I need to be caching anything?
我应该将图像存储在数据库或文件系统中,还是无关紧要?我需要缓存任何东西吗?
Thanks in advance!
提前致谢!
6 个解决方案
#1
While there are exceptions to everything, the general case is that storing images in the file system is your best bet. You can easily provide caching services to the images, you don't need to worry about additional code to handle image processing, and you can easily do maintenance on the images if needed through standard image editing methods.
虽然一切都有例外,但一般情况是将文件存储在文件系统中是最好的选择。您可以轻松地为图像提供缓存服务,您无需担心处理图像处理的其他代码,并且如果需要,您可以通过标准图像编辑方法轻松地对图像进行维护。
It sounds like your business model fits nicely into this scenario.
听起来您的商业模式非常适合这种情况。
#2
File system. No contest. The data has to go through a lot more layers when you store it in the db.
文件系统。没有比赛。将数据存储在数据库中时,数据必须经过更多层。
Edit on caching: If you want to cache the file while the user uploads it to ensure the operation finishes as soon as possible, dumping it straight to disk (i.e. file system) is about as quick as it gets. As long as the files aren't too big and you don't have too many concurrent users, you can 'cache' the file in memory, return to the user, then save to disk. To be honest, I wouldn't bother.
编辑缓存:如果要在用户上传文件时缓存文件以确保操作尽快完成,则将其直接转储到磁盘(即文件系统)的速度与获取速度一样快。只要文件不是太大并且您没有太多并发用户,您就可以将文件“缓存”到内存中,返回给用户,然后保存到磁盘。说实话,我不会打扰。
If you are making the files available on the web after they have been uploaded and want to cache to improve the performance, file system is still the best option. You'll get caching for free (may have to adjust a setting or two) from your web server. You wont get this if the files are in the database.
如果您在上载文件后在Web上提供文件并希望缓存以提高性能,则文件系统仍然是最佳选择。您将从Web服务器免费获得缓存(可能需要调整一两个设置)。如果文件在数据库中,您将无法获得此信息。
After all that it sounds like you should never store files in the database. Not the case, you just need a good reason to do so.
毕竟,听起来你永远不应该将文件存储在数据库中。不是这样,你只需要一个很好的理由这样做。
#3
Definitely store your images on the filesystem. One concern that folks don't consider enough when considering these types of things is bloat; cramming images as binary blobs into your database is a really quick way to bloat your DB way up. With a large database comes higher hardware requirements, more difficult replication and backup requirements, etc. Sticking your images on a filesystem means you can back them up / replicate them with many existing tools easily and simply. Storage space is far easier to increase on filesystem than in database, as well.
绝对将图像存储在文件系统中。在考虑这些类型的事情时,人们认为不够的一个问题是膨胀;将图像作为二进制blob填充到数据库中是一种非常快速的方式来扩展数据库。使用大型数据库会带来更高的硬件要求,更复杂的复制和备份要求等。在文件系统上粘贴图像意味着您可以轻松简单地使用许多现有工具备份/复制它们。存储空间在文件系统上比在数据库中更容易增加。
#4
Comment to the Sheepy's answer.
评论Sheepy的答案。
In common storing files in SQL is better when file size less than 256 kilobytes, and worth when it greater 1 megabyte. So between 256-1024 kilobytes it depends on several factors. Read this to learn more about reasons to use SQL or file systems.
通常,当文件大小小于256千字节时,SQL中的存储文件更好,而当大小超过1兆字节时则值得。因此,在256-1024千字节之间,它取决于几个因素。阅读本文以了解有关使用SQL或文件系统的原因的更多信息。
#5
a DB might be faster than a filesystem on some operations, but loading a well-identified chunk of data 100s of KB is not one of them.
在某些操作中,DB可能比文件系统更快,但加载一个明确标识的KB数据块不是其中之一。
also, a good frontend webserver (like nginx) is way faster than any webapp layer you'd have to write to read the blob from the DB. in some tests nginx is roughly on par with memcached for raw data serving of medium-sized files (like big HTMLs or medium-sized images).
另外,一个好的前端网络服务器(比如nginx)比你必须编写的任何webapp层要快得多,以便从数据库中读取blob。在某些测试中,对于中型文件(如大型HTML或中型图像)的原始数据服务,nginx大致与memcached相当。
go FS. no contest.
去FS。没有比赛。
#6
Maybe on a slight tangent, but in this video from the MySQL Conference, the presenter talks about how the website smugmug uses MySQL and various other technologies for superior performance. I think the video builds upon some of the answers posted here, but also suggest ways of improving website performance outside the scope of the DB.
也许略微相切,但在MySQL会议的这段视频中,主持人谈到了网站smugmug如何使用MySQL和各种其他技术以获得卓越的性能。我认为该视频建立在此处发布的一些答案的基础上,但也提出了在DB范围之外提高网站性能的方法。
#1
While there are exceptions to everything, the general case is that storing images in the file system is your best bet. You can easily provide caching services to the images, you don't need to worry about additional code to handle image processing, and you can easily do maintenance on the images if needed through standard image editing methods.
虽然一切都有例外,但一般情况是将文件存储在文件系统中是最好的选择。您可以轻松地为图像提供缓存服务,您无需担心处理图像处理的其他代码,并且如果需要,您可以通过标准图像编辑方法轻松地对图像进行维护。
It sounds like your business model fits nicely into this scenario.
听起来您的商业模式非常适合这种情况。
#2
File system. No contest. The data has to go through a lot more layers when you store it in the db.
文件系统。没有比赛。将数据存储在数据库中时,数据必须经过更多层。
Edit on caching: If you want to cache the file while the user uploads it to ensure the operation finishes as soon as possible, dumping it straight to disk (i.e. file system) is about as quick as it gets. As long as the files aren't too big and you don't have too many concurrent users, you can 'cache' the file in memory, return to the user, then save to disk. To be honest, I wouldn't bother.
编辑缓存:如果要在用户上传文件时缓存文件以确保操作尽快完成,则将其直接转储到磁盘(即文件系统)的速度与获取速度一样快。只要文件不是太大并且您没有太多并发用户,您就可以将文件“缓存”到内存中,返回给用户,然后保存到磁盘。说实话,我不会打扰。
If you are making the files available on the web after they have been uploaded and want to cache to improve the performance, file system is still the best option. You'll get caching for free (may have to adjust a setting or two) from your web server. You wont get this if the files are in the database.
如果您在上载文件后在Web上提供文件并希望缓存以提高性能,则文件系统仍然是最佳选择。您将从Web服务器免费获得缓存(可能需要调整一两个设置)。如果文件在数据库中,您将无法获得此信息。
After all that it sounds like you should never store files in the database. Not the case, you just need a good reason to do so.
毕竟,听起来你永远不应该将文件存储在数据库中。不是这样,你只需要一个很好的理由这样做。
#3
Definitely store your images on the filesystem. One concern that folks don't consider enough when considering these types of things is bloat; cramming images as binary blobs into your database is a really quick way to bloat your DB way up. With a large database comes higher hardware requirements, more difficult replication and backup requirements, etc. Sticking your images on a filesystem means you can back them up / replicate them with many existing tools easily and simply. Storage space is far easier to increase on filesystem than in database, as well.
绝对将图像存储在文件系统中。在考虑这些类型的事情时,人们认为不够的一个问题是膨胀;将图像作为二进制blob填充到数据库中是一种非常快速的方式来扩展数据库。使用大型数据库会带来更高的硬件要求,更复杂的复制和备份要求等。在文件系统上粘贴图像意味着您可以轻松简单地使用许多现有工具备份/复制它们。存储空间在文件系统上比在数据库中更容易增加。
#4
Comment to the Sheepy's answer.
评论Sheepy的答案。
In common storing files in SQL is better when file size less than 256 kilobytes, and worth when it greater 1 megabyte. So between 256-1024 kilobytes it depends on several factors. Read this to learn more about reasons to use SQL or file systems.
通常,当文件大小小于256千字节时,SQL中的存储文件更好,而当大小超过1兆字节时则值得。因此,在256-1024千字节之间,它取决于几个因素。阅读本文以了解有关使用SQL或文件系统的原因的更多信息。
#5
a DB might be faster than a filesystem on some operations, but loading a well-identified chunk of data 100s of KB is not one of them.
在某些操作中,DB可能比文件系统更快,但加载一个明确标识的KB数据块不是其中之一。
also, a good frontend webserver (like nginx) is way faster than any webapp layer you'd have to write to read the blob from the DB. in some tests nginx is roughly on par with memcached for raw data serving of medium-sized files (like big HTMLs or medium-sized images).
另外,一个好的前端网络服务器(比如nginx)比你必须编写的任何webapp层要快得多,以便从数据库中读取blob。在某些测试中,对于中型文件(如大型HTML或中型图像)的原始数据服务,nginx大致与memcached相当。
go FS. no contest.
去FS。没有比赛。
#6
Maybe on a slight tangent, but in this video from the MySQL Conference, the presenter talks about how the website smugmug uses MySQL and various other technologies for superior performance. I think the video builds upon some of the answers posted here, but also suggest ways of improving website performance outside the scope of the DB.
也许略微相切,但在MySQL会议的这段视频中,主持人谈到了网站smugmug如何使用MySQL和各种其他技术以获得卓越的性能。我认为该视频建立在此处发布的一些答案的基础上,但也提出了在DB范围之外提高网站性能的方法。