在一个配置文件页面上进行多个查询的 MySQL 性能和优化是否会降低?
我正在社交网站上工作,该网站为每个用户都有一个个人资料页面。
个人资料页面包含:
- 有关用户、头像、爱好和信息的信息。等
- 他们的视频和照片
- 他们的朋友
- 他们的书签
- 他们观看的视频
目前我每次加载个人资料页面时都会执行 14 个不同的查询,其中一些查询如下:
- 检查是否允许查看者查看个人资料页面
- 获取个人资料信息
- 获取个人资料视频
- 获取个人资料照片
- 获取朋友列表
- 获取书签列表
- 获取他们观看的视频
我想知道提高性能和优化我的网站的最佳方法,或者我可以减少运行的查询数量。
MySQL 能处理这么大的负载吗?
如果它对我使用 innodb 引擎有帮助的话,我需要更快的更新速度以及关系。
谢谢 :)
I am working on social networking site, which has a profile page for each user.
The profile page contains:
- info about the user, avatar, hobbies & etc
- their videos and photos
- their friends
- their bookmarks
- videos they watched
At the moment i execute 14 different queries each time profile page is loaded, some of them listed below:
- check if the viewer is allowed to view the profile page
- get profile info
- get profile videos
- get profile photos
- get friend list
- get bookmark list
- get videos they watched
I would like to know best way to improve the performance and optimize my site, or can i reduce the number of queries i run.
Can MySQL handle this much load?
if it helps i am using innodb engine i needed faster updating speed as well realtionships.
thanks :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果它确实成为性能问题,这里有一些简单的方法会有所帮助:
如果您需要更认真地进行操作,您可以在数据库中创建一个新表,将某些查询的结果全部存储在一行中,并定期重新生成。然后让您的页面从中进行选择(然后您就可以在一个查询中获得所需的一切)。
但最重要的是:@Jason 所说的。如果性能确实成为一个问题(因为你变成了下一个推特或其他什么东西),那么使用硬件来解决问题可能比重写更便宜。
If it ever does become a performance issue, here are a couple of easy things that will help:
If you need to get more serious, you can create a new table in the database that stores the results of some of your queries all in one row, and regenerate it periodically. Then have your page select from that (then you have everything you need in one query).
But most importantly: what @Jason said. Chances are if performance does become an issue (because you turn into the next twitter or something), it'll be cheaper to throw hardware at the problem than to rewrite.
只要它们是短期运行的查询就可以了。采取任何措施来优化速度最多可能会给您带来一些额外的毫秒数。如果仍然困扰,你可以做一些缓存。
还查找
memcache
。As long as they are short-running queries it's okay. Doing anything to optimize speed might give you, at best, some additional milliseconds. If it still bothers, you could do some caching.
Lookup also
memcache
.