Skip to content

Feature: Optimize DBConfigurableConsumer with a slow mode after a cer…#28

Merged
GaryPEGEOT merged 7 commits intomasterfrom
feature/optimize-db-consumer-consume
Jul 31, 2018
Merged

Feature: Optimize DBConfigurableConsumer with a slow mode after a cer…#28
GaryPEGEOT merged 7 commits intomasterfrom
feature/optimize-db-consumer-consume

Conversation

@BertrandF23
Copy link
Contributor

…tain period of inactivity.

Because now with the DBConfigurableConsumer, we consume with an endless frantic loop. This change allow to enter in a slow mode after some inactivity. When a new message is coming, then we leave that slow mode, until a long period of inactivity is detected again.

@GaryPEGEOT GaryPEGEOT force-pushed the feature/optimize-db-consumer-consume branch from 10909b8 to 8ca5f16 Compare July 30, 2018 13:09
if ($this->logger) {
$now = \DateTime::createFromFormat('U.u', microtime(true));
$this->logger->info('A message was consumed on '.$now->format('Y-m-d H:i:s.u'));
$this->logger->info('A message was consumed on {date}', ['date' => date('Y-m-d H:i:s.u')]);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

If you do like this you won't have the microseconds petit padawan ;-).
Try this :
`<?php
echo date('Y-m-d H:i:s.u');

$now = \DateTime::createFromFormat('U.u', microtime(true));
echo $now->format('Y-m-d H:i:s.u');`

$resolver->setDefaults([
self::OPTION_STOP_ON_NO_RESULTS => false,
self::OPTION_DB_CONNECTION_NAME => '',
self::OPTION_SLEEP_TIME => 100,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe by default we don't want the behaviour to change... So it would be a very high value for OPTION_INACTIVITY_TRIGGER...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can keep it like this, because without sleep time it is so bad and he will be tired.

@@ -41,11 +43,13 @@ public function configureOptionsResolver(OptionsResolver $resolver)
$resolver->setDefaults([
self::OPTION_STOP_ON_NO_RESULTS => false,
self::OPTION_DB_CONNECTION_NAME => '',
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 saw that you changed OPTION_DB_CONNECTION_NAME to be a numeric. So why the default value is ''?

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 saw you fixed it.

$options = [
ConfigurableDbalProtocol::OPTION_METHOD => 'myMethod',
ConfigurableDbalProtocol::OPTION_STOP_ON_NO_RESULTS => true,
ConfigurableDbalProtocol::OPTION_SLEEP_TIME => 10000,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is it possible to have a lower sleep time, because it means that this only test lasts at least 10 seconds... Like 2 seconds?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The way phpunit bridge works is brilliant. You are a genius. Or at least you use other geniuses tools. Well done.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

phpunit bridge does the job. You are a genius.


script:
- bin/phpunit --coverage-text --debug
- bin/simple-phpunit --coverage-text
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good improvement ;-)

$this->onConsume($endpoint, $message);
$wakeup = microtime(true);
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If we added extra line codes here, that take more than $inactivityTrigger, then we could trigger the nap by mistake... And it then it could make the system up to 50% slower.
The way it was done was not the best but it avoided that situation. Maybe it is not that important...!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The use of "iFeelAsleep" made sure that you would not have a nap just after consuming a message.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay we can keep it like this. There are pros and cons, but (development) time matters.

@GaryPEGEOT GaryPEGEOT self-requested a review July 31, 2018 09:55
@GaryPEGEOT GaryPEGEOT merged commit 3da379c into master Jul 31, 2018
@BertrandF23 BertrandF23 deleted the feature/optimize-db-consumer-consume branch July 31, 2018 16:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants