etc.curl: Formal review begin

jdrewsen jdrewsen at nospam.com
Tue Aug 30 11:21:56 PDT 2011


Den 30-08-2011 19:38, Andrei Alexandrescu skrev:
> On 8/30/11 12:22 PM, jdrewsen wrote:
>> Walter suggested that I should write an article about using the wrapper.
>> I've now taken the first steps on writing such an article. I will have
>> to get the library API rock stable before I can finish it though.
>
> I have a suggestion for you - write and test an asynchronous copy program.
>
> It is a continuous source of surprise to me that even seasoned
> programmers don't realize that this is an inefficient copy routine:
>
> while (read(source, buffer))
> write(target, buffer);
>
> If the methods are synchronous and the speeds of source and target are
> independent, the net transfer rate of the routine is R1*R1/(R1+R2),
> where R1 and R2 are the transfer rates of the source and destination
> respectively. In the worst case R1=R2 and the net transfer rate is half
> that.
>
[snip]

I guess that e.g. incoming network buffers in the OS often makes the 
shown copy routine faster than you would think i most cases. These 
buffers stores the incoming network data asynchronously by the OS and 
makes the next read() instantanous. The same can be said about writing 
to disk. Calling sync() is the real enemy here. This is only true as 
long as the buffers are not full of course.

> If your article discusses this and shows e.g. how to copy data optimally
> from one server to another using HTTP, or from one server to a file etc,
> and if furthermore you show how your API makes all that a trivial
> five-liner, that would be a very instructive piece.

That could be an interesting example.

/Jonas


More information about the Digitalmars-d mailing list