With the recent Sylius release v1.11, we've introduced a brand new feature - catalog promotions. As this feature may require processing a significant amount of data(the whole product catalog), we had to decide on async processing by default. But it does not mean that we can waste resources and not optimize the processing algorithm! We had to improve it and to do that we've been using Blackfire. During my presentation, I will bring you on the journey we've done to make catalog processing better from a performance point of view and beyond. The presentation will be based on real examples from Sylius. Nonetheless, its takeovers may be helpful in any Symfony app.
Presentation available at: https://live.symfony.com/account/replay/video/646
4. sylius.com
4
Product variants
Always have Y Channel Pricings,
Where Y equals amount of Channels in shop
Product
May have from 1 to N variants
Channel Pricing
Contains end pricing for customer
Sylius pricing model
5. sylius.com
Discounting rules set
5
Main con
fi
guration
Dates
Channels
Enabled
Priority
Exclusiveness
Processing scope
Variants
Products
Taxonomy
Resulting actions
Fixed discount
Percentage discount
6. sylius.com
6
1 - 10
To process updates of
Products through UI interface
Minimal processable scope
As a business rule
10k - 100k
Default behaviour should
Be consider for these values
Typical Sylius project
Based on the clients we are working the most
Over 1kk
Feature should be possible
To be used with this scope
Maximal processable scope
From the projects we know
Dataset size
8. sylius.com
8
Take all eligible catalog promotions
This step can be outsourced to DB
Fetch variants for given promotion
To ensure that only correct ones applies
Apply promotion for given variants
Go to the next promotion
Execute second step
Catalog Promotion
Processing order
Take all product variants
This step can be outsourced to DB
Take all eligible catalog promotions
This step can be outsourced to DB
Apply promotion for given variant
Product Variant
10. sylius.com
?
Dataset
7000 Product Variants
3 Catalog Promotions covering all of products at least once
2 Channels
Execution on single catalog promotion update
Triggering CatalogPromotionUpdated event
Environment
Production environment
No debug option
Removal of cache and cache warmup before each execution
<
E
10
11. sylius.com
11
Command Batching
Doctrine
Fetching only codes to avoid hydration
Flushing & transaction out-of-the-box
Clearance of entity manager
Symfony Messenger
No need for custom command
Flushing & transaction out-of-the-box
Sync & async switch is piece of cake
109. sylius.com
109
Check the highest class in your callgraph
And look for bugs
Remember to clear Entity Manager when batch processing
Unless you are executing asynchronously messages with Symfony Messenger
Load all data required to perform operation
But not more
Pure DQL may bring bene
fi
ts
But is hard to do it properly for complicated objects or mix it with ORM