Ivan,
no, it doesn't.
It only measures the time taken for request processing "inside" of the route…
On 11.04.2013, at 22:51, Ivan Topolnjak <
ivan...@gmail.com> wrote:
> @Mathias:
> Does the "time" directive as suggested here includes the processing
> time associated with writing to the socket?
>
> On Monday, December 10, 2012 6:55:15 AM UTC-3, Caoilte O'Connor wrote:
>>
>> Hi Mathias,
>>
>> That makes perfect sense. Thanks for laying it out so clearly.
>>
>> It really is an elegant solution.
>>
>>
>> Caoilte
>>
>> On Mon, Dec 10, 2012 at 9:47 AM, Mathias <
mat...@spray.io <javascript:>>
>> wrote:
>>> Caoilte,
>>>
>>> the `time` directive shown before measures the time it's inner route
>> takes between receiving the request and writing the response, no matter
>> whether this happens synchronously in the same thread or asynchronously via
>> a future or some other mechanism.
>>> The reason why this works is that the routing DSL is entirely
>> constructed in continuation-style.
>>>
>>> The limitation I was hinting at before is that you can hook in "slow
>> logic" outside of the route structure branch wrapped with `time` that is
>> not going to be measured.
>>> Consider the following example:
>>>
>>> time(...) { // A
>>> mapHttpResponse(someExpensiveLogic) {
>>> time(…) { // B
>>> … // route measured by `time` directive
>>> }
>>> }
>>> }
>>>
>>> If `someExpensiveLogic` is a slow response transformation function the
>> time logged by A will be significantly larger than the time logged by B.
>>> Again, it doesn't matter whether the inner route of B completes
>> directly, via a future or in some other way (e.g. by sending off the
>> RequestContext to another actor from which is then completed).
>>>
>>> HTH and cheers,
>>> Mathias
>>>
>>> ---
>>>
mat...@spray.io <javascript:>
>>>
http://spray.io
>>>
>>> On 08.12.2012, at 11:50, Caoilte O'Connor <
cao...@gmail.com<javascript:>>
>> wrote:
>>>
>>>> Hi Mathias,
>>>>
>>>> The documentation there is is already very good. Can't wait to read
>> more.
>>>>
>>>> I'm still not entirely sure what the time directive you provided is
>> measuring.
>>>>
>>>> If I have,
>>>>
>>>> route = { time(logger) {
>>>> paramsRoute { parameters => {
>>>> complete {
>>>> (usersActor ? GetUser(parameters.idFromAccessToken)).mapTo[String]
>>>> }
>>>> }
>>>> }
>>>>
>>>> I'm not sure if the time directive is wrapping the time it takes for
>>>> the future to complete or not.
>>>>
>>>> Also, I thought complete wrote the response, so it seemed to me like
>>>> it was wrapping that too.
>>>>
>>>> Any pointers you can give would be much appreciated as this is really
>>>> helping me understand the way spray-routing works.
>>>>
>>>> thanks,
>>>>
>>>> caoilte
>>>>
>>>>
>>>>
>>>> On Fri, Dec 7, 2012 at 6:55 PM, Mathias <
mat...@spray.io <javascript:>>
>> wrote:
>>>>> Caoilte,
>>>>>
>>>>> we'll have more documentation on directives like `mapRequestContext`
>> when the detailed directive docs are ready.
>>>>>
>>>>>> I take it that the
>>>>>> log call inside a mapHttpResponse is made after the response has been
>>>>>> written to the client?
>>>>>
>>>>> Nope, the `time` directive shown below measures the time the logic in
>> its inner route takes, i.e. the logic it "wraps".
>>>>> If there is a significant amount of processing happening outside of
>> the `time` directive it will not be measured.
>>>>>
>>>>> Cheers,
>>>>> Mathias
>>>>>
>>>>> ---
>>>>>
mat...@spray.io <javascript:>
>>>>>
http://spray.io
>>>>>
>>>>> On 07.12.2012, at 17:31, "Caoilte O'Connor" <
cao...@gmail.com<javascript:>>
>> wrote:
>>>>>
>>>>>> Thanks Mathias,
>>>>>>
>>>>>> mapHttpResponse was the missing piece of the puzzle. Might be useful
>>>>>> to have a page on the RequestContext in the docs as I'd kind of been
>>>>>> ignoring it until now!
>>>>>>
>>>>>> I think I've got the logging working for me now. I take it that the
>>>>>> log call inside a mapHttpResponse is made after the response has been
>>>>>> written to the client?
>>>>>>
>>>>>> Regards
>>>>>>
>>>>>> Caoilte
>>>>>>
>>>>>>
>>>>>> On Fri, Dec 7, 2012 at 3:22 PM, Mathias <
mat...@spray.io<javascript:>>
>> wrote:
>>>>>>> Caoilte,
>>>>>>>
>>>>>>> I'd suggest you write a small custom directive that you wrap (a
>> branch of) your route structure with.
>>>>>>> For example, it could look like this:
>>>>>>>
>>>>>>> def time(log: (HttpRequest, HttpResponse, Long) => Unit):
>> Directive0 =
>>>>>>> mapRequestContext { ctx =>
>>>>>>> val timeStamp = System.currentTimeMillis
>>>>>>> ctx.mapHttpResponse { response =>
>>>>>>> log(ctx.request, response, System.currentTimeMillis -
>> timeStamp)
>>>>>>> response
>>>>>>> }
>>>>>>> }
>>>>>>>
>>>>>>> HTH and cheers,
>>>>>>> Mathias
>>>>>>>
>>>>>>> ---
>>>>>>>
mat...@spray.io <javascript:>
>>>>>>>
http://spray.io
>>>>>>>
>>>>>>> On 07.12.2012, at 16:13, Caoilte O'Connor <
cao...@gmail.com<javascript:>>
>> wrote:
>>>>>>>
>>>>>>>> Hi,
>>>>>>>> I would like to log how long my spray-routing app takes to respond.
>>>>>>>>
>>>>>>>> I played around a bit with overriding onComplete but am struggling
>> because I am relying on a Future completing like so,
>>>>>>>>
>>>>>>>> complete {
>>>>>>>> (usersActor ?
>> GetUser(parameters.idFromAccessToken)).mapTo[String]
>>>>>>>> }
>>>>>>>>
>>>>>>>> It seems that complete behaves differently to routes and
>> directives. I think what I want to do is override an implicit somewhere
>> such that
>>>>>>>>
>>>>>>>> ctx.complete(myUser)
>>>>>>>>
log.info("total time {}", time)
>>>>>>>>
>>>>>>>> Possibly I'm going about this the wrong way. Does anybody have any
>> suggestions?
>>>>>>>>
>>>>>>>> --
>>>>>>>>
>>>>>>>>
>>>>>>>
>>>>>>> --
>>>>>>>
>>>>>>>
>>>>>>
>>>>>> --
>>>>>>
>>>>>>
>>>>>
>>>>> --
>>>>>
>>>>>
>>>>
>>>> --
>>>>
>>>>
>>>
>>> --
>>>
>>>
>>
>
> --
> You received this message because you are subscribed to the Google Groups "spray-user" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to
spray-user+...@googlegroups.com.
> For more options, visit
https://groups.google.com/groups/opt_out.
>
>