使用“app”db 节点”分片的优点/缺点与单独对数据库进行分片并对应用程序服务器进行负载平衡

发布于 2024-11-18 22:37:13 字数 490 浏览 4 评论 0原文

我们正准备扩展 API 密集型 Web 应用程序的 API 端。我的(精通技术的)客户对此提出了一种相当非常规的方法:他希望我们:

  • “对应用程序服务器进行分片”,将应用程序服务器代码和db 在每个物理服务器上,以便应用程序服务器仅连接到自己的数据库分片;
  • 让应用程序服务器在需要访问其他分片时相互通信(而不是直接与另一个分片的数据库通信);
  • 让 API 客户端自行选择一个应用程序分片(在客户端,基于一些稳定的哈希值)并直接与其对话。

根本原因是,这是最自然的事情,并且这将使我们能够在未来迁移到多站点分布式系统。

(该堆栈是 MySQL 上的 PHP + Node.js,尽管此时也考虑了向 MongoDB 的过渡。)

现在,我没有看到它现成的巨大问题。编写这些服务器到服务器交互的代码可能会有点麻烦,但它肯定有其自身的好处。基本上我不知道这是否是一个好主意。

您想到什么优点和缺点?我在这里寻找技术问题和优势。谢谢!

We are preparing to scale the API side of an API-heavy web application. My (technically savvy) client proposes a rather unconventional approach to this: instead of balancing the load to several app servers, which would talk to a sharded database, he wants us to:

  • “shard the app servers”, putting both app server code and db on each physical server, so that the app server only connects to its own db shard;
  • have the app servers talk to each other when they need to access other shards (instead of talking to another shard's DB directly);
  • have the API client pick an app shard itself (on the client side, based on some stable hash) and talk directly to it.

The underlying reasoning is that this is the most natural thing to do it, and that this would allow us to move to a multisite distributed system in the future.

(The stack is PHP + Node.js on MySQL, although at this point a transition to MongoDB is considered too.)

Now, I don't see huge problems with it off the shelf. It might get somewhat cumbersome to code these server-to-server interactions, but then it will surely have its own benefits. Basically I'm at a loss on whether this is a good idea or not.

What pros and cons come to your mind? I'm looking for technical issues and advantages here. Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

我三岁 2024-11-25 22:37:13

由于多种原因,这实在是太糟糕了。

  • API 客户端不应该知道要与哪个应用程序分片通信。这将以您现在可能无法预见的方式限制您,但将来可能/将成为一个问题。 API 客户端应该扮演愚蠢的角色​​,以便在应用程序服务器死亡、更改、再次分片等情况下,您可以适当地路由请求。
  • 如果您的应用程序代码或数据库架构很慢,会发生什么情况? (不是同时两个,只是一个)。现在您有了一个数据库分片,它会减慢应用程序分片的速度。
  • 您的 db+app 分片需要将应用程序代码+内存和数据库代码+内存保留在 RAM 中。这意味着 CPU 将花费更多时间来交换代码和内存来执行两组任务。
  • 我发现很难用语言来表达,但这种类型的架构尖叫着“糟糕的耦合”和“没有关注点分离”(可能不是正确的术语,但我希望你明白我的意思)。您将两种截然不同类型的应用程序(应用程序服务器和数据库)放入一个盒子中。更新它们和绕过失败实例的管理噩梦将非常困难。

我讨厌以这种方式争论我的观点,但很多非常聪明的人以前都处理过这些问题,而我从未听说过这种类型的架构。这可能是有原因的。更不用说有很多技术和资源可以帮助您处理应用程序和数据库服务器的传统分片和负载平衡。如果您采用客户建议的架构,那么您就只能靠自己了。

This is just plain bad for many reasons.

  • The API client should not know which app shard to talk to. This will limit you in ways you probably can't foresee now, but may/will become a problem in the future. The API client should play dumb so you can route requests appropriately if an app server dies, changes, gets sharded again etc.
  • What happens if your app code or database architecture is slow? (Not both at the same time, just one). Now you have a db shard slowing down an app shard.
  • Your db+app shards will need to keep both app code+memory and db code+memory in RAM. This means the CPUs will spend more time swapping code and memory in and out to perform both sets of tasks.
  • I'm finding it hard to put down in words, but this type of architecture screams 'bad coupling' and 'no separation of concerns' (probably not the right terminology but I hope you understand what I mean). You are putting two distinctly different types of applications (app server and database) onto one box. The management nightmare of updating them and routing around failed instances will be very difficult.

I hate to argue my point this way, but a lot of very smart people have dealt with these problems before and I've never heard of this type of architecture. There's probably a reason for it. Not to mention there's a lot of technology and resources out there that can help you handle traditional sharding and load balancing of app and database servers. If you go with your client's suggested architecture you're on your own.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文