如何计算数据库连接池的大小?

时间:2022-09-27 20:51:30

Say I'm expecting about 100 requests a second, each request should take anywhere between 1 - 3 seconds (In a perfect world).

假设我期待每秒约100个请求,每个请求应该在1到3秒之间(在一个完美的世界中)。

Would I create a pool of 300 connections? Or something slightly higher to compensate for potential spikes?

我会创建一个300连接的池吗?或稍高的东西来弥补潜在的尖峰?

1 个解决方案

#1


4  

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)

您可能需要查看这些注释(第17页),这些注释会为您提供一些公式,例如您同时提供n个请求的概率,或者您具有非空队列(您要避免的状态)

#1


4  

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)

您可能需要查看这些注释(第17页),这些注释会为您提供一些公式,例如您同时提供n个请求的概率,或者您具有非空队列(您要避免的状态)