Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Immediate writes to underlying stream until buffer is filled #54

Closed
wants to merge 2 commits into from

Conversation

clue
Copy link
Member

@clue clue 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.

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

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

@clue clue force-pushed the immediate-writes branch from 8faeac8 to 96cc409 Compare August 22, 2016 22:34
@clue clue changed the title [WIP] Immediate writes to underlying stream until buffer is filled Immediate writes to underlying stream until buffer is filled Aug 22, 2016
@clue
Copy link
Member Author

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?

{
$stream = fopen('php://temp', 'r+');
$loop = $this->createWriteableLoopMock();
$loop->preventWrites = true;
$loop = $this->createLoopMock();

$buffer = new Buffer($stream, $loop);
$buffer->softLimit = 4;
$buffer->on('error', $this->expectCallableNever());
$buffer->on('drain', $this->expectCallableOnce());
Copy link
Member Author

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
Member Author

clue commented Oct 19, 2016

Can we get this merged?

Absolutely! 👍

It bit me today and wasted many hours.

Huh, care to elaborate?

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

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.

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

clue commented Dec 19, 2016

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

@clue clue changed the title Immediate writes to underlying stream until buffer is filled [WIP] Immediate writes to underlying stream until buffer is filled Jan 24, 2017
@clue clue dismissed WyriHaximus’s stale review January 24, 2017 09:44

Turns out we need to reconsider the drain event first

@clue
Copy link
Member Author

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 👍

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

@clue - Any chance of getting this going again?

@clue
Copy link
Member Author

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 free to 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