0

I have implemented a Laravel 5.0 Queue (with a DB driver) in order to speed up the redirection speed on my website.

I wanted to speed up a process that takes about 400 ms.

I'm redirecting the user and want to use Queues to wipe out that 400ms waiting time.

However after implementing this Queue, it's still taking like 350-400ms to process the script and redirect the user.

Queue::push(function($job) use ($data)
{
    TestQueue::myFunc($data);

    $job->delete();
});

Am I doing anything wrong? Please let me know what else to provide in order for you to help me.

Samsquanch
  • 8,866
  • 12
  • 50
  • 89
Radical_Activity
  • 2,618
  • 10
  • 38
  • 70
  • what does TestQueue::myFunc($data) do? – Alex Harris Jun 28 '16 at 21:15
  • 2
    You realize that all a queue does is runs code, right? If `myFunc()` was taking 400ms to run and you moved it to a queue, `myFunc()` would still take 400ms to run. – Samsquanch Jun 28 '16 at 21:33
  • @chasenyc It's getting data from another server and then inserting data to the DB. However I think it should really affect the Queue length, should it. – Radical_Activity Jun 28 '16 at 21:33
  • @Samsquanch Yeah, but I beleive it'll only run in the background and the end user won't notice that 400ms waiting, right? Edited my question. – Radical_Activity Jun 28 '16 at 21:35
  • If your application did something like `process form -> run myFunc() -> retrun view` and changed the code to `process form -> queue myFunc() -> return view`, assuming `myFunc()` took a few hundred ms to run, the view should be returned much quicker while `myFunc()` runs in the queue which is in the background (assuming you have something like Beanstalk handling the queue). – Samsquanch Jun 28 '16 at 21:38
  • queue not purposely for speed up, it just execute your process in background. But if you have multiple jobs, then queue would help to speed up by running multiple workers using supervisord – xmhafiz Jun 28 '16 at 21:40
  • @Samsquanch Yes, exactly. However it's not speeding up too much, maybe 100ms or something. But I expect it to speed up 350ms+ – Radical_Activity Jun 28 '16 at 21:43
  • What driver are you using to handle the queue? – Samsquanch Jun 28 '16 at 21:43
  • @Samsquanch Database driver. – Radical_Activity Jun 28 '16 at 21:44
  • Basically I'd like to achieve something like this: http://stackoverflow.com/questions/5905877/how-to-run-the-php-code-asynchronous - like posting asynchronously. – Radical_Activity Jun 28 '16 at 21:44
  • If you completely comment out that part, what kind of load times are you seeing? Significantly lower? – Samsquanch Jun 28 '16 at 21:47
  • @Samsquanch Yeah, if I completely comment out the `Queue:push` function, then I'm seeing about 250-300ms loading time. If I'm using that, then I'm getting like 650-700ms loading time. – Radical_Activity Jun 28 '16 at 21:51
  • Which version of Laravel are you using? – Samsquanch Jun 28 '16 at 21:55
  • @Samsquanch Laravel 5.0.34 – Radical_Activity Jun 28 '16 at 21:56
  • Should it behave any differently then it is for me right now? – Radical_Activity Jun 28 '16 at 21:59
  • 1
    I was curious because I haven't used the closure version of Queue before and I couldn't find it in the 5.1 or 5.2 docs, so I'm thinking this may no longer be a feature in those versions. I have multiple apps running queues and I've never noticed a significant performance decrease using queues (one app has an average response time of around 20ms with a queue) -- I'd suggest maybe adding a queue handler with a listener and see if that helps out the performance at all. – Samsquanch Jun 28 '16 at 22:02
  • @Samsquanch Awesome, thank you I'll try that out! :-) – Radical_Activity Jun 28 '16 at 22:03
  • No problem. If that doesn't help give me a ping. – Samsquanch Jun 28 '16 at 22:06

0 Answers0