couchdb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Adam Kocoloski <kocol...@apache.org>
Subject Re: mochiweb socket options discriminating against slow connections
Date Thu, 05 Nov 2009 04:33:34 GMT
On Nov 4, 2009, at 5:37 PM, Adam Kocoloski wrote:

> On Nov 4, 2009, at 4:42 PM, Adam Kocoloski wrote:
>
>> I don't know what the behavior is when there are 0 bytes available  
>> on the socket -- does gen_tcp:recv just keep returning 0 and leave  
>> it to us to implement the timeout, or can we do something like
>>
>> gen_tcp:recv(Socket, 0, 10000)
>>
>> Best, Adam
>
> Ok, confirmed -- this call blocks for 10 seconds when no data is  
> available on the socket.  I think that's the behavior we're looking  
> for: detect stale connections, but let slow connections keep  
> working.  Not sure what the greater performance implications of  
> switching this configuration might be, though (the chunks of data  
> we'd be dealing with would be much smaller).  Best,
>
> Adam

So, it looks like we already "do the right thing" when dealing with  
attachment uploads -- we only timeout if no data is received for 10  
seconds.  It looks like the reason we take a different code path with  
document uploads is so that we can enforce the mox_document_size  
config setting (which is insanely high, BTW -- who really has a 4GB  
JSON document lying around!)

The following patch to MochiWeb gives it the desired timeout property  
while still limiting the total number of bytes in the received body.   
Test suite looks the same, and I didn't see a significant difference  
in performance in either baracus or the built-in JS bench tests.  Best,

Adam

Index: src/mochiweb/mochiweb_request.erl
===================================================================
--- src/mochiweb/mochiweb_request.erl	(revision 832988)
+++ src/mochiweb/mochiweb_request.erl	(working copy)
@@ -451,14 +451,11 @@

  stream_unchunked_body(0, _MaxChunkSize, Fun, FunState) ->
      Fun({0, <<>>}, FunState);
-stream_unchunked_body(Length, MaxChunkSize, Fun, FunState) when  
Length > MaxChunkSize ->
-    Bin = recv(MaxChunkSize),
-    NewState = Fun({MaxChunkSize, Bin}, FunState),
-    stream_unchunked_body(Length - MaxChunkSize, MaxChunkSize, Fun,  
NewState);
-stream_unchunked_body(Length, MaxChunkSize, Fun, FunState) ->
-    Bin = recv(Length),
-    NewState = Fun({Length, Bin}, FunState),
-    stream_unchunked_body(0, MaxChunkSize, Fun, NewState).
+stream_unchunked_body(Length, _, Fun, FunState) when Length > 0 ->
+    Bin = recv(0),
+    BinSize = size(Bin),
+    NewState = Fun({BinSize, Bin}, FunState),
+    stream_unchunked_body(Length - BinSize, 0, Fun, NewState).


  %% @spec read_chunk_length() -> integer()


Mime
View raw message