Cloudant - 连接池

Cloudant - Connection Pooling

我正在尝试使用 cloudant 数据库进行连接池。据我了解,cloudant 数据库本质上使用 max_connections = 6.max_connections code 的默认参数进行连接池。所需的代码片段位于第 130 行。

我有一个使用 akka-http 用 scala 编写的工作应用程序,具有以下初始化:

val client: CloudantClient = ClientBuilder.account(<accountdetails>)
.username(<my user name>)
.password(<my password>).maxConnections(20)
.build()
println("creating database")
val db: Database = client.database("exampledb", false)
println("created");

我的问题是如何确认连接池是否按预期工作,以获取来自学生数据库示例的基本获取功能。

我认为 akka-http 不会在这里产生影响,除非它取代 java.netHttpURLConnectionCloudantClient 使用 java.net.HttpURLConnection class 与 Cloudant 数据库通信。 HttpURLConnection 的实现默认由 JVM 提供,如果您添加了该依赖项,则由 OkHttp 提供。根据 documentation for connection pooling the behaviour changes if you are using the optional OkHttp client or not. The maxConnections method 仅在使用 OkHttp 依赖项时更改连接池大小。对于默认值 HttpURLConnection,池大小由 JVM 属性配置。

根据 this documentation it is possible to enable logging for the java-cloudant client. As the pool use is transparent to the client code if you want to validate whether a connection is created or leased from the pool you will need logging for the underlying HttpURLConnection. For more information about the log string for the default HttpURLConnection see for example this answer.

如果您担心池是否有效,您可能还会发现有关 this issue 的讨论相关。默认的 JVM 实现会在非常短的空闲时间后从池中清除连接。