I have an existing database containing some pictures in blob fields. For a web application I have to display them.
我有一个现有的数据库,其中包含blob字段中的一些图片。对于Web应用程序,我必须显示它们。
What's the best way to do that, considering stress on the server and maintenance and coding efforts.
考虑到服务器上的压力以及维护和编码工作,最好的方法是什么。
I can think of the following:
我能想到以下几点:
- "Cache" the blobs to external files and send the files to the browser.
- Read them from directly the database every time it's requested.
将blob“缓存”到外部文件并将文件发送到浏览器。
每次请求时直接从数据库中读取它们。
Some additionals facts:
一些额外的事实:
- I cannot change the database and get rid of the blobs alltogether and only save file references in the database (Like in the good ol' Access days), because the database is used by another application which actually requires the blobs.
- The images change rarely, i.e. if an image is in the database it mostly stays that way forever.
- There'll be many read accesses to the pictures, 10-100 pictures per view will be displayed. (Depending on the user's settings)
- The pictures are relativly small, < 500 KB
我无法更改数据库并完全摆脱blob并且只保存数据库中的文件引用(就像在“访问日”中那样),因为数据库由另一个实际需要blob的应用程序使用。
图像很少变化,即如果图像在数据库中,它大部分都会永远保持这种状态。
对图片进行多次读取访问,每个视图将显示10-100张图片。 (取决于用户的设置)
图片相对较小,<500 KB
2 个解决方案
#1
I would suggest a combination of the two ideas of yours: The first time the item is requested read it from the database. But afterwards make sure they are cached by something like Squid so you don't have to retrieve the every time they are requested.
我建议结合你的两个想法:第一次请求项目从数据库中读取它。但事后确保它们被像Squid这样的东西缓存,这样你就不必在每次请求时都检索它们。
#2
one improtant thing is to use proper HTTP cache control ... that is, setting expiration dates properly, responding to HEAD
requests correctly (not all plattforms/webservers allow that) ...
一个重要的事情是使用正确的HTTP缓存控制...即正确设置到期日期,正确响应HEAD请求(并非所有平台/网络服务器允许)...
caching thos blobs to the file system makes sense to me ... even more so, if the DB is running on another server ... but even if not, i think a simple file access is a lot cheaper, than piping the data through a local socket ... if you did cache the DB to the file system, you could most probably configure any webserver to do a good cache control for you ... if it's not the case already, you should maybe request, that there is a field to indicate the last update of the image, to make your cache more efficient ...
将thos blob缓存到文件系统对我来说是有意义的......更重要的是,如果DB在另一台服务器上运行......但即使不是,我认为简单的文件访问比通过管道传输数据要便宜得多一个本地套接字...如果你把数据库缓存到文件系统,你很可能会配置任何网络服务器为你做一个很好的缓存控制...如果不是这种情况,你应该请求,有一个字段,指示图像的上次更新,以使您的缓存更有效...
greetz
back2dos
#1
I would suggest a combination of the two ideas of yours: The first time the item is requested read it from the database. But afterwards make sure they are cached by something like Squid so you don't have to retrieve the every time they are requested.
我建议结合你的两个想法:第一次请求项目从数据库中读取它。但事后确保它们被像Squid这样的东西缓存,这样你就不必在每次请求时都检索它们。
#2
one improtant thing is to use proper HTTP cache control ... that is, setting expiration dates properly, responding to HEAD
requests correctly (not all plattforms/webservers allow that) ...
一个重要的事情是使用正确的HTTP缓存控制...即正确设置到期日期,正确响应HEAD请求(并非所有平台/网络服务器允许)...
caching thos blobs to the file system makes sense to me ... even more so, if the DB is running on another server ... but even if not, i think a simple file access is a lot cheaper, than piping the data through a local socket ... if you did cache the DB to the file system, you could most probably configure any webserver to do a good cache control for you ... if it's not the case already, you should maybe request, that there is a field to indicate the last update of the image, to make your cache more efficient ...
将thos blob缓存到文件系统对我来说是有意义的......更重要的是,如果DB在另一台服务器上运行......但即使不是,我认为简单的文件访问比通过管道传输数据要便宜得多一个本地套接字...如果你把数据库缓存到文件系统,你很可能会配置任何网络服务器为你做一个很好的缓存控制...如果不是这种情况,你应该请求,有一个字段,指示图像的上次更新,以使您的缓存更有效...
greetz
back2dos