Skip to content

Implement ExtEvLoop (PECL ext-ev) #148

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

Merged
merged 4 commits into from
Apr 8, 2018
Merged

Conversation

ivkalita
Copy link
Contributor

@ivkalita ivkalita commented Jan 15, 2018

@clue, @WyriHaximus, @jsor hello!

Finally I fixed my old pull request. I'm really sorry that it took so long for me.

I hope, that this feature still wanted and needed :)

@WyriHaximus
Copy link
Member

Hey @kaduev13 yes your PR is still wanted, in fact the plan was to take over and finish your PR once v0.5.0 gone out. Will look into this one later today or tomorrow 👍 .

@ivkalita ivkalita force-pushed the ext-ev-loop branch 2 times, most recently from 405cb25 to 41018f5 Compare January 15, 2018 20:48
Copy link
Member

@clue clue left a comment

Choose a reason for hiding this comment

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

@kaduev13 Thank you so much for keeping up with this and filing an update! 👍

I've found some minor issues below, otherwise LGTM 👍

},
function ($signal) {
if ($this->signals->count($signal) === 0) {
unset($this->signalEvents[$signal]);
Copy link
Member

Choose a reason for hiding this comment

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

This should probably stop() the watcher before clearing this reference, no?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it's very important to stop watcher before clearing the reference. Fixed.

private function getStreamListenerClosure($stream, callable $listener)
{
return function () use ($stream, $listener) {
call_user_func($listener, $stream, $this);
Copy link
Member

Choose a reason for hiding this comment

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

The additional $loop argument has been removed via #110, so the last parameter should be omitted here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for pointing it! I removed this argument.

src/Factory.php Outdated
} elseif (class_exists('EvLoop', false)) {
return new ExtEvLoop();
}
elseif (class_exists('EventBase', false)) {
Copy link
Member

Choose a reason for hiding this comment

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

Minor CS issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed, thank you :)

$this->loop->removeSignal(SIGUSR1, $function);
$this->loop->stop();
});

$this->assertRunSlowerThan(1.5);
$this->assertRunSlowerThan(2);
Copy link
Member

Choose a reason for hiding this comment

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

What is the motivation for this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought that there was a problem with floating point accuracy, but it was not. It should be changed to the previous 1.5 value. Fixed.

@ivkalita ivkalita force-pushed the ext-ev-loop branch 2 times, most recently from 97d946c to 8aef041 Compare January 16, 2018 16:04
@ivkalita
Copy link
Contributor Author

Also, I noticed that other loops implementations contains such code for signals callbacks:

function ($signal) {
    $this->signalEvents[$signal] = new SignalEvent($f = function () use ($signal, &$f) {
        $this->signals->call($signal);
        // Ensure there are two copies of the callable around until it has been executed.
        // For more information see: https://bugs.php.net/bug.php?id=62452
        // Only an issue for PHP 5, this hack can be removed once PHP 5 support has been dropped.
        $g = $f;
        $f = $g;
    }, $signal);
    $this->loop->add($this->signalEvents[$signal]);
},

My question is why using the $f identifier? Why not just

function ($signal) {
    $this->signalEvents[$signal] = new SignalEvent(function () use ($signal) {
        $this->signals->call($signal);
    }, $signal);
    $this->loop->add($this->signalEvents[$signal]);
}

@WyriHaximus
Copy link
Member

@kaduev13 The issue in PHP 5.x is that the callable we're calling $this->signals->call($signal); can get cleaned up by the engine while we're still in it causing odd errors. By referencing $f and juggling it again $g we ensure the engine keeps it around for after the $this->signals->call($signal);.

@ivkalita
Copy link
Contributor Author

@WyriHaximus, I checked that issue, but, as I understood, this bug is about aliasing. I mean, that this code will randomly fail:

function ($signal) {
    $this->signalEvents[$signal] = new SignalEvent($f = function () use ($signal, &$f) {
        $this->signals->call($signal);
    }, $signal);
    $this->loop->add($this->signalEvents[$signal]);
}

but this one should not (no alias == no problems?):

function ($signal) {
    $this->signalEvents[$signal] = new SignalEvent(function () use ($signal) {
        $this->signals->call($signal);
    }, $signal);
    $this->loop->add($this->signalEvents[$signal]);
}

@WyriHaximus
Copy link
Member

@kaduev13 feel free to prove me wrong, I don't like the solution for that bug so if we can get rid of it that would be great 👍 . Also be sure to check signal example to be sure. IIRC this is one of the failing builds for that bug: https://travis-ci.org/reactphp/event-loop/jobs/258431073#L1054

@ivkalita
Copy link
Contributor Author

@WyriHaximus, thank you! Unfortunately, the build url you provided is for commit, that does not exist. I'll try to reproduce this behavior.

@WyriHaximus
Copy link
Member

@kaduev13 yes correct/sorry about that the commits where squashed just before merging to keep a clean commit log.

@ivkalita
Copy link
Contributor Author

@WyriHaximus sorry, I didn't have enough time to completely test the issue with lambdas. I'll continue my investigation later. I added similar workaround to ExtEvLoop to ensure that everything will work well.
@clue, I fixed issues you have pointed at, review this changes again, please :)

@clue
Copy link
Member

clue commented Feb 6, 2018

@kaduev13 Very good point about signal handling callbacks! I've just filed #150, once this is in, this should be simplified significantly (this will likely cause a merge conflict here though).

@clue clue changed the title Implement ExtEvLoop. Implement ExtEvLoop (PECL ext-ev) Feb 7, 2018
@ivkalita ivkalita force-pushed the ext-ev-loop branch 2 times, most recently from 12d714f to 242fc11 Compare February 28, 2018 17:16
@ivkalita
Copy link
Contributor Author

@clue nice work with signals, thank you! I rebased this branch onto master, review pls =)

ExtEvLoop implements event loop based on PECL ev extension.
Copy link
Member

@WyriHaximus WyriHaximus left a comment

Choose a reason for hiding this comment

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

LGTM :shipit:

Copy link
Member

@clue clue left a comment

Choose a reason for hiding this comment

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

@kaduev13 Again, thank you so much for keeping up with this and putting the effort into keeping this updated! 👍

Only this one minor remark, otherwise I'm happy to get this in finally! :shipit: 🎉

public function isTimerActive(TimerInterface $timer)
{
return $this->timers->contains($timer);
}
Copy link
Member

Choose a reason for hiding this comment

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

This method has been removed from the public interface with #133, so this should probably be removed here.

@@ -201,6 +201,16 @@ It supports the same backends as libevent.

This loop is known to work with PHP 5.4 through PHP 7+.

#### ExtEvLoop
Copy link
Member

Choose a reason for hiding this comment

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

Should also be added to the TOC above 👍

@ivkalita
Copy link
Contributor Author

ivkalita commented Apr 6, 2018

@clue thank you for the review :) I fixed these issues.

Copy link
Member

@clue clue left a comment

Choose a reason for hiding this comment

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

Awesome, thank you for the update! :shipit: 🎉

@WyriHaximus WyriHaximus merged commit 5511b21 into reactphp:master Apr 8, 2018
@WyriHaximus
Copy link
Member

Awesome, thank you 👍 !

@ivkalita
Copy link
Contributor Author

ivkalita commented Apr 9, 2018

Great to know that it's merged! Thank you!

@WyriHaximus
Copy link
Member

@kaduev13 v0.5.1

@WyriHaximus
Copy link
Member

@kaduev13 FYI I've been running it in production for a week now, as expected no issue what so ever. Well done 👍

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