所以我用的是一个在数据库中大量存储图像的应用程序。你对此有什么看法?我更倾向于将位置存储在文件系统中,而不是直接存储在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
其他回答
根据我的经验,我必须管理两种情况:图像存储在数据库和图像文件系统的路径存储在db。
第一个解决方案,数据库中的图像,有点“干净”,因为你的数据访问层将只需要处理数据库对象;但这只在你必须处理小数字的时候有用。
显然,当您处理二进制大对象时,数据库访问性能正在下降,数据库维度将增长很多,再次导致性能损失…通常数据库空间比文件系统空间要昂贵得多。
另一方面,在文件系统中存储大型二进制对象将导致您的备份计划必须同时考虑数据库和文件系统,这对于某些系统可能是一个问题。
使用文件系统的另一个原因是当你必须与第三方访问共享你的图像数据(或声音、视频等)时:在这一天,我正在开发一个web应用程序,它使用的图像必须从“外部”我的网络农场访问,以这样一种方式访问数据库来检索二进制数据是根本不可能的。所以有时候也会有设计上的考虑促使你做出选择。
在做出这种选择时,还要考虑在访问二进制对象时是否必须处理权限和身份验证:当数据存储在db中时,这些必要条件通常可以以更简单的方式解决。
没有人提到的是DB保证原子操作、事务完整性和处理并发性。对于文件系统,甚至引用完整性都不存在了——那么您如何知道您的文件名仍然是正确的呢?
如果你的文件系统中有你的图像,当你写一个新版本甚至删除文件时,有人正在读取文件-会发生什么?
我们使用blob是因为它们也更容易管理(备份、复制、传输)。他们为我们工作得很好。
我会选择两种解决方案,我的意思是……我将开发一个小组件(EJB),它将映像存储在DB中,并将映像存储到服务器的路径。只有当我们有一个新的图像或原始图像更新时,这个DB才会更新。然后,我还将该路径存储在业务DB中。
从应用程序的角度来看,我将始终使用文件系统(从业务DB检索路径),通过这种方式,我们将修复备份问题,并避免可能的性能问题。
唯一的缺点是我们将存储相同的图像2次…好的一点是内存很便宜,拜托!
我最近创建了一个PHP/MySQL应用程序,用于在MySQL表中存储pdf /Word文件(到目前为止每个文件的大小为40MB)。
优点:
上传的文件复制到备份服务器连同其他一切,不需要单独的备份策略(安心)。 设置web服务器稍微简单一些,因为我不需要有一个上传/文件夹,并告诉我所有的应用程序它在哪里。 我可以使用事务进行编辑以提高数据的完整性——我不必担心孤立的和丢失的文件
缺点:
mysqldump现在需要很长时间,因为其中一个表中有500MB的文件数据。 总的来说,与文件系统相比,内存/cpu效率不是很高
我认为我的实现是成功的,它满足了备份需求并简化了项目布局。对于使用该应用程序的20-30人来说,性能还不错。
我负责一些管理许多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