How create one worker for each job?

77 views
Skip to first unread message

Felipe Prestes

unread,
Oct 31, 2018, 2:27:24 PM10/31/18
to Gearman
Hello everyone!

I'm using the Gearman with Symfony 2 and I'm having a problem. I have on average 2k of jobs for one worker. I don't know if is possible or the best practice, but i can create a worker for each job?

Here is an example of how my code is implemented.

$gearman = $this->container->get('gearman');

for (...) {
$gearman->doBackgroundJob('something~myJob', $workload);
}

In my for, i can create a new worker for each call doBackgroundJob for my job?

I'm a beginner with Gearman and English, so sorry if I say something wrong or idiot.

Thanks!

Brian Moon

unread,
Nov 1, 2018, 9:52:10 AM11/1/18
to gea...@googlegroups.com, Felipe Prestes
On 10/31/18 13:27 , Felipe Prestes wrote:
> Hello everyone!
>
> I'm using the Gearman with Symfony 2 and I'm having a problem. I have on
> average 2k of jobs for one worker. I don't know if is possible or the
> best practice, but i can create a worker for each job?
>
> Here is an example of how my code is implemented.
>
> $gearman = $this->container->get('gearman');
>
> for (...) {
> $gearman->doBackgroundJob('something~myJob', $workload);
> }
>
> In my for, i can create a new worker for each call *doBackgroundJob* for
> my job?
>
> I'm a beginner with Gearman and English, so sorry if I say something
> wrong or idiot.
>
> Thanks!
Hi,

If you want a separate worker for each job, you will need a separate PHP
process for each job. The easiest way to do that is
https://github.com/brianlmoon/GearmanManager/.

--

Brian.
--------
http://brian.moonspot.net/

Felipe Prestes

unread,
Nov 1, 2018, 12:06:59 PM11/1/18
to Gearman
Hi Brian!

So when I call $gearman->doBackgroundJob('something~myJob', $workload); in my for, doesn't mean that I have a separate PHP process?

I don't understand what you say by "separate PHP process for each job". Do you can tell me more about this, please?

Tks

Benjamin Meynell

unread,
Nov 1, 2018, 12:31:19 PM11/1/18
to Gearman
Felipe - it would be helpful to know:
  1. Your use-case (doesn't have to be exact, reveal biz secrets, etc., but should capture the spirit of what you want to accomplish).
  2. Your expectations (what problem you are facing having an "average 2k of jobs for one worker").
  3. Rationale behind your 1:1 job-to-worker question (ties into Q#1 above).
-b

Rowan Collins

unread,
Nov 1, 2018, 5:45:55 PM11/1/18
to gea...@googlegroups.com
On 01/11/2018 16:06, Felipe Prestes wrote:
Hi Brian!

So when I call $gearman->doBackgroundJob('something~myJob', $workload); in my for, doesn't mean that I have a separate PHP process?

I don't understand what you say by "separate PHP process for each job". Do you can tell me more about this, please?


Calling a function on the server will not create a worker; it will just push a job into a queue. It's up to you to run a separate process which looks at that queue and does the work. Normally, this would be a command-line script managed by something like Supervisor [http://supervisord.org/] or the Gearman Manager that Felipe mentioned.

The number of workers you need depends on what you're doing - since these are background jobs, you presumably don't need them all to happen at once, so you just need enough workers that they get through the tasks on average faster than they come in. You can use whatever tool you want to make sure there are enough workers, but Gearman will never create them for you.

Regards,

-- 
Rowan Collins
[IMSoP]

Felipe Prestes

unread,
Nov 5, 2018, 6:41:22 AM11/5/18
to Gearman
Thank you guys!

I'm going to try to implement Gearman Manager for PHP. And Rowan, your answer was very enlightening.
Reply all
Reply to author
Forward
0 new messages