gpt4 book ai didi

mysql - rails + database.yml 中的最大连接池大小

转载 作者:行者123 更新时间:2023-11-29 01:30:27 25 4
gpt4 key购买 nike

我可以在 database.yml 中设置的最大池大小是多少?我正在使用 Mysql Db。

我有 20 个 unicorn 进程在 24 核、32GB 内存的机器上运行。

最佳答案

MySQL 中的默认配置是 100 个连接。

来自 MySQL 5.5 页面

Linux or Solaris should be able to support at 500 to 1000 simultaneous connections routinely and as many as 10,000 connections if you have many gigabytes of RAM available and the workload from each is low or the response time target undemanding. Windows is limited to (open tables × 2 + open connections) < 2048 due to the Posix compatibility layer used on that platform.

你必须自己弄清楚,我认为同时连接到数据库不会成为你的瓶颈。

来自 Rails 连接池:

A connection pool synchronizes thread access to a limited number of database connections. The basic idea is that each thread checks out a database connection from the pool, uses that connection, and checks the connection back in. ConnectionPool is completely thread-safe, and will ensure that a connection cannot be used by two threads at the same time, as long as ConnectionPool’s contract is correctly followed. It will also handle cases in which there are more threads than connections: if all connections have been checked out, and a thread tries to checkout a connection anyway, then ConnectionPool will wait until some other thread has checked in a connection.

因此,您唯一不应该做的就是在 Rails 池大小中设置比 mysql 配置中更多的连接。

关于mysql - rails + database.yml 中的最大连接池大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15269096/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com