如何计算数据库连接池的大小?
假设我预计每秒大约有 100 个请求,每个请求应该花费 1 - 3 秒之间的时间(在完美的世界中)。
我会创建一个包含 300 个连接的池吗?或者稍微高一点的东西来补偿潜在的峰值?
Say I'm expecting about 100 requests a second, each request should take anywhere between 1 - 3 seconds (In a perfect world).
Would I create a pool of 300 connections? Or something slightly higher to compensate for potential spikes?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这取决于到达事件的分布。
排队理论可以为您提供一个公式(对于给定的分布)您需要多少个连接,以便失败的概率(在您的情况下没有免费连接)将不超过一定的百分比。
您可能需要查看这些注释(第 17 页),其中可以为您提供一些信息公式,例如同时处理 n 个请求的概率或者您有一个非空队列(您想要避免的状态)
That depends on the distribution of arriving events.
Queuing theory can give you a formula (for a given distribution) how many connections you need so that the probability of failure (no free connection in your case) will be no more than certain percentage.
You may want to look at these notes (page 17) which give you some formulas, such as probability that you have n requests being served at the same time or you have a non-empty queue (the state that you want to avoid)