Skip to content

[Messenger] Batch delivery #51034

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

Open
wants to merge 1 commit into
base: 7.3
Choose a base branch
from

Conversation

hgraca
Copy link

@hgraca hgraca commented Jul 19, 2023

Q A
Branch? 7.1
Bug fix? no
New feature? yes
Deprecations? no
Tickets Fix #47828
License MIT
Doc PR symfony/symfony-docs#18566

Currently, the doctrine transport only delivers one message at a time,
resulting in low performance and a very high amount of hits to the DB.
(one hit per message)

With batch delivery, the transport will retrieve several messages in a single query.

@hgraca hgraca force-pushed the messenger/doctrine_transport_batch_delivery branch from 8ecf8bb to 84e4797 Compare August 1, 2023 19:19
@OskarStark OskarStark changed the title Messenger/doctrine transport batch delivery [Messenger][Doctrine] Batch delivery Aug 2, 2023
@carsonbot carsonbot changed the title [Messenger][Doctrine] Batch delivery [Messenger] Batch delivery Aug 2, 2023
@hgraca hgraca force-pushed the messenger/doctrine_transport_batch_delivery branch from 84e4797 to 18d2270 Compare August 4, 2023 21:29
@hgraca hgraca force-pushed the messenger/doctrine_transport_batch_delivery branch 2 times, most recently from 308f750 to 5572863 Compare August 13, 2023 19:32
@hgraca
Copy link
Author

hgraca commented Aug 13, 2023

I've rebased this PR on branch 6.4, and removed all the commits that were merely small improvements (I will open PRs for them later).

I see that the pipeline is failing but it seems to be unrelated to this PR.

I am, however, afraid that this PR might be getting stale since it is open for a few weeks now.

Is this normal or is there something else that I should do? (I'm new to contributing to Symfony so I really don't know)

btw, there are checks failing but I believe they are unrelated to this PR.

@hgraca hgraca force-pushed the messenger/doctrine_transport_batch_delivery branch 2 times, most recently from bcd4960 to c727bb9 Compare September 25, 2023 20:02
@hgraca
Copy link
Author

hgraca commented Sep 25, 2023

Rebased again and put the changelog in the correct file

@hgraca hgraca force-pushed the messenger/doctrine_transport_batch_delivery branch 6 times, most recently from e6bc6fe to 5501be1 Compare November 5, 2023 09:18
@nicolas-grekas nicolas-grekas modified the milestones: 6.4, 7.1 Nov 15, 2023
@hgraca hgraca force-pushed the messenger/doctrine_transport_batch_delivery branch 2 times, most recently from be723f3 to b12ed43 Compare November 17, 2023 16:29
@hgraca hgraca requested a review from dunglas as a code owner November 17, 2023 16:46
@hgraca hgraca force-pushed the messenger/doctrine_transport_batch_delivery branch 2 times, most recently from b12ed43 to 32105fb Compare November 17, 2023 23:56
Currently, the doctrine transport only delivers one message at a time,
resulting in low performance and a very high amount of hits to the DB.
(one hit per message)

With batch delivery, the transport will retrieve several messages
in a single query.

Co-authored-by: Alexander Malyk <shu.rick.ifmo@gmail.com>
@hgraca hgraca force-pushed the messenger/doctrine_transport_batch_delivery branch from 32105fb to d2bae3b Compare November 21, 2023 15:07
public function __destruct()
{
// The worker using this transport might have pulled 50 msgs out of the mq, marking them as "in process",
// but because of its options (ie --limit, --failure-limit, --memory-limit, --time-limit) it might terminate
Copy link
Author

@hgraca hgraca Nov 22, 2023

Choose a reason for hiding this comment

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

Then I think we would increase complexity and it wouldn't scale.

For --limit we could do some calculations... would be doable despite the increase in complexity..
But for -failure-limit we would need to somehow keep track of how many failures happened, probably replicating logic that is already built somewhere. For --memory-limit and --time-limit the same.

Then, if/when in the future we would add more options, someone would need to also adjust this code, to be able to handle the new option.

With the implementation in this PR however, we don't need to do anything special to adjust to a particular option, neither now nor in the future if/when we add new options.

*/
public function extractDoctrineEnvelopeListIds(array $doctrineEnvelopeList): array
{
return array_map(
Copy link
Member

Choose a reason for hiding this comment

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

return array_column($doctrineEnvelopeList, 'id') will do the same and might be a bit faster by keeping all the logic in the C layer.

@@ -151,7 +155,7 @@ public function send(string $body, array $headers, int $delay = 0): string
return $this->driverConnection->lastInsertId();
}

public function get(): ?array
public function get(): array
Copy link
Member

Choose a reason for hiding this comment

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

I suggest document the type of the returned array.

],
[
Types::DATETIME_IMMUTABLE,
class_exists(ArrayParameterType::class) ? ArrayParameterType::INTEGER : Types::SIMPLE_ARRAY,
Copy link
Member

Choose a reason for hiding this comment

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

This is wrong. Types::SIMPLE_ARRAY is something totally different. The fallback for older DBAL versions is Connection::PARAM_INT_ARRAY.

And the code below does not check for older versions, so it is inconsistent.

@@ -58,11 +60,16 @@ public function get(): iterable
throw new TransportException($exception->getMessage(), 0, $exception);
}

if (null === $doctrineEnvelope) {
if (null === $doctrineEnvelopeList) {
Copy link
Member

Choose a reason for hiding this comment

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

This won't ever be true. Connection::get cannot return null anymore.

@@ -83,6 +90,11 @@ public function reject(Envelope $envelope): void
}
}

public function undeliverNotHandled(): void
Copy link
Member

Choose a reason for hiding this comment

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

should it be marked as @internal ?

@xabbuh xabbuh modified the milestones: 7.1, 7.2 May 15, 2024
@fabpot fabpot modified the milestones: 7.2, 7.3 Nov 20, 2024
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.

[Messenger] Bad performances with the Doctrine/MySQL transport
7 participants