Golang - 许多正在使用的连接

发布于 2025-01-17 00:31:49 字数 753 浏览 0 评论 0 原文

#golang #oracle

我试图了解 Max 连接是如何工作的。基本上我有这个数据库配置:

params.MinSessions = 5
params.MaxSessions = 6
params.SessionTimeout = 0
params.WaitTimeout = 5 * time.Second
params.SessionIncrement = 0
params.ConnClass = "GOLANGPOOL"

// Connect!
result, err := sql.Open("godror", params.StringWithPassword())
result.SetMaxIdleConns(0)

但是我可以使用 sql.DB.Stats 看到 242 个连接:

DB Established Open Conn (use + idle): 242
DB Idle Conn: 0
DB In Use Conn: 242
DB Max Idle Closed: 766
DB Max Idle Time Closed: 0
DB Max Lifetime Closed: 0
DB Max Open Conn: 0
DB Wait Count: 0
DB Wait Duration (sec): 0

这怎么可能?上限不应该是6吗?

谢谢

#golang #oracle

Im trying to understand how the Max connection works. Basically I have this db configuration:

params.MinSessions = 5
params.MaxSessions = 6
params.SessionTimeout = 0
params.WaitTimeout = 5 * time.Second
params.SessionIncrement = 0
params.ConnClass = "GOLANGPOOL"

// Connect!
result, err := sql.Open("godror", params.StringWithPassword())
result.SetMaxIdleConns(0)

However I can see 242 connections using sql.DB.Stats:

DB Established Open Conn (use + idle): 242
DB Idle Conn: 0
DB In Use Conn: 242
DB Max Idle Closed: 766
DB Max Idle Time Closed: 0
DB Max Lifetime Closed: 0
DB Max Open Conn: 0
DB Wait Count: 0
DB Wait Duration (sec): 0

How is it possible? The limit shouldn't be 6?

Thanks

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

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

发布评论

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

评论(3

ゞ花落谁相伴 2025-01-24 00:31:49

在Oracle中,连接和会话是不同的概念。

连接是与数据库的网络连接,而会话是
封装用户与数据库的交互...

参考本书,与Oracle之间的关系会话和连接池

In Oracle connections and sessions are different concepts.

A connection is a network connection to the DB, while a session is an
encapsulation of a user's interaction with the DB...

refering to this book, and Relation between Oracle session and connection pool.

梦里的微风 2025-01-24 00:31:49

假设您使用的是最新版本的驱动程序,https://github.com/godror/godror

sql.Open("godror", params.StringWithPassword()) 

implies standaloneConnection=0 setting.

统计信息您看到的是来自 go sql 连接池。 go sql 调用驱动程序 connect 方法,该方法又尝试从另一个池获取连接(OCI 由于设置standaloneConnection=0 而维护它)。

最大出站连接数尚未超过 params.MaxSessions,但它只是 go sql 连接计数器。

numOpen, ....

理想情况下,您将 go sql 池设置调整为更接近另一个池值,以便 go 例程不会阻塞。

您可以使用 GetPoolStats() 检查 OCI 池统计信息
godror.Conn 的方法并确认最大出站连接的实际数量。例子在这里

https://github.com/godror/godror/blob/main/z_test.go

Assuming you are using latest version of driver, https://github.com/godror/godror

sql.Open("godror", params.StringWithPassword()) 

implies standaloneConnection=0 setting.

The stats you are seeing is from go sql connection pool. The go sql calls the driver connect method which inturn tries to get connection from another pool (OCI maintains it due to setting standaloneConnection=0 ).

The max outbound connections hasn't exceeded the params.MaxSessions but its just the go sql connection counter

numOpen, ....

It is ideal you tune the go sql pool settings closer to another pool values so that the go routines just don't block.

You can check the OCI pool stats by using GetPoolStats()
method from godror.Conn and confirm the real number of maximum outbound connections. example here

https://github.com/godror/godror/blob/main/z_test.go
Smile简单爱 2025-01-24 00:31:49

数据库正在使用康涅狄格州:242
DB 最大空闲关闭:766

总和差不多1000,就像这个默认的值

poolMaxSessions=1000

我认为您没有同时使用 242 个连接。您有一个连接,数据库将限制同时会话的数量。

您应该检查 sql 包如何处理它(它是开源的!)以及特定驱动程序如何处理它(也是开源的!),如有必要,请在驱动程序项目上提出问题

https://github.com/godror/godror

DB In Use Conn: 242
DB Max Idle Closed: 766

The sum is almost 1000, like the value of this default

poolMaxSessions=1000

I think you don’t have 242 simultaneous connections in use. You have a pull of connections and the database will limit the number of simultaneous sessions.

You should check how the sql package handles it (it is open source!) and how the specific driver handles it (also open source!) and if necessary open an issue on the driver project

https://github.com/godror/godror

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