可扩展的数据库查询
我有一个 YouTube 风格的网站,但它以图片为中心。
在主页上,我想在有史以来最流行的图片上方显示已上传的最新图片。
当每个用户访问页面时,为他们检查最新图像并显示它们,进行数据库/缓存查询是个好主意吗?或者我应该采取另一种方式来确保数据库不会不断被请求淹没最新发布的图片?
也许某种批处理作业?
有什么想法吗?
I have a youtube style site but it revolves around pictures.
On the homepage I want to show latest pictures that have been uploaded above the most popular pictures of all time.
Is it a good idea to do a database/cache query for every user when they hit the page in order to check what the latest images are and display them or should I do this another way to ensure the database isn't constantly flooded with requests for the latest posted pictures?
Maybe some sort of batch job?
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以在这里做的最基本的主动操作是缓存数据库查询的结果 - 无论是在您的应用程序代码中(不太优选),还是在可集成到您的网络“堆栈”中的现有基础设施中,例如 Memcached 之类的东西:
http://memcached.org/
这帮助许多数据库支持的站点实现了某种最低水平的可扩展性/性能。
根据您的数据库,您还可以将此类查询缓存为数据库功能本身的一部分,但如果您可以在这些查询到达数据库之前拦截它们,那就更好了。
The most basic proactive thing you can do here is to cache the results of the DB query - either in your app code (less preferable) or in an existing piece of infrastructure integrate-able in your web "stack", for example something like Memcached:
http://memcached.org/
This has helped many a DB-backed site achieve some minimal level of scalability/performance.
Depending on your DB, you can also cache such queries as part of DB functionality itself, but it's better if you can intercept such things before they even get to the DB.