-
Notifications
You must be signed in to change notification settings - Fork 129
Fix: FlatFileDriver does not notice new messages #330
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
Fix: FlatFileDriver does not notice new messages #330
Conversation
I think we should check if the problem still persists after merge of #308 and merge this after! But already thanks for the work on this! |
@ackintosh I will take a look at this PR later today! |
Sorry for the delay! Changes look good to me, but can you add a test for this behavior (messages added after the initial collect)? |
193b3e2
to
aa25569
Compare
aa25569
to
6e7d758
Compare
tests/Driver/FlatFileDriverTest.php
Outdated
} | ||
|
||
$this->driver->createQueue('send-newsletter'); | ||
$snidel = new Snidel(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A test case for this behavior requires multiprocess(pop, push). Snidel (depends bernard!) provides the easiest way to achieve that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use the php internal function pcntl_fork
for this instead of snidel?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No real big issue, just checking if we can avoid an extra dependency 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. If that's what you want, I will rewrite it. 💡
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This library looks really interesting, thanks for sharing. Nevertheless, I second @acrobat 's opinion: let's keep the dependencies at the absolute minimum if possible.
@acrobat @sagikazarmark Thank you for your review! I replaced Snidel with pcntl_fork. |
.gitignore
Outdated
phpunit.xml | ||
coverage | ||
_build | ||
.idea |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please remove this added line as it is not project specific and should be added to your global .gitignore
file
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only a small comment about the gitignore file, the rest looks good! Thanks for your extra time to rewrite the tests!
I fixed it! |
After going trough this PR I realized that it probably affects performance as well since between the loops it reads the whole file list again. I would love to see some benchmarks comparing this version to the previous one, just to make sure it does not introduce a performance regression. But I don't think it blocks merging @acrobat ! |
I will try to do some benchmarks before merging, just to be sure we don't have (huge) performance regressions or if you are able to do some tests (or blackfire profiles) @ackintosh would be nice to! (Not sure if I will find time before mid next week or so) |
I would not say that this could cause a performance bug because it is only reading the directory again if there are no files. The other solution would be to not enter the while loop because it makes no sense to run when there are no files. But this would cause the job to quit and it must be restarted manually or automatically. So for my opinion this is the better solution as the runtime is used to find messages and not to always ask the driver again and again. But I think there is not the right way for it. |
I've tried to benchmark with blackfire and it seems there's no critical performance problems. Here is the sample code used on benchmark and the results of profile. Please let me know if there's something wrong on the result or my profiling.
<?php
require_once(__DIR__ . '/vendor/autoload.php');
$driver = new \Bernard\Driver\FlatFile\Driver(__DIR__ . '/queue');
$driver->createQueue('test');
list($message,) = $driver->popMessage('test', 30);
var_dump($message);
https://blackfire.io/profiles/eb65f6df-c03f-43be-8fa4-be953c471c95/graph
https://blackfire.io/profiles/bd1aec80-1ee9-406e-bf62-8492a307c4b1/graph |
Resolved the conflicts between master branch. 😉 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @ackintosh !
FlatFileDriver does not notice new messages until the polling duration ends.
So we should update the
$files
. 💡