Тёмный
No video :(

Laravel: Optimize Queue Jobs To Be "Dumb" With Fewer Parameters 

Laravel Daily
Подписаться 143 тыс.
Просмотров 13 тыс.
50% 1

I will show you a before/after practical example of queue jobs, if we pass the full object, or if we pass the exact variable values only.
Related links:
- Scaling Laravel to 30,000 requests/min and over 100M jobs subscribe.mate...
- My course "Queues in Laravel": laraveldaily.t...
- - - - -
Support the channel by checking out my products:
- My Laravel courses membership: laraveldaily.t...
- Laravel QuickAdminPanel: bit.ly/quickad...
- Livewire Kit Components: livewirekit.com
- - - - -
Other places to follow:
- My weekly Laravel newsletter: bit.ly/laravel-...
- My personal Twitter: / povilaskorop

Опубликовано:

 

21 авг 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 42   
@michaelcrash
@michaelcrash 2 года назад
cool. I would use contructor() to deconstruct object and store what I want to be use in handle() later on.
@jrplops89
@jrplops89 2 года назад
Your pronunciation of Portuguese names is very good! :)
2 года назад
Haha I was going to mention this. Really good!
@LaravelDaily
@LaravelDaily 2 года назад
Benefit of watching football in childhood, including many famous Portuguese names so now I know how to pronounce them :)
2 года назад
Great video. Thanks for the mention, Povilas!
@nadjinmalade8738
@nadjinmalade8738 2 года назад
For Real, we learn a lot from your videos. Thanks.
@daleryanaldover6545
@daleryanaldover6545 2 года назад
I learned this the hard way, real hard.
@mmramadan496
@mmramadan496 2 года назад
It's a huge time optimization, but it's important to pass a model instance for some cases, for illuminate, what if you need to queue sending mails when the user write his email and let's assume that the user wrote an invalid mail and he realized that after clicking submit button, in this case when the queue get started working he will not recieve any email because we pass his mail not model instance, but what if after realizing that he wrote invalid mail, he write a valid one, and we pass model instance, Laravel will retrieve the last mail because Laravel uses the `SerializesModels` trait.
@Shez-dc3fn
@Shez-dc3fn 2 года назад
i guess this video only works if you only need 'selective' things - so use it when you need, not EVERY TIME..
@JoseHenrique-xg1lp
@JoseHenrique-xg1lp 4 месяца назад
Very useful, thank you
@RodrigoNishino
@RodrigoNishino Год назад
Very nice! Thank you very much
@twentxx
@twentxx 2 года назад
Thank you very much 👍
@linasgutauskas5528
@linasgutauskas5528 2 года назад
What if i need to store results from job to database? Or if i want to save job status in database (if it was successful)? Is there any good practices on these cases? Thank you.
@daleryanaldover6545
@daleryanaldover6545 2 года назад
There is something new called Job Events, I don't remember that kind of functionality before but now you can pass results from job to database using before or after events. Check out the docs for more info.
@ivan_adamovich
@ivan_adamovich 2 года назад
Sir, can i ask you to make a video about websocket? how it works, how to use and ect.
@LaravelDaily
@LaravelDaily 2 года назад
Not in plans, for now, here's why: twitter.com/PovilasKorop/status/1470640480593801216
@GergelyCsermely
@GergelyCsermely 2 года назад
Tahnks
@ryonnl
@ryonnl 2 года назад
What would you do if you need the actual model in the job itself? Query it?
2 года назад
When you pass the model, Laravel automatically queries it behind the scenes when it picks up the job. So that’s another thing to be aware of: if you pass the actual model, the state you get by the time your queue worker picks it up might be different from what you expect.
@Shez-dc3fn
@Shez-dc3fn 2 года назад
i dont understand if I send the USER to a job, Its serialised and saved in jobs table next to that job - when the job is run, why would LARAVEL make a new call to user table? surely it deserializes the saved user and works with that?
2 года назад
Laravel doesn’t serialize the state, but the model’s class and ID so it can query it when the job is picked up. That allows you to avoid working with incorrect state and also make the payload smaller
@budiprihhastomo5936
@budiprihhastomo5936 2 года назад
But does this case apply to very large payloads? For example, I created a job to store logs in the database, of course the logs will contain the information we need, and if it's a lot, won't passing it into parameters will only make the payload stored in the database fatter than we use serialize model?
@LaravelDaily
@LaravelDaily 2 года назад
Your example is pretty extreme, I would say. Yes in some cases it's worth storing the model and then query the data when needed.
@budiprihhastomo5936
@budiprihhastomo5936 2 года назад
@@LaravelDaily Thank you for the answer sir, maybe now I understand better if I have to use one of them. 👍
@SLIMBOY489
@SLIMBOY489 2 года назад
Off topic question but, in your experience, how many requests can handle a Laravel API per second?
@LaravelDaily
@LaravelDaily 2 года назад
Haven't tested it. Googled "laravel benchmarks", found this 2017 article: medium.com/@taylorotwell/benchmarking-laravel-symfony-zend-2c01c2b270f8#:~:text=Laravel%3A%20521.64%20requests%20per%20second%20(mean) But generally, it depends on what your API does.
@cykablyatii2086
@cykablyatii2086 2 года назад
is it better if we dispatch a job inside a loop? or do the loop inside the job?
@LaravelDaily
@LaravelDaily 2 года назад
I prefer many small individual jobs.
@danjanuspineda4330
@danjanuspineda4330 2 года назад
how about chunking so it does not run out of memory, most of the times this speed in sending email are not that much necessary, wdyt sir, thanks for your content
@LaravelDaily
@LaravelDaily 2 года назад
Sending email is just an example, jobs may be for other things, it's a general advice. But yes, batching and grouping jobs is also possible, but not sure how it would save memory exactly.
@Saifallak
@Saifallak 2 года назад
​@@LaravelDaily i guess he means while getting the data `User::all()`, chunking here saves you, because loading much data in memory is a bad idea
@daleryanaldover6545
@daleryanaldover6545 2 года назад
@@Saifallak he should never use User::all() with jobs. It's always better to trigger jobs on a single instance of model. But for a similar case, I used to generate reports using jobs, and passing a huge number of models would simply make php ran out of memory. In this case trim out unnecessary attributes from the models. This can be done by querying only needed columns explicitly so the result of User::all() would only include teh needed attributes.
@iamriwash7943
@iamriwash7943 2 года назад
can u make a video about how to send email with email template support of CSS ????
@LaravelDaily
@LaravelDaily 2 года назад
That wouldn't be video about Laravel, then. It would be about some CSS template in HTML email, I'm not an expert in that, look for that info on some front-end related channel.
@iamriwash7943
@iamriwash7943 2 года назад
@@LaravelDaily no in laravel when we send email in laravel CSS does not show in email
@abduzzy
@abduzzy 2 года назад
you can use css with inline or internal style in blade template. If you want to use tailwind as css style, you should check maizzle.
@daleryanaldover6545
@daleryanaldover6545 2 года назад
@@abduzzy laravel actually comes with a mail feature, complete with css customisations. He can simply publish the assets and modify it from there. It will be converted to in-line css by the mailable class.
@daleryanaldover6545
@daleryanaldover6545 2 года назад
@@iamriwash7943 laravel had a documentation about mailable class, it's pretty easy to understand.
@unitaxi1644
@unitaxi1644 2 года назад
When will be published new course in teachable platforme ?
@LaravelDaily
@LaravelDaily 2 года назад
Today or tomorrow, if everything is according to the plan
@LaravelDaily
@LaravelDaily 2 года назад
It's out: laraveldaily.teachable.com/p/laravel-testing-for-beginners-phpunit-and-pest
2 года назад
so helpful