[99s-extend] timeouts and slow clients in cowboy loop handler

Loïc Hoguin essen at ninenines.eu
Fri Sep 20 21:04:34 CEST 2013


send_after sends an Erlang message to a Pid after N milliseconds. It's 
the same as Pid ! Message, except it's sent later. Send it to self().

But if you're going to use timestamps then you probably don't need this 
timeout, just check the timestamps and close when too slow.

On 09/20/2013 08:59 PM, akonsu wrote:
> Understand about chunks being synchronous. that helps me tremendously to
> understand how it works.
>
> would you give me a sketchy example of how to use send_after in a loop
> handler? (sorry I am new to erlang)
>
> Konstantin
>
>
> 2013/9/20 Loïc Hoguin <essen at ninenines.eu <mailto:essen at ninenines.eu>>
>
>     chunk only returns when the client has received the chunk, so the
>     timestamps solution should work.
>
>     As for the timeout, you can simply use erlang:send_after or
>     something like usual and the message will arrive in info/3.
>
>
>     On 09/20/2013 08:54 PM, akonsu wrote:
>
>         thanks!
>
>         how to implement timeout callback manually? if I had receive then I
>         would just use timeout clause there, but with the handler I do
>         not know...
>
>         I have doubts about validity of my question on the erlang list.
>           I later
>         realised that there is no problem receiving messages in my
>         handler from
>         my upstream process, I can do it fast enough and shove
>         everything to the
>         response. my real problem is to determine if the http client is
>         reading
>         fast enough from the response...
>
>
>         2013/9/20 Loïc Hoguin <essen at ninenines.eu
>         <mailto:essen at ninenines.eu> <mailto:essen at ninenines.eu
>         <mailto:essen at ninenines.eu>>>
>
>
>              Loop handlers close after a while regardless of what you
>         send, it
>              only checks what the client sends. The best way for you
>         would be to
>              disable that timeout and handle it manually.
>
>              As for the second question, I'm still reading the thread on
>              erlang-questions but I've seen some good ideas about
>         timestamps so far.
>
>
>              On 09/20/2013 08:47 PM, akonsu wrote:
>
>                  Hi,
>
>                  I am using loop handler and I stream from it:
>
>                  info({stream, Part}, Req, S) ->
>                        ok = cowboy_req:chunk(Part, Req),
>                        {loop, Req, S, hibernate};
>
>                  I have two questions:
>
>                  1. on timeouts cowboy sends 204 No Content. In my case
>         it is not the
>                  right response because I may have already sent some
>         data. Is
>                  there a way
>                  to send a custom response?
>
>                  2. how to check if the client is too slow and is not
>         reading the
>                  response stream fast enough? If this happens, then I
>         need to
>                  disconnect.
>
>                  I can live without 1. but I need to figure out 2.
>         Please help.
>
>                  thank you!
>                  Konstantin
>
>
>
>                  ___________________________________________________
>                  Extend mailing list
>         Extend at lists.ninenines.eu <mailto:Extend at lists.ninenines.eu>
>         <mailto:Extend at lists.__ninenines.eu
>         <mailto:Extend at lists.ninenines.eu>>
>         http://lists.ninenines.eu:81/____listinfo/extend
>         <http://lists.ninenines.eu:81/__listinfo/extend>
>
>                  <http://lists.ninenines.eu:81/__listinfo/extend
>         <http://lists.ninenines.eu:81/listinfo/extend>>
>
>
>
>              --
>              Loďc Hoguin
>              Erlang Cowboy
>              Nine Nines
>         http://ninenines.eu
>
>
>
>
>     --
>     Loïc Hoguin
>
>     Erlang Cowboy
>     Nine Nines
>     http://ninenines.eu
>
>


-- 
Loïc Hoguin
Erlang Cowboy
Nine Nines
http://ninenines.eu



More information about the Extend mailing list