Hi,
I've solved my issues with using SessionVars during rewrite, but during
this, I noted that quite a few DB connections are created during the
rewrite phase: It seems every Mapper query opens a connection, executes
the query and then closes the connection.
Question: Is this needed? I have two issues with this:
1) I test the connection by doing a "SELECT 1" , so needless get/release
of connections slows down the request
2) Transaction semantics are undefined. While not an issue in this case,
I think well-defined transaction boundaries are important.
/Jeppe
This is my code:
def findForParams(p1: String, p2: String):Box[(Account, OrgUnit)] = {
println("findForParams p1=%s, pp2=%s".format(p1,p2))
val decrypted1 = FleetZoneRules.decrypt(p1)
val decrypted2 = FleetZoneRules.decrypt(p2)
println("Finding account")
urlAccount(Account.find(decrypted1))
println("Finding orgunit")
urlOrgUnit(OrgUnit.find(decrypted2))
if (urlAccount.isDefined && urlOrgUnit.isDefined)
Full((urlAccount.open_!, urlOrgUnit.open_!))
else
Empty
}
override val rewrite: LocRewrite =
Full(NamedPF(name) {
case RewriteRequest(pp , _, _)
if pp.wholePath.startsWith(path) &&
pp.wholePath.length == (path.length + 2)
&&
findForParams(pp.wholePath(path.length),pp.wholePath.last).isDefined
=>
println("Rewrite match, creating
response");(RewriteResponse(path),
findForParams(pp.wholePath(path.length),pp.wholePath.last))
})
And this is the output for a single request (I do realize why findForParams
is called 3 times :-)
findForParams p1=64383961446c6b597479593d, pp2=35376d4d426265354179633d
Finding account
11:20:04.041 [qtp-553402542-2] INFO bootstrap.liftweb.DBVendor$ -
Found connection in pool, size=1
11:20:04.041 [qtp-553402542-2] TRACE bootstrap.liftweb.DBVendor$ -
Verifying DB connection:org.postgresql.jdbc4.jdbc4connect...@43f854bd
11:20:04.048 [qtp-553402542-2] TRACE bootstrap.liftweb.DBVendor$ - DB
connection ok: org.postgresql.jdbc4.jdbc4connect...@43f854bd
11:20:04.051 [qtp-553402542-2] INFO query - >>>
All queries took 2ms:
11:20:04.051 [qtp-553402542-2] INFO query -
Exec query "SELECT accounts.name, accounts.id FROM accounts WHERE id = 1" :
org.postgresql.jdbc4.jdbc4result...@1ed2e55e took 1ms
11:20:04.051 [qtp-553402542-2] INFO query - <<<
End queries
11:20:04.052 [qtp-553402542-2] TRACE bootstrap.liftweb.DBVendor$ -
Releasing connection, size=1: org.postgresql.jdbc4.jdbc4connect...@43f854bd
Finding orgunit
11:20:04.053 [qtp-553402542-2] INFO bootstrap.liftweb.DBVendor$ -
Found connection in pool, size=1
11:20:04.053 [qtp-553402542-2] TRACE bootstrap.liftweb.DBVendor$ -
Verifying DB connection:org.postgresql.jdbc4.jdbc4connect...@43f854bd
11:20:04.055 [qtp-553402542-2] TRACE bootstrap.liftweb.DBVendor$ - DB
connection ok: org.postgresql.jdbc4.jdbc4connect...@43f854bd
11:20:04.058 [qtp-553402542-2] INFO query - >>>
All queries took 3ms:
11:20:04.058 [qtp-553402542-2] INFO query -
Exec query "SELECT org_units.diesel_limit, org_units.addon_limit,
org_units.description, org_units.account_id, org_units.id FROM org_units WHERE
id = 43" : org.postgresql.jdbc4.jdbc4result...@454e2c9c took 1ms
11:20:04.058 [qtp-553402542-2] INFO query - <<<
End queries
11:20:04.059 [qtp-553402542-2] TRACE bootstrap.liftweb.DBVendor$ -
Releasing connection, size=1: org.postgresql.jdbc4.jdbc4connect...@43f854bd
findForParams p1=64383961446c6b597479593d, pp2=35376d4d426265354179633d
Finding account
11:20:04.062 [qtp-553402542-2] INFO bootstrap.liftweb.DBVendor$ -
Found connection in pool, size=1
11:20:04.062 [qtp-553402542-2] TRACE bootstrap.liftweb.DBVendor$ -
Verifying DB connection:org.postgresql.jdbc4.jdbc4connect...@43f854bd
11:20:04.062 [qtp-553402542-2] TRACE bootstrap.liftweb.DBVendor$ - DB
connection ok: org.postgresql.jdbc4.jdbc4connect...@43f854bd
11:20:04.064 [qtp-553402542-2] INFO query - >>>
All queries took 1ms:
11:20:04.064 [qtp-553402542-2] INFO query -
Exec query "SELECT accounts.name, accounts.id FROM accounts WHERE id = 1" :
org.postgresql.jdbc4.jdbc4result...@6102d81c took 0ms
11:20:04.064 [qtp-553402542-2] INFO query - <<<
End queries
11:20:04.064 [qtp-553402542-2] TRACE bootstrap.liftweb.DBVendor$ -
Releasing connection, size=1: org.postgresql.jdbc4.jdbc4connect...@43f854bd
Finding orgunit
11:20:04.065 [qtp-553402542-2] INFO bootstrap.liftweb.DBVendor$ -
Found connection in pool, size=1
11:20:04.065 [qtp-553402542-2] TRACE bootstrap.liftweb.DBVendor$ -
Verifying DB connection:org.postgresql.jdbc4.jdbc4connect...@43f854bd
11:20:04.066 [qtp-553402542-2] TRACE bootstrap.liftweb.DBVendor$ - DB
connection ok: org.postgresql.jdbc4.jdbc4connect...@43f854bd
11:20:04.068 [qtp-553402542-2] INFO query - >>>
All queries took 2ms:
11:20:04.068 [qtp-553402542-2] INFO query -
Exec query "SELECT org_units.diesel_limit, org_units.addon_limit,
org_units.description, org_units.account_id, org_units.id FROM org_units WHERE
id = 43" : org.postgresql.jdbc4.jdbc4result...@4cf8f332 took 1ms
11:20:04.068 [qtp-553402542-2] INFO query - <<<
End queries
11:20:04.068 [qtp-553402542-2] TRACE bootstrap.liftweb.DBVendor$ -
Releasing connection, size=1: org.postgresql.jdbc4.jdbc4connect...@43f854bd
Rewrite match, creating response
findForParams p1=64383961446c6b597479593d, pp2=35376d4d426265354179633d
Finding account
11:20:04.070 [qtp-553402542-2] INFO bootstrap.liftweb.DBVendor$ -
Found connection in pool, size=1
11:20:04.070 [qtp-553402542-2] TRACE bootstrap.liftweb.DBVendor$ -
Verifying DB connection:org.postgresql.jdbc4.jdbc4connect...@43f854bd
11:20:04.071 [qtp-553402542-2] TRACE bootstrap.liftweb.DBVendor$ - DB
connection ok: org.postgresql.jdbc4.jdbc4connect...@43f854bd
11:20:04.072 [qtp-553402542-2] INFO query - >>>
All queries took 1ms:
11:20:04.072 [qtp-553402542-2] INFO query -
Exec query "SELECT accounts.name, accounts.id FROM accounts WHERE id = 1" :
org.postgresql.jdbc4.jdbc4result...@9d8643e took 1ms
11:20:04.072 [qtp-553402542-2] INFO query - <<<
End queries
11:20:04.073 [qtp-553402542-2] TRACE bootstrap.liftweb.DBVendor$ -
Releasing connection, size=1: org.postgresql.jdbc4.jdbc4connect...@43f854bd
Finding orgunit
11:20:04.073 [qtp-553402542-2] INFO bootstrap.liftweb.DBVendor$ -
Found connection in pool, size=1
11:20:04.074 [qtp-553402542-2] TRACE bootstrap.liftweb.DBVendor$ -
Verifying DB connection:org.postgresql.jdbc4.jdbc4connect...@43f854bd
11:20:04.074 [qtp-553402542-2] TRACE bootstrap.liftweb.DBVendor$ - DB
connection ok: org.postgresql.jdbc4.jdbc4connect...@43f854bd
11:20:04.076 [qtp-553402542-2] INFO query - >>>
All queries took 1ms:
11:20:04.076 [qtp-553402542-2] INFO query -
Exec query "SELECT org_units.diesel_limit, org_units.addon_limit,
org_units.description, org_units.account_id, org_units.id FROM org_units WHERE
id = 43" : org.postgresql.jdbc4.jdbc4result...@5ca801b0 took 0ms
11:20:04.076 [qtp-553402542-2] INFO query - <<<
End queries
11:20:04.077 [qtp-553402542-2] TRACE bootstrap.liftweb.DBVendor$ -
Releasing connection, size=1: org.postgresql.jdbc4.jdbc4connect...@43f854bd
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Lift" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/liftweb?hl=en
-~----------~----~----~----~------~----~------~--~---