所以我用的是一个在数据库中大量存储图像的应用程序。你对此有什么看法?我更倾向于将位置存储在文件系统中,而不是直接存储在DB中。

你认为优点和缺点是什么?


当前回答

我将采用文件系统方法。不需要创建或维护带有映像的DB,从长远来看,这将为您节省一些主要的麻烦。

其他回答

如果你正在计划一个面向公众的网站,那么你不应该选择任何一个选项。您应该使用内容分发网络(CDN)。在互联网上传递大量静态内容时,CDN具有价格、可扩展性和速度优势。

将图像存储在文件系统中的另一个好处是,您不需要做任何特殊的事情来让客户端缓存它们……

...当然,除非图像不能通过文档根访问(例如身份验证障碍),在这种情况下,你需要检查你的代码正在发送的缓存控制头。

我将采用文件系统方法。正如其他一些人所指出的,大多数web服务器被构建为从文件路径发送图像。如果您不需要从数据库中写入或输出BLOB字段,那么您将获得更高的性能。当内容不变或希望限制数据库负载时,将图像存储在文件系统中可以更容易地设置静态页面。

我负责一些管理许多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

如果您没有使用SQL Server 2008,并且有充分的理由将特定的映像文件放在数据库中,那么您可以采用“两者兼备”的方法,将文件系统用作临时缓存,并将数据库用作主存储库。

例如,您的业务逻辑可以在提供映像文件之前检查该映像文件是否存在于磁盘上,并在必要时从数据库检索。这为你购买了多个web服务器的能力和更少的同步问题。