当我的网站流量很大时,如何更改我使用的表?
好吧,我已经构建了一组运行的表,这些表旨在以更少的连接运行,但我想保留我的规范化数据库。当我的网站流量很大时,有办法在它们之间切换吗?
Well, I have built a set of tables that run are meant to run with fewer joins, but I want to keep my normalized database around. Is there a way to switch between them when my site has a lot of traffic?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果是为了简化您的查询,您可能需要 创建一个视图,它又可以捆绑一些连接。
If it is in order to simplify your queries, you might want to create a view which in turn can bundle some joins.
创建一个全局变量,每次访问页面时该变量都会递增,并重置为 0,每次递增每分钟递减 1,称为“
pages_accessed_per_一分钟
”。创建一个接受两个参数的函数,一个是上面提到的全局参数,另一个是油门限制:
throttleOn('pages_accessed_per_一分钟', '1000')
。如果每分钟访问的页面数增加超过某个点(本例中为 1000),请交换使用其他数据库的备用 php 脚本。
不过,我不能 100% 确定我正确使用了 include_once 。
我还发现大多数服务器都有一个符号链接到共享主机上用户主目录的日志。可以使用
$tail -f
(命令行)实时监控这些日志。它比轮询更好,因为服务器可能会变得繁忙,并且当发生这种情况时最好依靠钩子。Create a global that is incremented each time a page is accessed and resets to 0 de-incremented by 1 per minute per incrementation called '
pages_accessed_per_minute
'.Create a function that takes two arguments, one the global mentioned above, and the other the limit for your throttle:
throttleOn('pages_accessed_per_minute', '1000')
.If the number of pages being accessed per minute increases beyond a certain point (1000 in this case), swap in the alternate php scripts which use the other databases.
I'm not 100% sure that I'm using include_once correctly, though.
I also discovered that most servers have a log symlinked to their users' home directories on shared hosts. These logs can be monitored live with the
$tail -f
(command line). It's better than polling because the server may become busy, and it's better to rely on hooks when that happens.问:有什么办法可以在它们之间切换吗?
答:当然可以 - 只需重定向到不同的 PHP 页面,该页面对一组不同的表执行不同的查询。
...但是...
问:您将如何保持表格同步?
问:有什么机制可以提醒您“您的网站流量很大”?
Q: Is there any way to switch between them?
A: Sure - just redirect to a different PHP page which does a different query of a different set of tables.
... however ...
Q: How are you going to keep the tables in synch?
Q: What mechanism is available to alert you that "your site has a lot of traffic"?
您可以“在生产中”执行此操作,但请记住,这很快就会变得至关重要!
You can do this "in production", but keep in mind that this can become critical very fast!