JuliaLang/julia — pull request #6768 by amitmurthy (2014-05-06 16:26:01+00:00)
Title: Reduce memory footprint while reading an array from an asyncstream object

Currently, deserializing a large array, say a couple of GB, results in the following:
1) The entire array is first recd into an IOBuffer associated with the socket, from where it is then copied onto the allocated array.
2) The IOBuffer associated with the socket is never compressed, which means it continues to occupy as much memory as the largest array ever recd for the lifetime of the connection.

This PR changes the above behavior to
1) Reads arrays from asyncstream objects directly into the array memory instead of via the sockets intermediate iobuffer.
2) Limits the length of data stored in the asyncstream's iobuffer. Pauses the libuv socket reads till user code actually starts requesting data from the asyncstream object.

Without this patch
```
julia> remotecall_fetch(2, ()->ones(2^28));
julia> println(length(Base.PGRP.workers[2].socket.buffer.data))
2147511424
julia> println(length(Base.PGRP.workers[2].socket.buffer.data))
2147511424
```

With this patch
```
julia> remotecall_fetch(2, ()->ones(2^28));
julia> println(length(Base.PGRP.workers[2].socket.buffer.data))
131072
julia> println(length(Base.PGRP.workers[2].socket.buffer.data))
131072
```