Skip to content

Commit

Permalink
Merge pull request #2279 from hongwei1/develop
Browse files Browse the repository at this point in the history
feature/tweaked the maxPoolSize and change the log level to trace
  • Loading branch information
simonredfern authored Sep 26, 2023
2 parents bd074dc + 820d4f2 commit e880c33
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
4 changes: 2 additions & 2 deletions obp-api/src/main/resources/props/sample.props.template
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,8 @@ write_connector_metrics=true
db.driver=org.h2.Driver
db.url=jdbc:h2:./lift_proto.db;NON_KEYWORDS=VALUE;DB_CLOSE_ON_EXIT=FALSE

#the default max database connection pool size is 10
db.maxPoolSize=10
#the default max database connection pool size is 30
db.maxPoolSize=30


#If you want to use the postgres , be sure to create your database and update the line below!
Expand Down
22 changes: 11 additions & 11 deletions obp-api/src/main/scala/bootstrap/liftweb/CustomDBVendor.scala
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ trait CustomProtoDBVendor extends ConnectionManager {
* Override this method if you want something other than 10 connections in the freePool and usedPool
* freePool.size + usedPool.size <=10
*/
val dbMaxPoolSize = APIUtil.getPropsAsIntValue("db.maxPoolSize",10)
val dbMaxPoolSize = APIUtil.getPropsAsIntValue("db.maxPoolSize",30)
protected def maxPoolSize = dbMaxPoolSize

/**
Expand Down Expand Up @@ -93,15 +93,15 @@ trait CustomProtoDBVendor extends ConnectionManager {
def commonPart(name: ConnectionIdentifier): (Box[Connection], Boolean) =
synchronized {
freePool match {
case Nil if (freePool.size + usedPool.size) < maxPoolSize =>{ //we set maxPoolSize 4.
case Nil if (freePool.size + usedPool.size) < maxPoolSize =>{
val ret = createOne // get oneConnection from JDBC, not in the freePool yet, we add ot the Pool when we release it .
try {
ret.head.setAutoCommit(false) // we test the connection status, if it is success, we return it back.
usedPool = ret.head :: usedPool
logger.debug(s"Created connection is good, detail is $ret ")
logger.trace(s"Created connection is good, detail is $ret ")
} catch {
case e: Exception =>
logger.debug(s"Created connection is bad, detail is $e")
logger.trace(s"Created connection is bad, detail is $e")
}

//Note: we may return the invalid connection
Expand All @@ -113,7 +113,7 @@ trait CustomProtoDBVendor extends ConnectionManager {
logger.error(s"The (freePool.size + usedPool.size) is at the limit ($maxPoolSize) and there are no free connections.")
(
Failure(s"The (freePool.size + usedPool.size) is at the limit ($maxPoolSize) and there are no free connections."),
true
false
)

case freeHead :: freeTail =>//if freePool is not empty, we just get connection from freePool, no need to create new connection from JDBC.
Expand Down Expand Up @@ -149,18 +149,18 @@ trait CustomProtoDBVendor extends ConnectionManager {

def releaseConnection(conn: Connection): Unit = synchronized {
usedPool = usedPool.filterNot(_ ==conn)
logger.debug(s"Released connection. removed connection from usedPool size is ${usedPool.size}")
logger.trace(s"Released connection. removed connection from usedPool size is ${usedPool.size}")
//TODO check if we need add head or tail
freePool = conn :: freePool
logger.debug(s"Released connection. added connection to freePool size is ${freePool.size}")
logger.trace(s"Released connection. added connection to freePool size is ${freePool.size}")
notifyAll
}

def closeAllConnections_!(): Unit = _closeAllConnections_!(0)


private def _closeAllConnections_!(cnt: Int): Unit = synchronized {
logger.debug(s"Closing all connections, try the $cnt time")
logger.trace(s"Closing all connections, try the $cnt time")
if (cnt > 10) ()//we only try this 10 times,
else {
freePool.foreach {c => tryo(c.close);}
Expand All @@ -177,16 +177,16 @@ trait CustomProtoDBVendor extends ConnectionManager {

//This is only for debugging
def logAllConnectionsStatus = {
logger.debug(s"Hello from logAllConnectionsStatus: usedPool.size is ${usedPool.length}, freePool.size is ${freePool.length}")
logger.trace(s"Hello from logAllConnectionsStatus: usedPool.size is ${usedPool.length}, freePool.size is ${freePool.length}")
for {
usedConnection <- usedPool
} yield {
logger.debug(s"usedConnection (${usedConnection.toString}): isClosed-${usedConnection.isClosed}, getWarnings-${usedConnection.getWarnings}")
logger.trace(s"usedConnection (${usedConnection.toString}): isClosed-${usedConnection.isClosed}, getWarnings-${usedConnection.getWarnings}")
}
for {
freeConnection <- freePool
} yield {
logger.debug(s"freeConnection (${freeConnection.toString}): isClosed-${freeConnection.isClosed}, getWarnings-${freeConnection.getWarnings}")
logger.trace(s"freeConnection (${freeConnection.toString}): isClosed-${freeConnection.isClosed}, getWarnings-${freeConnection.getWarnings}")
}
}
}
2 changes: 1 addition & 1 deletion release_notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
### Most recent changes at top of file
```
Date Commit Action
22/09/2023 752ff04b Added props db.maxPoolSize, default is 10.
22/09/2023 752ff04b Added props db.maxPoolSize, default is 30.
24/08/2023 bcb8fcfd Added props expectedOpenFuturesPerService, default is 100.
16/08/2023 4d8dfa66 Added props short_endpoint_timeout, default is 1.
Added props medium_endpoint_timeout, default is 7.
Expand Down

0 comments on commit e880c33

Please sign in to comment.