当我的网站流量很大时,如何更改我使用的表?

发布于 2024-12-11 09:50:05 字数 74 浏览 0 评论 0原文

好吧,我已经构建了一组运行的表,这些表旨在以更少的连接运行,但我想保留我的规范化数据库。当我的网站流量很大时,有办法在它们之间切换吗?

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

梦里兽 2024-12-18 09:50:05

如果是为了简化您的查询,您可能需要 创建一个视图,它又可以捆绑一些连接。

If it is in order to simplify your queries, you might want to create a view which in turn can bundle some joins.

人心善变 2024-12-18 09:50:05

创建一个全局变量,每次访问页面时该变量都会递增,并重置为 0,每次递增每分钟递减 1,称为“pages_accessed_per_一分钟”。

创建一个接受两个参数的函数,一个是上面提到的全局参数,另一个是油门限制:throttleOn('pages_accessed_per_一分钟', '1000')

如果每分钟访问的页面数增加超过某个点(本例中为 1000),请交换使用其他数据库的备用 php 脚本。

if throttleOn('pages_accessed_per_minute', '1000') == true){
  include_once('dbAccess1.php');
}
else{
  include_once('dbAccess2.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.

if throttleOn('pages_accessed_per_minute', '1000') == true){
  include_once('dbAccess1.php');
}
else{
  include_once('dbAccess2.php');
}

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.

吻泪 2024-12-18 09:50:05

问:有什么办法可以在它们之间切换吗?
答:当然可以 - 只需重定向到不同的 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"?

暮倦 2024-12-18 09:50:05

您可以“在生产中”执行此操作,但请记住,这很快就会变得至关重要!

  • 通过添加所需的附加列来更改表。
  • 填充新列(使用脚本,以便您可以控制每次触摸的行数,以确保不会生成太多负载)
  • 使用新结构更改您的(网站)脚本。最好的方法是同时更新所有脚本。
  • 重新运行“填充脚本”以确保所有行确实采用新格式
  • 删除不必要的列/表

You can do this "in production", but keep in mind that this can become critical very fast!

  • Alter your tables by adding the additional columns you need.
  • Populate the new columns (with a script, so that you can control how many rows are touched per time to make sure you do not generate to much load)
  • Change your (website)-scripts using the new structure. Best way would be to update all scripts at the same time.
  • Re-run your "populate-script" to ensure all rows are really in the new format
  • Remove unneccessary columns/tables
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文