On Mon, Nov 16, 2009 at 2:24 AM, Jeppe Nejsum Madsen <[email protected]>wrote:

>
> 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.
>

Yes.  The rewrite phase happens before any scope (other than request var).
The "around" stuff is part of the S scope... so you don't get the
transactional wrapping.

After seeing all the thrashing that's going on here, I think I'm going to
introduce a second re-write phase after the S scope has been entered.
Basically, there'll be a stateless rewrite phase so you can do a rewrite
that's going to deal with determining if it's a Lift request (or should be
passed to the servlet filter chain) and to see if it matches the stateless
stuff.

The second rewrite phase will be within the S scope and have the
SessionVars, etc. wrapped around it.

I think this will address your issues.  Sound good?

Thanks,

David


>
> 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
>
>
> >
>


-- 
Lift, the simply functional web framework http://liftweb.net
Beginning Scala http://www.apress.com/book/view/1430219890
Follow me: http://twitter.com/dpp
Surf the harmonics

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to