Skip to content

Conversation

@clue
Copy link
Member

@clueclue commented Aug 21, 2016

With this change applied, the Buffer will immediately write to the underlying stream instead of waiting for the loop to say it it writable. This is safe because the stream is non-blocking anyway and the Buffer class will return to normal buffer behavior once the data can not be flushed immediately.

Running the examples/benchmark-throughput.php script, this change alone increases performance from ~100 MiB/s to ~160 MiB/s on my (rather mediocre) test system, using PHP 7.0.8.
Combined with #53, it increases performance from ~100 MiB/s to ~1900 MiB/s.

Marking this as WIP because this needs some additional tests once #52 is in. Edit: done.

@clueclue added this to the v0.4.5 milestone Aug 21, 2016
@clue
Copy link
MemberAuthor

clue commented Aug 21, 2016

Afaict this has also been suggested in #15 by @mbonneau around 2 years ago.

@WyriHaximus
Copy link
Member

WyriHaximus commented Aug 21, 2016

This combined with #53 puts my benchmark at 3000MB/s where #53 already raised it to 2500MB/s from 260MB/s on my laptop (PHP 7).

👍 from me

@clueclue changed the title [WIP] Immediate writes to underlying stream until buffer is filledImmediate writes to underlying stream until buffer is filledAug 22, 2016
@clue
Copy link
MemberAuthor

clue commented Aug 22, 2016

Rebased now that #52 is in. Ready for review :shipit:

@WyriHaximus
Copy link
Member

LGTM :shipit:

@davidwdan
Copy link

Can we get this merged? It bit me today and wasted many hours.

WyriHaximus
WyriHaximus previously approved these changes Oct 19, 2016
@WyriHaximus
Copy link
Member

Agreed @davidwdan lets get this in. @clue what is holding us back from merging this and related issues?

$buffer = newBuffer($stream, $loop);
$buffer->softLimit = 4;
$buffer->on('error', $this->expectCallableNever());
$buffer->on('drain', $this->expectCallableOnce());
Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it really make sense to emit a drain event here?

After reconsidering this, we should probably not trigger this event if the data can be flushed immediately. Even though the data may exceed the buffer size, this is an atomic step that can not be observed from the outside.

Instead, we should probably only trigger this event if the buffer returned false previously and it is now ready again.

@clue
Copy link
MemberAuthor

clue commented Oct 19, 2016

Can we get this merged?

Absolutely! 👍

It bit me today and wasted many hours.

Huh, care to elaborate?

@clueclue modified the milestones: v0.4.6, v0.4.5Nov 8, 2016
@clue
Copy link
MemberAuthor

clue commented Nov 13, 2016

Rebased now that #55 is in.

I've moved this PR to the next milestone because it requires an update to not emit a drain event during an immediate write. This actually requires quite a few updates in our test suite because most test cases do not expect immediate writes and thus expect a drain event.

@clueclue removed this from the v0.4.6 milestone Dec 19, 2016
@clue
Copy link
MemberAuthor

clue commented Dec 19, 2016

Removing the milestone for now until the drain behavior is addressed.

@clueclue changed the title Immediate writes to underlying stream until buffer is filled[WIP] Immediate writes to underlying stream until buffer is filledJan 24, 2017
@clueclue dismissed WyriHaximus’s stale reviewJanuary 24, 2017 09:44

Turns out we need to reconsider the drain event first

@clue
Copy link
MemberAuthor

clue commented May 3, 2017

The main focus is currently on getting the v1.0.0 out. As such, there are currently no immediate plans to build this from my end, so I'm closing this for now 👍

@clueclue closed this May 3, 2017
@clueclue deleted the immediate-writes branch May 5, 2017 17:08
@mbonneau
Copy link

@clue - Any chance of getting this going again?

@clue
Copy link
MemberAuthor

clue commented Jan 16, 2018

@mbonneau I'm currently busy working on the other components and this feature does not seem to have a high priority right now, but in case anybody feels like picking this up, I'm happy to help :shipit: 👍

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@clue@WyriHaximus@davidwdan@mbonneau