Best way to measure service request time

瀏覽次數:147 次
跳到第一則未讀訊息

Mark Feeney

未讀,
2011年11月2日 下午4:52:572011/11/2
收件者:lif...@googlegroups.com
Hi all.

I'm trying to record service times of requests in my Lift app.  It looks like I can do this with LiftRules.onBeginServicing and LiftRules.onEndServicing.  I'm wondering if there's a better way.  In LiftServlet#service() I see TimeHelper being used like this:

  def service(req: Req, resp: HTTPResponse): Boolean = {
    try {
      def doIt: Boolean = {
        if (LiftRules.logServiceRequestTiming) {
          logTime {
            val ret = doService(req, resp)
            val msg = "Service request (" + req.request.method + ") " + req.request.uri + " returned " + resp.getStatus + ","
            (msg, ret)
          }
        } else {
          doService(req, resp)
        }
      }
      ...

That's exactly where I'd like to hook in, but it seems inaccessible.

Any suggestions are appreicated.  Thanks,


Mark.

David Pollak

未讀,
2011年11月2日 下午5:27:292011/11/2
收件者:lif...@googlegroups.com
Please open a ticket (http://ticket.liftweb.net you must be a watcher of the space on Assembla to open tickets) and we'll add a hook.
--
Lift, the simply functional web framework: http://liftweb.net
Code: http://github.com/lift
Discussion: http://groups.google.com/group/liftweb
Stuck? Help us help you: https://www.assembla.com/wiki/show/liftweb/Posting_example_code

Mark Feeney

未讀,
2011年11月2日 下午6:07:382011/11/2
收件者:lif...@googlegroups.com

Christoph Knabe

未讀,
2011年11月4日 清晨5:20:332011/11/4
收件者:Lift
Hi Marc,

Isn't S.addAround exactly the hook you are needing to measure the
duration of an individual request processing? Once David Pollak said,
this method should have its place betterly in LiftRules, but now it is
in S. May be that is why you did not find it.

You can see an example of its usage in

https://www.assembla.com/code/liftbuchcode/git/nodes/src/main/scala/bootstrap/liftweb/Boot.scala

There I install a general exception reporter for all requests by

S.addAround(ExceptionReporting)

You can find it in the same package there.

Greetings,

Christoph

On 2 Nov., 21:52, Mark Feeney <mark.fee...@gmail.com> wrote:
> Hi all.
>
> I'm trying to record service times of requests in my Lift app.  It looks
> like I can do this with LiftRules.onBeginServicing
> and LiftRules.onEndServicing.  I'm wondering if there's a better way.  In
> LiftServlet#service() I see TimeHelper being used like this:
>
>   def service(req: Req, resp: HTTPResponse): Boolean = {
>     try {
>       def doIt: Boolean = {
>         if (LiftRules.logServiceRequestTiming) {
> *          logTime {*
> *            val ret = doService(req, resp)*
> *            val msg = "Service request (" + req.request.method + ") " +
> req.request.uri + " returned " + resp.getStatus + ","*
> *            (msg, ret)*
> *          }*

Andreas Joseph Krogh

未讀,
2011年11月4日 清晨5:25:092011/11/4
收件者:lif...@googlegroups.com
On 11/04/2011 10:20 AM, Christoph Knabe wrote:
> Hi Marc,
>
> Isn't S.addAround exactly the hook you are needing to measure the
> duration of an individual request processing? Once David Pollak said,
> this method should have its place betterly in LiftRules, but now it is
> in S. May be that is why you did not find it.
>
> You can see an example of its usage in
>
> https://www.assembla.com/code/liftbuchcode/git/nodes/src/main/scala/bootstrap/liftweb/Boot.scala
>
> There I install a general exception reporter for all requests by
>
> S.addAround(ExceptionReporting)

BTW: You know about Lift's built-in exceptionHandler-mechanism?

LiftRules.exceptionHandler.prepend {case (runMode, request, exception) =>
<custom-code here to handle exception>
}

--
Andreas Joseph Krogh <and...@officenet.no> - mob: +47 909 56 963
Senior Software Developer / CTO - OfficeNet AS - http://www.officenet.no
Public key: http://home.officenet.no/~andreak/public_key.asc

Jeppe Nejsum Madsen

未讀,
2011年11月4日 清晨5:51:522011/11/4
收件者:lif...@googlegroups.com
On Fri, Nov 4, 2011 at 10:20 AM, Christoph Knabe
<kn...@beuth-hochschule.de> wrote:
> Hi Marc,
>
> Isn't S.addAround exactly the hook you are needing to measure the
> duration of an individual request processing? Once David Pollak said,
> this method should have its place betterly in LiftRules, but now it is
> in S. May be that is why you did not find it.

I agree that this should be enough and I've used this in the past.
Unfortunately the addAround functions are now called twice for each
request (first in a stateless mode, then in statefull). I've been
trying to see if I can fix this, but haven't had the time yet...

/Jeppe

Mark Feeney

未讀,
2011年11月4日 上午8:33:512011/11/4
收件者:lif...@googlegroups.com
Hi, Christoph.

Thanks for the suggestion. I was not aware of S.addAround() -- very
cool. Jeppe mentions there is currently a problem with addAround
being called twice per request, but once (or if) that is fixed it
might work quite well.

Thanks,


Mark.

回覆所有人
回覆作者
轉寄
0 則新訊息