Laravel Queue fall asleep when Queue is empty
I have a controller function which dispatchs a job
. When this job
is handled, at the end it dispatch the same job
again (with different args). There are 5 jobs of the same in total.
Queue driver: database
The problem is: I record the time duration from create()
to handle()
. The first job dispatched by the controller took 1700ms, where the other jobs dispatched by the jobs themselves took only 40ms.
Queue driver: sync
When I changed to use sync
queue driver, all the jobs worked in lightning speed.
Findings:
The first queue job took long time from create()
to handle()
. Before that the queue was empty. It might be the queue driver problem.
Why and how to fix please? thanks!!
UPDATE:
Added a TestJob
that dispatch itself when job was handled. That meant the queue always had a TestJob
being handled or waiting for handling.
Repeating my original jobs, they all took only <70ms from created()
to handle()
completed.
Conclusion:
I am pretty sure it is the queue driver problem. Looks like the worker fall asleep when the queue is empty. Do anyone know the fix please?
laravel performance queue jobs
add a comment |
I have a controller function which dispatchs a job
. When this job
is handled, at the end it dispatch the same job
again (with different args). There are 5 jobs of the same in total.
Queue driver: database
The problem is: I record the time duration from create()
to handle()
. The first job dispatched by the controller took 1700ms, where the other jobs dispatched by the jobs themselves took only 40ms.
Queue driver: sync
When I changed to use sync
queue driver, all the jobs worked in lightning speed.
Findings:
The first queue job took long time from create()
to handle()
. Before that the queue was empty. It might be the queue driver problem.
Why and how to fix please? thanks!!
UPDATE:
Added a TestJob
that dispatch itself when job was handled. That meant the queue always had a TestJob
being handled or waiting for handling.
Repeating my original jobs, they all took only <70ms from created()
to handle()
completed.
Conclusion:
I am pretty sure it is the queue driver problem. Looks like the worker fall asleep when the queue is empty. Do anyone know the fix please?
laravel performance queue jobs
add a comment |
I have a controller function which dispatchs a job
. When this job
is handled, at the end it dispatch the same job
again (with different args). There are 5 jobs of the same in total.
Queue driver: database
The problem is: I record the time duration from create()
to handle()
. The first job dispatched by the controller took 1700ms, where the other jobs dispatched by the jobs themselves took only 40ms.
Queue driver: sync
When I changed to use sync
queue driver, all the jobs worked in lightning speed.
Findings:
The first queue job took long time from create()
to handle()
. Before that the queue was empty. It might be the queue driver problem.
Why and how to fix please? thanks!!
UPDATE:
Added a TestJob
that dispatch itself when job was handled. That meant the queue always had a TestJob
being handled or waiting for handling.
Repeating my original jobs, they all took only <70ms from created()
to handle()
completed.
Conclusion:
I am pretty sure it is the queue driver problem. Looks like the worker fall asleep when the queue is empty. Do anyone know the fix please?
laravel performance queue jobs
I have a controller function which dispatchs a job
. When this job
is handled, at the end it dispatch the same job
again (with different args). There are 5 jobs of the same in total.
Queue driver: database
The problem is: I record the time duration from create()
to handle()
. The first job dispatched by the controller took 1700ms, where the other jobs dispatched by the jobs themselves took only 40ms.
Queue driver: sync
When I changed to use sync
queue driver, all the jobs worked in lightning speed.
Findings:
The first queue job took long time from create()
to handle()
. Before that the queue was empty. It might be the queue driver problem.
Why and how to fix please? thanks!!
UPDATE:
Added a TestJob
that dispatch itself when job was handled. That meant the queue always had a TestJob
being handled or waiting for handling.
Repeating my original jobs, they all took only <70ms from created()
to handle()
completed.
Conclusion:
I am pretty sure it is the queue driver problem. Looks like the worker fall asleep when the queue is empty. Do anyone know the fix please?
laravel performance queue jobs
laravel performance queue jobs
edited Nov 27 '18 at 11:57
Terry D
asked Nov 24 '18 at 4:44
Terry DTerry D
539
539
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
I post my answer here, hope to be useful to someone else on the internet.
Reference
https://divinglaravel.com/queue-system/workers
Answer
After putting echo
and echo debug_backtrace()[1]['function'];
everywhere, it was found that there was DEFAULT VALUE of sleep when queue was empty, inside IlluminateQueueConsoleWorkCommand
protected $signature = 'queue:work{--sleep=3 : Number of seconds to sleep when no job is available}
Solution
so the solution is to mention sleep
in the console command:
php artisan queue:work --sleep=0
Thanks for reading.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53455207%2flaravel-queue-fall-asleep-when-queue-is-empty%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
I post my answer here, hope to be useful to someone else on the internet.
Reference
https://divinglaravel.com/queue-system/workers
Answer
After putting echo
and echo debug_backtrace()[1]['function'];
everywhere, it was found that there was DEFAULT VALUE of sleep when queue was empty, inside IlluminateQueueConsoleWorkCommand
protected $signature = 'queue:work{--sleep=3 : Number of seconds to sleep when no job is available}
Solution
so the solution is to mention sleep
in the console command:
php artisan queue:work --sleep=0
Thanks for reading.
add a comment |
I post my answer here, hope to be useful to someone else on the internet.
Reference
https://divinglaravel.com/queue-system/workers
Answer
After putting echo
and echo debug_backtrace()[1]['function'];
everywhere, it was found that there was DEFAULT VALUE of sleep when queue was empty, inside IlluminateQueueConsoleWorkCommand
protected $signature = 'queue:work{--sleep=3 : Number of seconds to sleep when no job is available}
Solution
so the solution is to mention sleep
in the console command:
php artisan queue:work --sleep=0
Thanks for reading.
add a comment |
I post my answer here, hope to be useful to someone else on the internet.
Reference
https://divinglaravel.com/queue-system/workers
Answer
After putting echo
and echo debug_backtrace()[1]['function'];
everywhere, it was found that there was DEFAULT VALUE of sleep when queue was empty, inside IlluminateQueueConsoleWorkCommand
protected $signature = 'queue:work{--sleep=3 : Number of seconds to sleep when no job is available}
Solution
so the solution is to mention sleep
in the console command:
php artisan queue:work --sleep=0
Thanks for reading.
I post my answer here, hope to be useful to someone else on the internet.
Reference
https://divinglaravel.com/queue-system/workers
Answer
After putting echo
and echo debug_backtrace()[1]['function'];
everywhere, it was found that there was DEFAULT VALUE of sleep when queue was empty, inside IlluminateQueueConsoleWorkCommand
protected $signature = 'queue:work{--sleep=3 : Number of seconds to sleep when no job is available}
Solution
so the solution is to mention sleep
in the console command:
php artisan queue:work --sleep=0
Thanks for reading.
answered Dec 1 '18 at 13:19
Terry DTerry D
539
539
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53455207%2flaravel-queue-fall-asleep-when-queue-is-empty%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown