News for hackers. Stuff that matters.
Re:Fibers: An Elegant Windows API by magicalhippo on Friday March 29, 2019 @11:49AM (#19522685)
What would you have the OS do?

If you got connections with inbound data, the OS has to store it somewhere. Might as well be in your read buffer right away.

If you ask the OS to read 4k from 10k files simultaneously, why are you surprised that the OS wants the buffer to stay around until the read is completed?

Re:Fibers: An Elegant Windows API by jstimpfle on Friday March 29, 2019 @12:07PM (#19522850)
It should let me choose which buffer I want to use next, from a pool of buffers that I provide.

There is no point in having a 1:1 relationship between buffers and read handles.

Re:Fibers: An Elegant Windows API by magicalhippo on Friday March 29, 2019 @12:17PM (#19522952)
That doesn't sound very performant having to switch back into userspace just to get another buffer, then back into kernel space to continue completing the read.

Though as far as I can see you could get close to what you wish by doing 1 byte reads.

Re:Fibers: An Elegant Windows API by jstimpfle on Friday March 29, 2019 @12:23PM (#19523035)
Your snarkiness is not appreciated and I never said you should do constant switching. It's not required.

> If you ask the OS to read 4k from 10k files simultaneously

There is a difference between between copying inbound data from 10k handles simultaneously (which does require as many buffers) on the one hand, and on the other hand being open to read from any M-sized subset of 10k handles at once, which requires only M buffers.

I also never said to have only 4k of (combined) buffer data for 10k handles. "4k should be a reasonable read buffer size" means 4k per buffer. I don't think I've been unclear, but with a tiny bit of good will you could have figured out what I meant anyway.

Re:Fibers: An Elegant Windows API by magicalhippo on Friday March 29, 2019 @12:52PM (#19523344)
FWIW I'm not trying to be snarky.

> I never said you should do constant switching. It's not required.

I didn't see any other way to interpret your "It should let me choose which buffer I want to use next".

Though perhaps what you meant was that you want to be able to tell the OS "yo, here's a bunch of buffers, use these to complete my reads"?

> [...] and on the other hand being open to read from any M-sized subset of 10k handles at once, which requires only M buffers.

I interpret that as saying "yo OS, I want to read 4k each from these 10k files, but only use these M 4k buffers when doing so", where M << 10k.

If a request is slow to be fulfilled won't it hog a buffer, reducing the maximum throughput of the fast requests? Why would this be a performance win?

Re:Fibers: An Elegant Windows API by jstimpfle on Friday March 29, 2019 @01:05PM (#19523488)
> Though perhaps what you meant was that you want to be able to tell the OS "yo, here's a bunch of buffers, use these to complete my reads"?

Thank you for clarifying, and yes, that would be the best way to do it I think.

> If a request is slow to be fulfilled won't it hog a buffer, reducing the maximum throughput of the fast requests? Why would this be a performance win?

So someone else here said that with IOCP the kernel doesn't have its own read buffers but writes directly to userspace memory (in cases where this is possible, anyway). So there might be a possiblity for buffer hogging, I don't know. On the other hand, when the request really is slow to be fulfilled, the OS could just call it a partial write and notify the program of a (partial) completion. In which case the buffer is free for other uses again.

Re:Fibers: An Elegant Windows API by magicalhippo on Friday March 29, 2019 @01:24PM (#19523692)
Thanks for the follow-up. Would be interesting to see if it made much difference in the end, guess we'll have to wait a bit longer for all of Windows to be open sourced :P
Re:Fibers: An Elegant Windows API by magicalhippo on Friday March 29, 2019 @12:54PM (#19523365)
> I also never said to have only 4k of (combined) buffer data for 10k handles. "4k should be a reasonable read buffer size" means 4k per buffer.

I never thought the former, only the latter.

Re:Fibers: An Elegant Windows API by jstimpfle on Friday March 29, 2019 @01:07PM (#19523513)
Oh I see, it was the other commenter saying "less than 1 byte per buffer" and you only said "by doing 1 byte reads". It seems I really was a little unclear and should try to hold my horses.
Re:Fibers: An Elegant Windows API by magicalhippo on Friday March 29, 2019 @01:23PM (#19523685)
No harm done :)

My idea was to exploit the caching mechanism in the OS. Though clearly it wouldn't be as efficient as providing a set of buffers for the OS to use.