所以我用的是一个在数据库中大量存储图像的应用程序。你对此有什么看法?我更倾向于将位置存储在文件系统中,而不是直接存储在DB中。
你认为优点和缺点是什么?
所以我用的是一个在数据库中大量存储图像的应用程序。你对此有什么看法?我更倾向于将位置存储在文件系统中,而不是直接存储在DB中。
你认为优点和缺点是什么?
当前回答
我负责一些管理许多TB图像的应用程序。我们发现在数据库中存储文件路径是最好的。
这里有几个问题:
database storage is usually more expensive than file system storage you can super-accelerate file system access with standard off the shelf products for example, many web servers use the operating system's sendfile() system call to asynchronously send a file directly from the file system to the network interface. Images stored in a database don't benefit from this optimization. things like web servers, etc, need no special coding or processing to access images in the file system databases win out where transactional integrity between the image and metadata are important. it is more complex to manage integrity between db metadata and file system data it is difficult (within the context of a web application) to guarantee data has been flushed to disk on the filesystem
其他回答
这取决于你要存储的图像数量和它们的大小。我曾经使用数据库存储图像,我的经验是相当不错的。
在我看来,使用数据库存储图像的优点是,
A.你不需要FS结构来保存你的图像 B.当存储更多的项时,数据库索引比FS树执行得更好 C.智能调优的数据库在缓存查询结果方面表现良好 D.备份很简单。如果您设置了复制,并且内容从用户附近的服务器传递,那么它也可以很好地工作。在这种情况下,不需要显式同步。
如果你的图像很小(比如< 64k),并且你的db的存储引擎支持内联(记录中)blob,它可以进一步提高性能,因为不需要间接(实现了引用的局部性)。
当您处理少量大尺寸图像时,存储图像可能是一个坏主意。在db中存储图像的另一个问题是,像创建、修改日期这样的元数据必须由应用程序处理。
在数据库中存储图像仍然意味着图像数据最终位于文件系统中的某个位置,但被遮蔽,因此您不能直接访问它。
+压力:
数据库的完整性 它易于管理,因为您不必担心在添加或删除映像时保持文件系统同步
-维斯:
性能损失——数据库查找通常比文件系统查找慢 您不能直接编辑图像(裁剪,调整大小)
这两种方法都是常见的和实践的。看看优点和缺点。无论哪种方式,你都必须考虑如何克服缺点。在数据库中存储通常意味着调整数据库参数并实现某种缓存。使用文件系统要求您找到某种保持文件系统+数据库同步的方法。
假设:应用程序是基于web的
我很惊讶没有人真正提到这一点……委托给其他专家->使用第三方映像/文件托管提供商。
将文件存储在付费的在线服务上,比如
Amazon S3 Moso云存储
另一个StackOverflow线程在这里讨论这个。
这篇文章解释了为什么你应该使用第三方托管提供商。
太值得了。它们能有效地储存。没有带宽从你的服务器上传到客户端请求等等。
当然是文件系统。然后你可以使用所有的操作系统功能来处理这些图像-备份,web服务器,甚至只是使用imagemic之类的工具进行批量修改。如果您将它们存储在DB中,那么您需要编写自己的代码来解决这些问题。
我负责一些管理许多TB图像的应用程序。我们发现在数据库中存储文件路径是最好的。
这里有几个问题:
database storage is usually more expensive than file system storage you can super-accelerate file system access with standard off the shelf products for example, many web servers use the operating system's sendfile() system call to asynchronously send a file directly from the file system to the network interface. Images stored in a database don't benefit from this optimization. things like web servers, etc, need no special coding or processing to access images in the file system databases win out where transactional integrity between the image and metadata are important. it is more complex to manage integrity between db metadata and file system data it is difficult (within the context of a web application) to guarantee data has been flushed to disk on the filesystem