Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[Messenger] implementation ofmessenger:consume, which processes messages concurrently#53964

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
alli83 wants to merge1 commit intosymfony:7.4
base:7.4
Choose a base branch
Loading
fromalli83:messenger-handling-concurrent-messages

Conversation

alli83
Copy link
Contributor

@alli83alli83 commentedFeb 16, 2024
edited by OskarStark
Loading

QA
Branch?7.3
Bug fix?no
New feature?yes
Deprecations?no
Issues
LicenseMIT

The purpose of this PR is to enable concurrent handling of Symfony Messenger messages. This PR utilizes the amphp/parallel library to achieve this. During the worker configuration, it is possible to define how many processes should be batched in parallel before flushing, meaning accessing the result, acknowledging, or initiating executions in case of errors.

In the child process, a container is cached. Therefore, in each child process, it will be possible to inject services and make requests, etc.

In this initial use case, the decision was made not to reuse the parent connection, such as the Doctrine connection. This is because it could currently be inconvenient for users, as they would need to modify their handlers, which could be cumbersome.

Even without reusing the parent connection, there is a performance gain since operations are performed concurrently for x number of processes. Therefore, even if there is a handler with blocking code, it does not prevent other child processes from proceeding.
for example, in the case we have 2 handlers and one of the handlers has a 4-second pause, and we have, for instance, 40 messages processed concurrently with a batch size of 10 using the ParallelBus, it's approximately 6 times faster between handling the first message and the last message (This observation was made during a test conducted in our development environment)

In order to dispatch messages concurrently, it is necessary to first consider the ParallelMessageBus:
! It works for async mode - It doesn't work with BatchHandler Trait !

Async mode:

$this->bus->dispatch(newUserMessage($user->getId()), [newBusNameStamp('parallel_bus')]);

You can specify how many processes will be executed in parallel.
It will define how many processes will be launched - threaded to then complete them one by one and get the return of the message processing
By default: 10

php bin/console messenger:consume async -p 20

TODO:

  • CHANGELOG:

This feature is being developed by@coopTilleuls and@TradersPost and it has been designed with@jwage and@dunglas

welcoMattic, kbond, antoniovj1, ging-dev, jwage, chalasr, root-aza, dunglas, bkosun, and matyo91 reacted with rocket emoji
@carsonbotcarsonbot added this to the7.1 milestoneFeb 16, 2024
@carsonbotcarsonbot changed the title[Messenger] implementation of messenger:consume, which processes messages concurrently[Messenger] implementation of messenger:consume, which processes messages concurrentlyFeb 16, 2024
@alli83alli83force-pushed themessenger-handling-concurrent-messages branch fromea02a2e to8cf4f65CompareFebruary 16, 2024 08:03
Copy link
Member

@lyrixxlyrixx left a comment

Choose a reason for hiding this comment

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

quick review, I like it

jwage reacted with thumbs up emoji
@alli83alli83force-pushed themessenger-handling-concurrent-messages branch 2 times, most recently from8b8e52c to66200dbCompareFebruary 16, 2024 08:16
@alli83alli83force-pushed themessenger-handling-concurrent-messages branch 3 times, most recently fromc1d082a to89b22b9CompareFebruary 16, 2024 08:42
@alli83alli83force-pushed themessenger-handling-concurrent-messages branch from89b22b9 to885c278CompareFebruary 16, 2024 13:36
Copy link
Contributor

@jwagejwage left a comment

Choose a reason for hiding this comment

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

Nicely done! Just a few questions/comments.

@alli83alli83force-pushed themessenger-handling-concurrent-messages branch 11 times, most recently from8fac51d tof35b5adCompareFebruary 25, 2024 22:34
@alli83alli83force-pushed themessenger-handling-concurrent-messages branch frome6b8863 to5d6bae6CompareAugust 17, 2024 06:24
@alli83alli83 marked this pull request as draftAugust 19, 2024 13:53
@alli83alli83force-pushed themessenger-handling-concurrent-messages branch 5 times, most recently fromf976458 to52e9176CompareAugust 20, 2024 01:15
@alli83alli83force-pushed themessenger-handling-concurrent-messages branch from52e9176 to522a316CompareAugust 20, 2024 03:56
@alli83alli83 marked this pull request as ready for reviewAugust 20, 2024 21:53
@@ -282,4 +329,37 @@ public function getMetadata(): WorkerMetadata
{
return $this->metadata;
}

public function handleFutures(string $transportName, $parallelProcessLimit): void
Copy link
Member

Choose a reason for hiding this comment

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

$parallelProcessLimit seems unused

@IndraGunawan
Copy link
Contributor

IndraGunawan commentedOct 4, 2024
edited
Loading

@dunglas@alli83 any chance this feature will be included in v7.2 release?

@dunglas
Copy link
Member

@IndraGunawan I'd love to, but I can't decide that on my own 😅

@fabpotfabpot modified the milestones:7.2,7.3Nov 20, 2024
Copy link
Member

@dunglasdunglas left a comment

Choose a reason for hiding this comment

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

when conflicts will be resolved

@matyo91
Copy link
Contributor

! It works for async mode - It doesn't work with BatchHandler Trait !

It's relevant. BatchHandler will handle processing data synchronously. If I understood well, do you suggest it miss async capabilities? Somehow updating BatchHandler to make it async aware or declaring another BatchAsyncHandler trait could allow processing batch messaging with async mechanisms.

jwage reacted with thumbs up emoji

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@stloydstloydstloyd left review comments

@jwagejwagejwage left review comments

@lyrixxlyrixxlyrixx left review comments

@OskarStarkOskarStarkOskarStark left review comments

@oleg-andreyevoleg-andreyevoleg-andreyev left review comments

@NyholmNyholmNyholm left review comments

@withinboredomwithinboredomwithinboredom requested changes

@dunglasdunglasdunglas approved these changes

Assignees
No one assigned
Projects
None yet
Milestone
7.4
Development

Successfully merging this pull request may close these issues.

14 participants
@alli83@jwage@IndraGunawan@dunglas@matyo91@stloyd@lyrixx@OskarStark@oleg-andreyev@Nyholm@withinboredom@fabpot@xabbuh@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp